中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

做網(wǎng)站 怎么提升瀏覽量seo推廣官網(wǎng)

做網(wǎng)站 怎么提升瀏覽量,seo推廣官網(wǎng),植物提取網(wǎng)站做的比較好的廠家,軟件開(kāi)發(fā)專業(yè)課程有哪些Debug庫(kù) 是一個(gè)小巧但功能強(qiáng)大的 JavaScript 調(diào)試工具庫(kù),可以幫助開(kāi)發(fā)人員更輕松地進(jìn)行調(diào)試,以便更快地發(fā)現(xiàn)和修復(fù)問(wèn)題。它的主要特點(diǎn)是可以輕松地添加調(diào)試日志語(yǔ)句,同時(shí)在不需要調(diào)試時(shí)可以輕松地禁用它們,以避免在生產(chǎn)環(huán)境中對(duì)性…

Debug庫(kù) 是一個(gè)小巧但功能強(qiáng)大的 JavaScript 調(diào)試工具庫(kù),可以幫助開(kāi)發(fā)人員更輕松地進(jìn)行調(diào)試,以便更快地發(fā)現(xiàn)和修復(fù)問(wèn)題。它的主要特點(diǎn)是可以輕松地添加調(diào)試日志語(yǔ)句,同時(shí)在不需要調(diào)試時(shí)可以輕松地禁用它們,以避免在生產(chǎn)環(huán)境中對(duì)性能產(chǎn)生影響。我們?cè)谝恍┯忻娜綆?kù)如socket.io,就能看到debug庫(kù)的身影,說(shuō)明它確實(shí)很常用。

Debug 庫(kù)介紹

一個(gè)模仿Node.js核心調(diào)試技術(shù)的小型JavaScript調(diào)試實(shí)用程序。適用于Node.js和web瀏覽器。Debug庫(kù) 是一個(gè)小巧但功能強(qiáng)大的 JavaScript 調(diào)試工具庫(kù),可以幫助開(kāi)發(fā)人員更輕松地進(jìn)行調(diào)試,以便更快地發(fā)現(xiàn)和修復(fù)問(wèn)題。它的主要特點(diǎn)是可以輕松地添加調(diào)試日志語(yǔ)句,同時(shí)在不需要調(diào)試時(shí)可以輕松地禁用它們,以避免在生產(chǎn)環(huán)境中對(duì)性能產(chǎn)生影響。

debug庫(kù)的github:GitHub - debug-js/debug: A tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers

它提供了一種比console.log()更方便的打印調(diào)試信息的方式。Debug 庫(kù)包含了一個(gè)全局函數(shù) debug(),通過(guò)調(diào)用這個(gè)函數(shù)可以創(chuàng)建一個(gè)具有指定名稱的調(diào)試器對(duì)象。調(diào)試器對(duì)象提供了一些方法,可以用于在控制臺(tái)中輸出調(diào)試信息。同時(shí),可以使用環(huán)境變量來(lái)控制調(diào)試器對(duì)象是否啟用。

我移植發(fā)布的鴻蒙的debug庫(kù):

參見(jiàn)鴻蒙三方中心庫(kù):OpenHarmony三方庫(kù)中心倉(cāng)

簡(jiǎn)單使用

下面是一個(gè) Debug 庫(kù)的代碼示例:

let debug = require('debug')('myapp');function myFunction() {debug('This is a debug message');debug('This is a debug message:%d',2);
}myFunction();

首先使用 require() 函數(shù)將 Debug 庫(kù)引入到我們的代碼中,并調(diào)用 debug() 函數(shù)創(chuàng)建一個(gè)名為 "myapp" 的調(diào)試器對(duì)象。然后,我們定義一個(gè)名為 myFunction() 的函數(shù),在這個(gè)函數(shù)中調(diào)用調(diào)試器對(duì)象的 debug() 方法輸出一條調(diào)試信息。

如果我們想要在控制臺(tái)中看到這些調(diào)試信息,我們需要設(shè)置環(huán)境變量 DEBUG 的值為 "myapp",這可以在終端中使用命令行來(lái)完成:

$ DEBUG=myapp node myscript.js

這會(huì)啟動(dòng)名為 "myapp" 的調(diào)試器對(duì)象,并在控制臺(tái)中輸出所有與該名稱相關(guān)聯(lián)的調(diào)試信息。如果我們要禁用調(diào)試信息,只需要將 DEBUG 環(huán)境變量的值設(shè)置為空即可:

$ DEBUG= node myscript.js

這將禁用所有調(diào)試信息,避免在生產(chǎn)環(huán)境中對(duì)性能產(chǎn)生影響。

此外,js-debug庫(kù)還支持設(shè)置不同的命名空間來(lái)過(guò)濾特定的調(diào)試信息。例如:

const debug1 = require('debug')('app:debug1')const debug2 = require('debug')('app:debug2')

然后在終端輸入DEBUG=app:* node app.js,則會(huì)輸出形如app:debug1 This is debug1 message!的信息。

上述示例是基于nodejs的命令行環(huán)境下的。

鴻蒙下的使用舉例:

import debugModule from "@yyz116/debug" // debug()const debug = debugModule("MyApp:client"); debug.enable('') //為空則是禁用日志輸出
debug.enable('MyApp:client'); //開(kāi)啟日志。注意,默認(rèn)日志輸出是關(guān)閉的,開(kāi)啟調(diào)試日志需要代碼里調(diào)用enbale接口。不同于原庫(kù)的環(huán)境變量方式debug('booting %s', 'Hello MyTest');
debug("this is a %d test", 5);debug("hello");

源碼簡(jiǎn)析

源碼很簡(jiǎn)單,代碼量也不多,很容易看懂。首先看 index.js:

if (typeof process !== 'undefined' && process.type === 'renderer') {
module.exports = require('./browser.js');
} else {
module.exports = require('./node.js');
}

說(shuō)明它同時(shí)支持瀏覽器環(huán)境和nodejs環(huán)境,通過(guò)if判斷process對(duì)象是否存在來(lái)決定是使用哪個(gè)文件的導(dǎo)出。

由于我們是要移植到鴻蒙系統(tǒng)中的,于是node的那版就不看了,直接看browser.js源碼:

/* eslint-env browser *//*** This is the web browser implementation of `debug()`.*/exports.formatArgs = formatArgs;
exports.save = save;
exports.load = load;
exports.useColors = useColors;
exports.storage = localstorage();
exports.destroy = (() => {let warned = false;return () => {if (!warned) {warned = true;console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');}};
})();/*** Colors.*/exports.colors = ['#0000CC','#0000FF',......'#FFCC33'
];/*** Currently only WebKit-based Web Inspectors, Firefox >= v31,* and the Firebug extension (any Firefox version) are known* to support "%c" CSS customizations.** TODO: add a `localStorage` variable to explicitly enable/disable colors*/// eslint-disable-next-line complexity
function useColors() {// NB: In an Electron preload script, document will be defined but not fully// initialized. Since we know we're in Chrome, we'll just detect this case// explicitlyif (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {return true;}// Internet Explorer and Edge do not support colors.if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {return false;}// Is webkit? http://stackoverflow.com/a/16459606/376773// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||// Is firebug? http://stackoverflow.com/a/398120/376773(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||// Is firefox >= v31?// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||// Double check webkit in userAgent just in case we are in a worker(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
}/*** Colorize log arguments if enabled.** @api public*/function formatArgs(args) {args[0] = (this.useColors ? '%c' : '') +this.namespace +(this.useColors ? ' %c' : ' ') +args[0] +(this.useColors ? '%c ' : ' ') +'+' + module.exports.humanize(this.diff);if (!this.useColors) {return;}const c = 'color: ' + this.color;args.splice(1, 0, c, 'color: inherit');// The final "%c" is somewhat tricky, because there could be other// arguments passed either before or after the %c, so we need to// figure out the correct index to insert the CSS intolet index = 0;let lastC = 0;args[0].replace(/%[a-zA-Z%]/g, match => {if (match === '%%') {return;}index++;if (match === '%c') {// We only are interested in the *last* %c// (the user may have provided their own)lastC = index;}});args.splice(lastC, 0, c);
}/*** Invokes `console.debug()` when available.* No-op when `console.debug` is not a "function".* If `console.debug` is not available, falls back* to `console.log`.** @api public*/
exports.log = console.debug || console.log || (() => {});/*** Save `namespaces`.** @param {String} namespaces* @api private*/
function save(namespaces) {try {if (namespaces) {exports.storage.setItem('debug', namespaces);} else {exports.storage.removeItem('debug');}} catch (error) {// Swallow// XXX (@Qix-) should we be logging these?}
}/*** Load `namespaces`.** @return {String} returns the previously persisted debug modes* @api private*/
function load() {let r;try {r = exports.storage.getItem('debug');} catch (error) {// Swallow// XXX (@Qix-) should we be logging these?}// If debug isn't set in LS, and we're in Electron, try to load $DEBUGif (!r && typeof process !== 'undefined' && 'env' in process) {r = process.env.DEBUG;}return r;
}/*** Localstorage attempts to return the localstorage.** This is necessary because safari throws* when a user disables cookies/localstorage* and you attempt to access it.** @return {LocalStorage}* @api private*/function localstorage() {try {// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context// The Browser also has localStorage in the global context.return localStorage;} catch (error) {// Swallow// XXX (@Qix-) should we be logging these?}
}module.exports = require('./common')(exports);const {formatters} = module.exports;/*** Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.*/formatters.j = function (v) {try {return JSON.stringify(v);} catch (error) {return '[UnexpectedJSONParseError]: ' + error.message;}
};

?代碼量很少,注定移植是很簡(jiǎn)單的事情。這個(gè)文件中就定義了一系列的函數(shù),掛載到了node的exports對(duì)象上面。至于功能是干什么的,簡(jiǎn)單的不用再說(shuō)了。直接看這里:

module.exports = require('./common')(exports);const {formatters} = module.exports;

這里才是關(guān)鍵,核心的類和對(duì)象的實(shí)現(xiàn)是在common.js文件里的。

//common.js
/*** This is the common logic for both the Node.js and web browser* implementations of `debug()`.*/function setup(env) {createDebug.debug = createDebug;createDebug.default = createDebug;createDebug.coerce = coerce;createDebug.disable = disable;createDebug.enable = enable;createDebug.enabled = enabled;createDebug.humanize = require('ms');createDebug.destroy = destroy;Object.keys(env).forEach(key => {createDebug[key] = env[key];});/*** The currently active debug mode names, and names to skip.*/createDebug.names = [];createDebug.skips = [];/*** Map of special "%n" handling functions, for the debug "format" argument.** Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".*/createDebug.formatters = {};/*** Selects a color for a debug namespace* @param {String} namespace The namespace string for the debug instance to be colored* @return {Number|String} An ANSI color code for the given namespace* @api private*/function selectColor(namespace) {let hash = 0;for (let i = 0; i < namespace.length; i++) {hash = ((hash << 5) - hash) + namespace.charCodeAt(i);hash |= 0; // Convert to 32bit integer}return createDebug.colors[Math.abs(hash) % createDebug.colors.length];}createDebug.selectColor = selectColor;/*** Create a debugger with the given `namespace`.** @param {String} namespace* @return {Function}* @api public*/function createDebug(namespace) {let prevTime;let enableOverride = null;let namespacesCache;let enabledCache;function debug(...args) {// Disabled?if (!debug.enabled) {return;}const self = debug;// Set `diff` timestampconst curr = Number(new Date());const ms = curr - (prevTime || curr);self.diff = ms;self.prev = prevTime;self.curr = curr;prevTime = curr;args[0] = createDebug.coerce(args[0]);if (typeof args[0] !== 'string') {// Anything else let's inspect with %Oargs.unshift('%O');}// Apply any `formatters` transformationslet index = 0;args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {// If we encounter an escaped % then don't increase the array indexif (match === '%%') {return '%';}index++;const formatter = createDebug.formatters[format];if (typeof formatter === 'function') {const val = args[index];match = formatter.call(self, val);// Now we need to remove `args[index]` since it's inlined in the `format`args.splice(index, 1);index--;}return match;});// Apply env-specific formatting (colors, etc.)createDebug.formatArgs.call(self, args);const logFn = self.log || createDebug.log;logFn.apply(self, args);}debug.namespace = namespace;debug.useColors = createDebug.useColors();debug.color = createDebug.selectColor(namespace);debug.extend = extend;debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.Object.defineProperty(debug, 'enabled', {enumerable: true,configurable: false,get: () => {if (enableOverride !== null) {return enableOverride;}if (namespacesCache !== createDebug.namespaces) {namespacesCache = createDebug.namespaces;enabledCache = createDebug.enabled(namespace);}return enabledCache;},set: v => {enableOverride = v;}});// Env-specific initialization logic for debug instancesif (typeof createDebug.init === 'function') {createDebug.init(debug);}return debug;}function extend(namespace, delimiter) {const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);newDebug.log = this.log;return newDebug;}/*** Enables a debug mode by namespaces. This can include modes* separated by a colon and wildcards.** @param {String} namespaces* @api public*/function enable(namespaces) {createDebug.save(namespaces);createDebug.namespaces = namespaces;createDebug.names = [];createDebug.skips = [];let i;const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);const len = split.length;for (i = 0; i < len; i++) {if (!split[i]) {// ignore empty stringscontinue;}namespaces = split[i].replace(/\*/g, '.*?');if (namespaces[0] === '-') {createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));} else {createDebug.names.push(new RegExp('^' + namespaces + '$'));}}}/*** Disable debug output.** @return {String} namespaces* @api public*/function disable() {const namespaces = [...createDebug.names.map(toNamespace),...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)].join(',');createDebug.enable('');return namespaces;}/*** Returns true if the given mode name is enabled, false otherwise.** @param {String} name* @return {Boolean}* @api public*/function enabled(name) {if (name[name.length - 1] === '*') {return true;}let i;let len;for (i = 0, len = createDebug.skips.length; i < len; i++) {if (createDebug.skips[i].test(name)) {return false;}}for (i = 0, len = createDebug.names.length; i < len; i++) {if (createDebug.names[i].test(name)) {return true;}}return false;}/*** Convert regexp to namespace** @param {RegExp} regxep* @return {String} namespace* @api private*/function toNamespace(regexp) {return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, '*');}/*** Coerce `val`.** @param {Mixed} val* @return {Mixed}* @api private*/function coerce(val) {if (val instanceof Error) {return val.stack || val.message;}return val;}/*** XXX DO NOT USE. This is a temporary stub function.* XXX It WILL be removed in the next major release.*/function destroy() {console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');}createDebug.enable(createDebug.load());return createDebug;
}module.exports = setup;

代碼也比較簡(jiǎn)單。主要看三個(gè)函數(shù),setup,?createDebug函數(shù)和其內(nèi)部的debug函數(shù)。

function setup(env) {createDebug.debug = createDebug;createDebug.default = createDebug;createDebug.coerce = coerce;createDebug.disable = disable;createDebug.enable = enable;createDebug.enabled = enabled;createDebug.humanize = require('ms');createDebug.destroy = destroy;Object.keys(env).forEach(key => {createDebug[key] = env[key];});/*** The currently active debug mode names, and names to skip.*/createDebug.names = [];createDebug.skips = [];
.....
}

JavaScript中的函數(shù)是一種特殊的對(duì)象,因此可以像普通對(duì)象一樣被擴(kuò)展屬性和方法。這種行為是由JavaScript中的函數(shù)對(duì)象的特性所決定的。

在JavaScript中,函數(shù)也是一種對(duì)象,也可以擁有屬性和方法。當(dāng)我們定義一個(gè)函數(shù)時(shí),實(shí)際上是在內(nèi)存中創(chuàng)建了一個(gè)函數(shù)對(duì)象,并且該函數(shù)對(duì)象可以擁有自己的屬性和方法。這意味著我們可以在函數(shù)外部對(duì)其進(jìn)行擴(kuò)展,添加新的屬性和方法,或者修改已有的屬性和方法。上述代碼是給createDebug的函數(shù)擴(kuò)展了一些屬性和方法。這些屬性會(huì)成為函數(shù)對(duì)象的一部分,并且可以被訪問(wèn)和使用。

JavaScript中函數(shù)對(duì)象的這種特性為我們提供了一定的靈活性,使得可以在函數(shù)對(duì)象上添加額外的信息或者功能,這在某些場(chǎng)景下是非常有用。

需要注意的是,盡管函數(shù)對(duì)象可以被擴(kuò)展屬性和方法,但這并不意味著推薦在實(shí)際開(kāi)發(fā)中頻繁地對(duì)函數(shù)對(duì)象進(jìn)行擴(kuò)展。通常情況下,函數(shù)應(yīng)當(dāng)專注于其原本的用途和功能,并遵循單一職責(zé)原則。

另外需要注意的是,createDebug是一個(gè)函數(shù)而不是一個(gè)類。在JavaScript中,函數(shù)和類都可以用來(lái)創(chuàng)建對(duì)象,但它們的語(yǔ)法和用法有所不同。createDebug函數(shù)被用作一個(gè)工廠函數(shù),用于創(chuàng)建調(diào)試器對(duì)象。它返回一個(gè)包含內(nèi)部狀態(tài)和方法的對(duì)象,而不是一個(gè)類的實(shí)例。通過(guò)調(diào)用createDebug函數(shù),我們可以得到一個(gè)具有特定功能和狀態(tài)的調(diào)試器對(duì)象。在這種情況下,并沒(méi)有使用JavaScript中的類(class)關(guān)鍵字來(lái)定義createDebug,而是直接定義了一個(gè)函數(shù)來(lái)實(shí)現(xiàn)相同的功能。

js在es6規(guī)范之前沒(méi)有class的定義,但可以通過(guò)函數(shù)來(lái)實(shí)現(xiàn)類對(duì)象的行為,這種方式通常稱為構(gòu)造函數(shù)和原型繼承。通過(guò)構(gòu)造函數(shù)和原型繼承的方式,模擬類和實(shí)現(xiàn)類對(duì)象的行為。如下面這一小段代碼:

// 通過(guò)構(gòu)造函數(shù)定義類
function Person(name, age) {this.name = name;this.age = age;
}// 在原型上定義方法
Person.prototype.sayHello = function() {console.log('Hello, my name is ' + this.name);
};// 創(chuàng)建類的實(shí)例
let person1 = new Person('Alice', 25);
let person2 = new Person('Bob', 30);// 調(diào)用實(shí)例方法
person1.sayHello(); // 輸出:Hello, my name is Alice
person2.sayHello(); // 輸出:Hello, my name is Bob

setup函數(shù)分析

在給定環(huán)境env下,通過(guò)調(diào)用setup(env)來(lái)設(shè)置和返回一個(gè)名為createDebug的函數(shù)。createDebug函數(shù)內(nèi)部定義了一個(gè)名為debug的內(nèi)部函數(shù),以及一系列與debug相關(guān)的屬性和方法。這種將函數(shù)作為返回值的寫(xiě)法是一種高階函數(shù)的應(yīng)用,通過(guò)內(nèi)部函數(shù)的閉包特性,我們可以在外部函數(shù)中定義私有的屬性和方法,并返回一個(gè)可供外部使用的函數(shù)。

接下來(lái),讓我們解釋一下debug函數(shù)。debug是在createDebug函數(shù)內(nèi)部定義的一個(gè)函數(shù),用于創(chuàng)建一個(gè)帶有給定namespace的調(diào)試器。它還包含一些內(nèi)部狀態(tài)和邏輯,用于控制調(diào)試器的輸出行為。在這個(gè)代碼中,通過(guò)閉包的方式實(shí)現(xiàn)了一些私有狀態(tài)的存儲(chǔ)和訪問(wèn)。

這種嵌套定義的寫(xiě)法充分利用了JavaScript中閉包的特性,可以有效地封裝內(nèi)部狀態(tài),并提供一個(gè)對(duì)外的接口。這種寫(xiě)法為代碼的模塊化和可維護(hù)性提供了一定的幫助。

簡(jiǎn)單來(lái)說(shuō),createDebug函數(shù)是用于設(shè)置調(diào)試功能的工廠函數(shù),而debug函數(shù)是用于創(chuàng)建特定命名空間的調(diào)試器的函數(shù)。整個(gè)代碼的結(jié)構(gòu)是基于函數(shù)式編程和閉包的思想,通過(guò)高階函數(shù)的方式來(lái)組織代碼和管理狀態(tài),使得邏輯清晰,靈活性較高。

d.ts聲明文件

為了便于在TypeScript 中能夠使用js的代碼,d.ts聲明文件必不可少。以便在開(kāi)發(fā)過(guò)程中進(jìn)行類型檢查、自動(dòng)補(bǔ)全、跳轉(zhuǎn)到定義等操作。

.d.ts聲明文件(Declaration Files)是用來(lái)描述一個(gè) JavaScript 模塊、庫(kù)或者框架的類型信息以及代碼結(jié)構(gòu)的文件。它的作用是為了在開(kāi)發(fā)階段能夠讓 TypeScript 或者其他支持類型檢查的工具能夠了解 JavaScript 代碼中的類型信息和結(jié)構(gòu)。

為什么需要.d.ts聲明文件?主要是因?yàn)?JavaScript 是一種動(dòng)態(tài)類型語(yǔ)言,而 TypeScript 是一種靜態(tài)類型的超集。為了在 TypeScript 中能夠?qū)?JavaScript 模塊進(jìn)行類型檢查和更好的代碼提示,需要聲明文件來(lái)提供類型信息。很多優(yōu)秀的 JavaScript 模塊和庫(kù)都提供了官方或者社區(qū)維護(hù)的聲明文件,以便讓 TypeScript 或其他支持類型檢查的工具能夠更好地理解和協(xié)助開(kāi)發(fā)者使用這些模塊。

//index.d.ts
declare var debug: debug.Debug & { debug: debug.Debug; default: debug.Debug };
export = debug;declare namespace debug {interface Debug {(namespace: string): Debugger;coerce: (val: any) => any;disable: () => string;enable: (namespaces: string) => void;enabled: (namespaces: string) => boolean;formatArgs: (this: Debugger, args: any[]) => void;log: (...args: any[]) => any;selectColor: (namespace: string) => string | number;names: RegExp[];skips: RegExp[];formatters: Formatters;inspectOpts?: {hideDate?: boolean | number | null;colors?: boolean | number | null;depth?: boolean | number | null;showHidden?: boolean | number | null;};}type IDebug = Debug;interface Formatters {[formatter: string]: (v: any) => string;}type IDebugger = Debugger;interface Debugger {(formatter: any, ...args: any[]): void;color: string;diff: number;enabled: boolean;enable: (namespaces: string) => void;log: (...args: any[]) => any;namespace: string;destroy: () => boolean;extend: (namespace: string, delimiter?: string) => Debugger;}
}

interface Debug是對(duì)應(yīng)?createDebug函數(shù)的接口,interface Debugger是對(duì)應(yīng)內(nèi)部的debug函數(shù)的接口聲明。因?yàn)?/code>interface Debug 接口中包括了coerce、disable、enableenabled?等方法,這些方法與?createDebug?函數(shù)的行為和特性相符。

harmonyOS平臺(tái)移植

搞懂了源碼,移植就簡(jiǎn)單了。下面分享下在harmonyOS平臺(tái)下的移植。

新建一harmony.js的文件,仿照實(shí)現(xiàn)以下內(nèi)容:

/* eslint-env harmonyos */
/*** This is the harmonyos implementation of `debug()`.* author:yangyongzhen* blog: blog.scdn.net/qq8864*/let exp = {}exp.useColors = useColors;
exp.formatArgs = formatArgs;
exp.save = save;
exp.load = load;exp.storage = (function () {var data = {};return {setItem: function (key, item) { data[key] = item; },getItem: function (key) { return data[key]; },removeItem: function (key) { delete data[key]; },};
})();exp.destroy  = (() => {let warned = false;return () => {if (!warned) {warned = true;console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');}};
})();/*** Invokes `console.debug()` when available.* No-op when `console.debug` is not a "function".* If `console.debug` is not available, falls back* to `console.log`.** @api public*/
exp.log = console.log || (() => {});/*** Colors.*/exp.colors = ['#0000CC','#0000FF',......'#FFCC33'
];/*** Currently only WebKit-based Web Inspectors, Firefox >= v31,* and the Firebug extension (any Firefox version) are known* to support "%c" CSS customizations.** TODO: add a `localStorage` variable to explicitly enable/disable colors*/// eslint-disable-next-line complexity
function useColors() {// NB: In an Electron preload script, document will be defined but not fully// initialized. Since we know we're in Chrome, we'll just detect this case// explicitlyreturn false;
}/*** Colorize log arguments if enabled.** @api public*/function formatArgs(args) {args[0] = (this.useColors ? '%c' : '') +this.namespace +(this.useColors ? ' %c' : ' ') +args[0] +(this.useColors ? '%c ' : ' ');if (!this.useColors) {return;}const c = 'color: ' + this.color;args.splice(1, 0, c, 'color: inherit');// The final "%c" is somewhat tricky, because there could be other// arguments passed either before or after the %c, so we need to// figure out the correct index to insert the CSS intolet index = 0;let lastC = 0;args[0].replace(/%[a-zA-Z%]/g, match => {if (match === '%%') {return;}index++;if (match === '%c') {// We only are interested in the *last* %c// (the user may have provided their own)lastC = index;}});args.splice(lastC, 0, c);
}/*** Save `namespaces`.** @param {String} namespaces* @api private*/
function save(namespaces) {try {if (namespaces) {exp.storage.setItem('debug', namespaces);} else {exp.storage.removeItem('debug');}} catch (error) {// Swallow// XXX (@Qix-) should we be logging these?}
}/*** Load `namespaces`.** @return {String} returns the previously persisted debug modes* @api private*/
function load() {let r;try {r = exp.storage.getItem('debug');} catch (error) {// Swallow// XXX (@Qix-) should we be logging these?}// If debug isn't set in LS, and we're in Electron, try to load $DEBUGif (!r && typeof process !== 'undefined' && 'env' in process) {r = process.env.DEBUG;}return r;
}import {setup} from './common'var outs = setup(exp);const {formatters} = outs;/*** Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.*/formatters.j = function (v) {try {return JSON.stringify(v);} catch (error) {return '[UnexpectedJSONParseError]: ' + error.message;}
};export {outs};

發(fā)布到中心倉(cāng)

寫(xiě)完單元測(cè)試用例,測(cè)試沒(méi)問(wèn)題,發(fā)布的過(guò)程很簡(jiǎn)單。參見(jiàn):HarmonyOS 鴻蒙應(yīng)用開(kāi)發(fā)(九、還是藍(lán)海,如何貢獻(xiàn)第三方庫(kù))_鴻蒙開(kāi)發(fā)第三方庫(kù)社區(qū)-CSDN博客

寫(xiě)在最后

  • 如果你覺(jué)得這篇內(nèi)容對(duì)你還蠻有幫助,我想邀請(qǐng)你幫我三個(gè)小忙:
  • 點(diǎn)贊,轉(zhuǎn)發(fā),有你們的 『點(diǎn)贊和評(píng)論』,才是我創(chuàng)造的動(dòng)力。
  • 關(guān)注博主,同時(shí)可以期待后續(xù)文章ing🚀,不定期分享原創(chuàng)知識(shí)。
  • 想要獲取更多完整鴻蒙最新VIP學(xué)習(xí)資料,請(qǐng)關(guān)注貓哥公眾號(hào)【貓青年】,回復(fù)“鴻蒙”獲取

其他資源

分享7個(gè)實(shí)用又高效的 Node.js 工具庫(kù)

npm--debug模塊_npm debug-CSDN博客

GitHub - debug-js/debug: A tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers

http://www.risenshineclean.com/news/62345.html

相關(guān)文章:

  • 做網(wǎng)絡(luò)課堂的平臺(tái)有哪些網(wǎng)站鄭州seo推廣外包
  • 運(yùn)動(dòng)網(wǎng)頁(yè)設(shè)計(jì)哪里有seo排名優(yōu)化
  • 做網(wǎng)站建設(shè)費(fèi)用nba最新排名東西部
  • 重慶建設(shè)摩托車質(zhì)量怎么樣seo入門版
  • 幫詐騙公司做網(wǎng)站企業(yè)網(wǎng)站推廣技巧
  • 阜寧做網(wǎng)站的價(jià)格怎么推廣自己的網(wǎng)站
  • php 網(wǎng)站 項(xiàng)目cilimao磁力貓搜索引擎
  • wordpress手機(jī)評(píng)論百度seo新站優(yōu)化
  • swiper做的網(wǎng)站百度網(wǎng)頁(yè)版瀏覽器入口
  • 青島做網(wǎng)站費(fèi)用廚師培訓(xùn)機(jī)構(gòu)
  • 平臺(tái)企業(yè)采用勞務(wù)派遣方式用工的seo的形式有哪些
  • 網(wǎng)站自做書(shū)本永久免費(fèi)的網(wǎng)站服務(wù)器有哪些軟件
  • 建設(shè)一個(gè)網(wǎng)站的步驟有哪些網(wǎng)絡(luò)推廣公司怎么找客戶
  • 百度搜索網(wǎng)站介紹杭州上城區(qū)抖音seo有多好
  • 做網(wǎng)站優(yōu)化哪家公司好關(guān)鍵詞自動(dòng)優(yōu)化
  • 合肥知名網(wǎng)站制作上海關(guān)鍵詞優(yōu)化排名哪家好
  • 松原網(wǎng)站建設(shè)網(wǎng)站建設(shè)的好公司
  • 做網(wǎng)站網(wǎng)頁(yè)掙錢不免費(fèi)刷seo
  • 深圳做網(wǎng)站公司地點(diǎn)十大免費(fèi)網(wǎng)站推廣平臺(tái)
  • 百度搜索量seo要點(diǎn)
  • 圖床網(wǎng)站怎么做廣州seo團(tuán)隊(duì)
  • 石家莊高鐵站123網(wǎng)址之家
  • 秦皇島網(wǎng)站制作方案電商網(wǎng)站怎樣優(yōu)化
  • 網(wǎng)站建設(shè)公司的網(wǎng)銷好做嗎百度輸入法免費(fèi)下載
  • wordpress使用步驟杭州seo網(wǎng)站推廣排名
  • 云南房產(chǎn)網(wǎng)站建設(shè)seo的理解
  • 鹽城z做網(wǎng)站上海專業(yè)的seo公司
  • 專業(yè)網(wǎng)站建設(shè)策劃網(wǎng)絡(luò)營(yíng)銷和網(wǎng)絡(luò)推廣
  • 做測(cè)算的網(wǎng)站影視后期培訓(xùn)機(jī)構(gòu)全國(guó)排名
  • 湖南網(wǎng)站建設(shè) 真好磐石網(wǎng)絡(luò)免費(fèi)推廣網(wǎng)址