axe 10.0.0 → 10.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -27
- package/dist/axe.js +115 -367
- package/dist/axe.min.js +1 -1
- package/lib/index.js +65 -108
- package/package.json +2 -2
package/dist/axe.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Axe=e()}}((function(){!function(e){"use strict";e.console||(e.console={});for(var t,r,n=e.console,o=function(){},i=["memory"],s="assert,clear,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn".split(",");t=i.pop();)n[t]||(n[t]={});for(;r=s.pop();)n[r]||(n[r]=o)}("undefined"==typeof window?this:window);const e=Symbol("kErrors");class t extends Error{constructor(t){const o=new Set(t.map(i).filter(Boolean));super(Array.from(o).join("; ")),r(this,"name","CombinedError"),r(this,e,t),n(this,"stack",()=>t.map(s).join("\n\n")),n(this,"transient",()=>t.length>0&&t.every(c)),n(this,"expected",()=>t.length>0&&t.every(a))}[Symbol.iterator](){return this[e][Symbol.iterator]()}}function r(e,t,r){Object.defineProperty(e,t,{value:r})}function n(e,t,r){Object.defineProperty(e,t,{get:r})}function o(e){return null!=e}function i(e){return e.message}function s(e){return e.stack}function c(e){return!0===e.transient}function a(e){return!0===e.expected}var f=function(e){var t=Array.prototype.slice.call(arguments,1);return t.length&&(e=e.toString().replace(/(%?)(%([jds]))/g,(function(e,r,n,o){var i=t.shift();switch(o){case"s":i=""+i;break;case"d":i=Number(i);break;case"j":i=JSON.stringify(i)}return r?(t.unshift(i),e):i}))),t.length&&(e=e.toString()+" "+t.join(" ")),""+e.toString().replace(/%{2,2}/g,"%")},l=["%s","%d","%i","%f","%j","%o","%O","%%"],u=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:".";if(n=e,"[object Object]"!==Object.prototype.toString.call(n)||!t)return e;var n;const o=Array.isArray(t)?t:String(t).split(r),{length:i}=o;return i<2?e[o[0]]:((e,t,r)=>{for(let n=0;n<r;n++){if(null===e)return;const r=e[t[n]];if(void 0===r)return;e=r}return e})(e,o,i)},g=function(e){switch(Object.prototype.toString.call(e)){case"[object Error]":case"[object Exception]":case"[object DOMException]":return!0;default:return e instanceof Error}},p=e=>{if("[object Object]"!==Object.prototype.toString.call(e))return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype};const{hasOwnProperty:h}=Object.prototype,{propertyIsEnumerable:y}=Object,d=(e,t,r)=>Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0}),b=this,m={concatArrays:!1,ignoreUndefined:!1},v=e=>{const t=[];for(const r in e)h.call(e,r)&&t.push(r);if(Object.getOwnPropertySymbols){const r=Object.getOwnPropertySymbols(e);for(const n of r)y.call(e,n)&&t.push(n)}return t};function A(e){return Array.isArray(e)?function(e){const t=e.slice(0,0);return v(e).forEach(r=>{d(t,r,A(e[r]))}),t}(e):p(e)?function(e){const t=null===Object.getPrototypeOf(e)?Object.create(null):{};return v(e).forEach(r=>{d(t,r,A(e[r]))}),t}(e):e}const j=(e,t,r,n)=>(r.forEach(r=>{void 0===t[r]&&n.ignoreUndefined||(r in e&&e[r]!==Object.getPrototypeOf(e)?d(e,r,O(e[r],t[r],n)):d(e,r,A(t[r])))}),e);function O(e,t,r){return r.concatArrays&&Array.isArray(e)&&Array.isArray(t)?((e,t,r)=>{let n=e.slice(0,0),o=0;return[e,t].forEach(t=>{const i=[];for(let r=0;r<t.length;r++)h.call(t,r)&&(i.push(String(r)),d(n,o++,t===e?t[r]:A(t[r])));n=j(n,t,v(t).filter(e=>!i.includes(e)),r)}),n})(e,t,r):p(t)&&p(e)?j(e,t,v(t),r):A(t)}var w={};const E=async(e,t)=>{const r=[];let n=0;for(const o of e)r.push(await t(await o,n++));return r};(w=E).default=E;var S={},_=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(!g(e))throw new Error("`err` must be an Error");if(!Array.isArray(t))throw new Error("`fields` must be an Array");var r={};return Object.getOwnPropertyNames(Object.getPrototypeOf(e)).concat(Object.getOwnPropertyNames(e)).forEach((function(t){"function"!=typeof e[t]&&(r[t]=e[t])})),!r.name&&e.constructor.name&&(r.name=e.constructor.name),Array.isArray(t)&&0!==t.length?r.filter((function(e){return t.includes(e)})):r};const T=e=>"object"==typeof e||"function"==typeof e,k=(e,t)=>"__proto__"==e||"constructor"==e&&"function"==typeof t.constructor;var P=function(e,t,r){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:".";if(!T(e)||!t||!t.length)return e;const o=Array.isArray(t)?t:String(t).split(n);if(k(o[0],e))return e;const{length:i}=o;return 1===i?(e[o[0]]=r,e):((e,t,r,n)=>{let o=e,i=0;for(;i<r-1;i++){const e=t[i];k(e,o)||(o=T(o[e])?o[e]:o[e]={})}return o[t[i]]=n,e})(e,o,i,r)},x=function(e){return null!=e&&"object"==typeof e&&!1===Array.isArray(e)};function I(e,t,r){return"function"==typeof r.join?r.join(e):e[0]+t+e[1]}function L(e,t,r){return"function"!=typeof r.isValid||r.isValid(e,t)}function F(e){return x(e)||Array.isArray(e)||"function"==typeof e}var M=Object.prototype.toString;function N(e){return"function"==typeof e.constructor?e.constructor.name:null}var C=function e(t){switch(function(e){if(void 0===e)return"undefined";if(null===e)return"null";var t=typeof e;if("boolean"===t)return"boolean";if("string"===t)return"string";if("number"===t)return"number";if("symbol"===t)return"symbol";if("function"===t)return"GeneratorFunction"===N(e)?"generatorfunction":"function";if(function(e){return Array.isArray?Array.isArray(e):e instanceof Array}(e))return"array";if(function(e){return!(!e.constructor||"function"!=typeof e.constructor.isBuffer)&&e.constructor.isBuffer(e)}(e))return"buffer";if(function(e){try{if("number"==typeof e.length&&"function"==typeof e.callee)return!0}catch(t){if(-1!==t.message.indexOf("callee"))return!0}return!1}(e))return"arguments";if(function(e){return e instanceof Date||"function"==typeof e.toDateString&&"function"==typeof e.getDate&&"function"==typeof e.setDate}(e))return"date";if(function(e){return e instanceof Error||"string"==typeof e.message&&e.constructor&&"number"==typeof e.constructor.stackTraceLimit}(e))return"error";if(function(e){return e instanceof RegExp||"string"==typeof e.flags&&"boolean"==typeof e.ignoreCase&&"boolean"==typeof e.multiline&&"boolean"==typeof e.global}(e))return"regexp";switch(N(e)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(e){return"function"==typeof e.throw&&"function"==typeof e.return&&"function"==typeof e.next}(e))return"generator";switch(t=M.call(e)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return t.slice(8,-1).toLowerCase().replace(/\s/g,"")}(t)){case"boolean":case"date":case"function":case"null":case"number":return!0;case"undefined":return!1;case"regexp":return"(?:)"!==t.source&&""!==t.source;case"buffer":return""!==t.toString();case"error":return""!==t.message;case"string":case"arguments":return 0!==t.length;case"file":case"map":case"set":return 0!==t.size;case"array":case"object":for(const r of Object.keys(t))if(e(t[r]))return!0;return!1;default:return!0}},D=function(e,t,r){return!(null==(n=e)||"object"!=typeof n&&"function"!=typeof n&&!Array.isArray(n)||"string"!=typeof t&&!Array.isArray(t))&&C(function(e,t,r){if(x(r)||(r={default:r}),!F(e))return void 0!==r.default?r.default:e;"number"==typeof t&&(t=String(t));const n=Array.isArray(t),o="string"==typeof t,i=r.separator||".",s=r.joinChar||("string"==typeof i?i:".");if(!o&&!n)return e;if(o&&t in e)return L(t,e,r)?e[t]:r.default;let c=n?t:function(e,t,r){return"function"==typeof r.split?r.split(e):e.split(t)}(t,i,r),a=c.length,f=0;do{let t=c[f];for("number"==typeof t&&(t=String(t));t&&"\\"===t.slice(-1);)t=I([t.slice(0,-1),c[++f]||""],s,r);if(t in e){if(!L(t,e,r))return r.default;e=e[t]}else{let n=!1,o=f+1;for(;o<a;)if(n=(t=I([t,c[o++]],s,r))in e){if(!L(t,e,r))return r.default;e=e[t],f=o-1;break}if(!n)return r.default}}while(++f<a&&F(e));return f===a?e:r.default}(e,t,r));var n};const X=e=>{if((e=>"__proto__"===e||"constructor"===e||"prototype"===e)(e))throw new Error(`Cannot set unsafe key: "${e}"`)};var B=function(e,t){if(null==(r=e)||"object"!=typeof r||!1!==Array.isArray(r))throw new TypeError("expected an object.");var r,n=Array.isArray(t);if(!n&&e.hasOwnProperty(t))return delete e[t],!0;if(D(e,t)){for(var o=n?t.slice():t.split("."),i=o.pop();o.length&&"\\"===o[o.length-1].slice(-1);)i=o.pop().slice(0,-1)+"."+i;for(;o.length;)t=o.shift(),X(t),e=e[t];return delete e[i]}return!0},U={};Object.defineProperty(U,"__esModule",{value:!0}),U.boolean=void 0,U.boolean=function(e){switch(Object.prototype.toString.call(e)){case"[object String]":return["true","t","yes","y","on","1"].includes(e.trim().toLowerCase());case"[object Number]":return 1===e.valueOf();case"[object Boolean]":return e.valueOf();default:return!1}};var W={};Object.defineProperty(W,"__esModule",{value:!0}),W.isBooleanable=void 0,W.isBooleanable=function(e){switch(Object.prototype.toString.call(e)){case"[object String]":return["true","t","yes","y","on","1","false","f","no","n","off","0"].includes(e.trim().toLowerCase());case"[object Number]":return[0,1].includes(e.valueOf());case"[object Boolean]":return!0;default:return!1}};var z={};Object.defineProperty(z,"__esModule",{value:!0}),z.boolean=void 0,Object.defineProperty(z,"boolean",{enumerable:!0,get:function(){return U.boolean}}),Object.defineProperty(z,"isBooleanable",{enumerable:!0,get:function(){return W.isBooleanable}});var R,H,K,V="10.0.0",G=R={};function J(){throw new Error("setTimeout has not been defined")}function $(){throw new Error("clearTimeout has not been defined")}function q(e){if(H===setTimeout)return setTimeout(e,0);if((H===J||!H)&&setTimeout)return H=setTimeout,setTimeout(e,0);try{return H(e,0)}catch(t){try{return H.call(null,e,0)}catch(t){return H.call(this,e,0)}}}!function(){try{H="function"==typeof setTimeout?setTimeout:J}catch(e){H=J}try{K="function"==typeof clearTimeout?clearTimeout:$}catch(e){K=$}}();var Q,Y=[],Z=!1,ee=-1;function te(){Z&&Q&&(Z=!1,Q.length?Y=Q.concat(Y):ee=-1,Y.length&&re())}function re(){if(!Z){var e=q(te);Z=!0;for(var t=Y.length;t;){for(Q=Y,Y=[];++ee<t;)Q&&Q[ee].run();ee=-1,t=Y.length}Q=null,Z=!1,function(e){if(K===clearTimeout)return clearTimeout(e);if((K===$||!K)&&clearTimeout)return K=clearTimeout,clearTimeout(e);try{K(e)}catch(t){try{return K.call(null,e)}catch(t){return K.call(this,e)}}}(e)}}function ne(e,t){this.fun=e,this.array=t}function oe(){}G.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];Y.push(new ne(e,t)),1!==Y.length||Z||q(re)},ne.prototype.run=function(){this.fun.apply(null,this.array)},G.title="browser",G.browser=!0,G.env={},G.argv=[],G.version="",G.versions={},G.on=oe,G.addListener=oe,G.once=oe,G.off=oe,G.removeListener=oe,G.removeAllListeners=oe,G.emit=oe,G.prependListener=oe,G.prependOnceListener=oe,G.listeners=function(e){return[]},G.binding=function(e){throw new Error("process.binding is not supported")},G.cwd=function(){return"/"},G.chdir=function(e){throw new Error("process.chdir is not supported")},G.umask=function(){return 0};var ie={};return function(e){(function(){const{boolean:r}=z,n=new Set(["config","log"]),i=["trace","debug","info","warn","error","fatal"],s={warning:"warn",err:"error"},c="`level` invalid, must be: "+i.join(", ");function a(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t)||Symbol.toStringTag in e||Symbol.iterator in e)}function h(e){return null==e||"object"==typeof e&&0===Object.keys(e).length||"string"==typeof e&&0===e.trim().length}function y(e){return void 0===e}function d(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function v(e){return"string"==typeof e}ie=class{constructor(){var t=this;let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const s={};if(e.env.AXE_REMAPPED_META_FIELDS){const t=e.env.AXE_REMAPPED_META_FIELDS.split(",").map(e=>e.split(":"));for(const[e,r]of t)s[e]=r}this.config=function(){const e=O(A(m),this!==b&&this||{},m);let t={_:{}};for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];for(const i of n)if(void 0!==i){if(!p(i))throw new TypeError("`"+i+"` is not an Option Object");t=O(t,{_:i},e)}return t._}({showStack:!e.env.AXE_SHOW_STACK||r(e.env.AXE_SHOW_STACK),meta:Object.assign({show:!e.env.AXE_SHOW_META||r(e.env.AXE_SHOW_META),remappedFields:s,omittedFields:e.env.AXE_OMIT_META_FIELDS?e.env.AXE_OMIT_META_FIELDS.split(",").map(e=>e.trim()):["level","err","app","args"],pickedFields:e.env.AXE_PICK_META_FIELDS?e.env.AXE_PICK_META_FIELDS.split(",").map(e=>e.trim()):[],cleanupRemapping:!0},"object"==typeof o.meta?o.meta:{}),version:V,silent:!1,logger:console,name:!1,level:"info",levels:["info","warn","error","fatal"],appInfo:!e.env.AXE_APP_INFO||r(e.env.AXE_APP_INFO),hooks:Object.assign({pre:[],post:[]},"object"==typeof o.hooks?o.hooks:{})},o),this.appInfo=!!this.config.appInfo&&"function"==typeof S&&S(),this.log=this.log.bind(this);const c=Object.keys(this.config.logger).filter(e=>!n.has(e));for(const e of c)this[e]=this.config.logger[e];for(const e of i)"function"!=typeof this.config.logger[e]&&("fatal"===e?this.config.logger.fatal=this.config.logger.error||this.config.logger.info||this.config.logger.log:this.config.logger[e]=this.config.logger.info||this.config.logger.log),this[e]=function(){for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return t.log(e,...Array.prototype.slice.call(n))};this.setLevel=this.setLevel.bind(this),this.getNormalizedLevel=this.getNormalizedLevel.bind(this),this.setName=this.setName.bind(this),this.config.name&&this.setName(this.config.name),this.setLevel(this.config.level),this.err=this.error,this.warning=this.warn,this.pre=function(e,t){this.config.hooks.pre.push((function(r){for(var n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return e!==r?[...o]:t(...o)}))},this.post=function(e,t){this.config.hooks.post.push((function(r){for(var n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return e!==r?[...o]:t(...o)}))}}setLevel(e){if(!v(e)||-1===i.indexOf(e))throw new Error(c);v(this.config.logger.logLevel)?this.config.logger.logLevel=e:this.config.logger.level=e,this.config.levels=i.slice(i.indexOf(e))}getNormalizedLevel(e){return v(e)?v(s[e])?s[e]:-1===i.indexOf(e)?"info":e:"info"}setName(e){if(!v(e))throw new Error("`name` must be a String");v(this.config.logger.scope)?this.config.logger.scope=e:this.config.logger.name=e}log(e,r,n){const c=[],p=[];y(e)||c.push(e),y(r)||c.push(r),y(n)||c.push(n);for(var b=arguments.length,m=new Array(b>3?b-3:0),A=3;A<b;A++)m[A-3]=arguments[A];for(const t of Array.prototype.slice.call(m))c.push(t);const{config:j}=this;let O=0;if(v(e)&&v(s[e])?e=s[e]:g(e)?(n=r,r=e,e="error"):v(e)&&-1!==i.indexOf(e)||(n=r,r=e,e=this.getNormalizedLevel(e),O=-1),-1===j.levels.indexOf(e))return;let E,S=!1;if((d(r)||Array.isArray(r))&&v(n)){S=!0;const e=n;n=r,r=v(e)&&c.length>=3+O?f(...c.slice(2+O)):e}if(y(r)&&(r=e),1!==c.slice(1+O).length||v(r)||g(r))if(!S&&c.length>=4+O){r=void 0,n={};const t=[];for(const e of c)g(e)?p.push(e):v(e)&&t.push(e);0===p.length&&t.length>0?r=f(...t):p.length>0&&"log"===e&&(e="error")}else if(!S&&c.length===3+O&&v(r)&&l.some(e=>-1!==r.indexOf(e)))r=f(r,n),n={};else if(g(r)){if(g(n)){p.push(n);for(const e of c.slice(2+O))n!==e&&g(e)&&p.push(e);n={}}}else g(n)?(p.push(n),n={}):d(n)||y(n)||null===n?v(r)||(r=f(r)):(r=f(r,n),n={});else n={message:r},r=e;y(n)||d(n)?d(n)||(n={}):n={original_meta:n},g(r)&&(p.unshift(r),r=void 0),d(n.err)&&(g(n.err)&&p.push(n.err),n.original_err=g(n.err)?_(n.err):n.err),p.length>0&&(E=function(e){if(0!==(e=e.filter(o)).length)return 1===e.length?e[0]:new t(e)}(p),n.err=_(E),v(r)||(r=E.message)),n.args=c,n.level=e,this.appInfo&&(n.app=this.appInfo);const T=-1===O?"log":e;if(!h(this.config.meta.remappedFields))for(const t of Object.keys(this.config.meta.remappedFields))if(P(n,this.config.meta.remappedFields[t],u(n,t)),B(n,t),this.config.meta.cleanupRemapping){const e=t.lastIndexOf(".");if(-1===e)continue;const r=t.slice(0,e);h(u(n,r))&&B(n,r)}if(!h(this.config.meta.omittedFields)||!h(this.config.meta.pickedFields)){const e=function(e){const t=[];return function e(r,n){for(const o of Object.keys(r)){const i=r[o],s=n?n+"."+o:o;a(i)?e(i,s):t.push(s)}}(e),t}(n);if(!h(this.config.meta.omittedFields))for(const t of this.config.meta.omittedFields){let r=e.length;for(;r--;)e[r]!==t&&0!==e[r].indexOf(t+".")||e.splice(r,1)}if(!h(this.config.meta.pickedFields))for(const t of this.config.meta.pickedFields){const r=t.indexOf("."),n=t.slice(0,r+1);if(-1!==r){let t=e.length;for(;t--;)0===e[t].indexOf(n)&&e.splice(t,1)}-1===e.indexOf(t)&&e.push(t)}n=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:".";if(n=e,"[object Object]"!==Object.prototype.toString.call(n)||!t||!Array.isArray(t)&&"string"!=typeof t)return{};var n;const{length:o}=t;if("string"==typeof t||o<2){const n="string"==typeof t?t:t[0],o=u(e,n,r);return void 0!==o?P({},n,o,r):{}}return((e,t,r,n)=>{const o={};for(let i=0;i<r;i++){const r=t[i],s=u(e,r,n);void 0!==s&&P(o,r,s,n)}return o})(e,t,o,r)}(n,e)}for(const t of this.config.hooks.pre)[E,r,n]=t(T,E,r,n);j.silent||(g(E)&&j.showStack?!j.meta.show||h(n)?this.config.logger[T](E):this.config.logger[T](E,n):!j.meta.show||h(n)?this.config.logger[T](r):this.config.logger[T](r,n)),w(this.config.hooks.post,e=>e(T,E,r,n)).then().catch(e=>{this.config.logger.error(e)})}}}).call(this)}.call(this,R),ie}));
|
|
1
|
+
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Axe=e()}}((function(){!function(e){"use strict";e.console||(e.console={});for(var t,r,n=e.console,o=function(){},i=["memory"],s="assert,clear,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn".split(",");t=i.pop();)n[t]||(n[t]={});for(;r=s.pop();)n[r]||(n[r]=o)}("undefined"==typeof window?this:window);const e=Symbol("kErrors");class t extends Error{constructor(t){const o=new Set(t.map(i).filter(Boolean));super(Array.from(o).join("; ")),r(this,"name","CombinedError"),r(this,e,t),n(this,"stack",()=>t.map(s).join("\n\n")),n(this,"transient",()=>t.length>0&&t.every(c)),n(this,"expected",()=>t.length>0&&t.every(a))}[Symbol.iterator](){return this[e][Symbol.iterator]()}}function r(e,t,r){Object.defineProperty(e,t,{value:r})}function n(e,t,r){Object.defineProperty(e,t,{get:r})}function o(e){return null!=e}function i(e){return e.message}function s(e){return e.stack}function c(e){return!0===e.transient}function a(e){return!0===e.expected}var f=function(e){var t=Array.prototype.slice.call(arguments,1);return t.length&&(e=e.toString().replace(/(%?)(%([jds]))/g,(function(e,r,n,o){var i=t.shift();switch(o){case"s":i=""+i;break;case"d":i=Number(i);break;case"j":i=JSON.stringify(i)}return r?(t.unshift(i),e):i}))),t.length&&(e=e.toString()+" "+t.join(" ")),""+e.toString().replace(/%{2,2}/g,"%")},l=["%s","%d","%i","%f","%j","%o","%O","%%"],u=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:".";if(n=e,"[object Object]"!==Object.prototype.toString.call(n)||!t)return e;var n;const o=Array.isArray(t)?t:String(t).split(r),{length:i}=o;return i<2?e[o[0]]:((e,t,r)=>{for(let n=0;n<r;n++){if(null===e)return;const r=e[t[n]];if(void 0===r)return;e=r}return e})(e,o,i)},g=function(e){switch(Object.prototype.toString.call(e)){case"[object Error]":case"[object Exception]":case"[object DOMException]":return!0;default:return e instanceof Error}},p=e=>{if("[object Object]"!==Object.prototype.toString.call(e))return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype};const{hasOwnProperty:h}=Object.prototype,{propertyIsEnumerable:y}=Object,d=(e,t,r)=>Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0}),b=this,m={concatArrays:!1,ignoreUndefined:!1},v=e=>{const t=[];for(const r in e)h.call(e,r)&&t.push(r);if(Object.getOwnPropertySymbols){const r=Object.getOwnPropertySymbols(e);for(const n of r)y.call(e,n)&&t.push(n)}return t};function A(e){return Array.isArray(e)?function(e){const t=e.slice(0,0);return v(e).forEach(r=>{d(t,r,A(e[r]))}),t}(e):p(e)?function(e){const t=null===Object.getPrototypeOf(e)?Object.create(null):{};return v(e).forEach(r=>{d(t,r,A(e[r]))}),t}(e):e}const j=(e,t,r,n)=>(r.forEach(r=>{void 0===t[r]&&n.ignoreUndefined||(r in e&&e[r]!==Object.getPrototypeOf(e)?d(e,r,O(e[r],t[r],n)):d(e,r,A(t[r])))}),e);function O(e,t,r){return r.concatArrays&&Array.isArray(e)&&Array.isArray(t)?((e,t,r)=>{let n=e.slice(0,0),o=0;return[e,t].forEach(t=>{const i=[];for(let r=0;r<t.length;r++)h.call(t,r)&&(i.push(String(r)),d(n,o++,t===e?t[r]:A(t[r])));n=j(n,t,v(t).filter(e=>!i.includes(e)),r)}),n})(e,t,r):p(t)&&p(e)?j(e,t,v(t),r):A(t)}var w={};const E=async(e,t)=>{const r=[];let n=0;for(const o of e)r.push(await t(await o,n++));return r};(w=E).default=E;var S={},_=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(!g(e))throw new Error("`err` must be an Error");if(!Array.isArray(t))throw new Error("`fields` must be an Array");var r={};return Object.getOwnPropertyNames(Object.getPrototypeOf(e)).concat(Object.getOwnPropertyNames(e)).forEach((function(t){"function"!=typeof e[t]&&(r[t]=e[t])})),!r.name&&e.constructor.name&&(r.name=e.constructor.name),Array.isArray(t)&&0!==t.length?r.filter((function(e){return t.includes(e)})):r};const T=e=>"object"==typeof e||"function"==typeof e,k=(e,t)=>"__proto__"==e||"constructor"==e&&"function"==typeof t.constructor;var P=function(e,t,r){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:".";if(!T(e)||!t||!t.length)return e;const o=Array.isArray(t)?t:String(t).split(n);if(k(o[0],e))return e;const{length:i}=o;return 1===i?(e[o[0]]=r,e):((e,t,r,n)=>{let o=e,i=0;for(;i<r-1;i++){const e=t[i];k(e,o)||(o=T(o[e])?o[e]:o[e]={})}return o[t[i]]=n,e})(e,o,i,r)},x=function(e){return null!=e&&"object"==typeof e&&!1===Array.isArray(e)};function I(e,t,r){return"function"==typeof r.join?r.join(e):e[0]+t+e[1]}function L(e,t,r){return"function"!=typeof r.isValid||r.isValid(e,t)}function F(e){return x(e)||Array.isArray(e)||"function"==typeof e}var M=Object.prototype.toString;function N(e){return"function"==typeof e.constructor?e.constructor.name:null}var C=function e(t){switch(function(e){if(void 0===e)return"undefined";if(null===e)return"null";var t=typeof e;if("boolean"===t)return"boolean";if("string"===t)return"string";if("number"===t)return"number";if("symbol"===t)return"symbol";if("function"===t)return"GeneratorFunction"===N(e)?"generatorfunction":"function";if(function(e){return Array.isArray?Array.isArray(e):e instanceof Array}(e))return"array";if(function(e){return!(!e.constructor||"function"!=typeof e.constructor.isBuffer)&&e.constructor.isBuffer(e)}(e))return"buffer";if(function(e){try{if("number"==typeof e.length&&"function"==typeof e.callee)return!0}catch(t){if(-1!==t.message.indexOf("callee"))return!0}return!1}(e))return"arguments";if(function(e){return e instanceof Date||"function"==typeof e.toDateString&&"function"==typeof e.getDate&&"function"==typeof e.setDate}(e))return"date";if(function(e){return e instanceof Error||"string"==typeof e.message&&e.constructor&&"number"==typeof e.constructor.stackTraceLimit}(e))return"error";if(function(e){return e instanceof RegExp||"string"==typeof e.flags&&"boolean"==typeof e.ignoreCase&&"boolean"==typeof e.multiline&&"boolean"==typeof e.global}(e))return"regexp";switch(N(e)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(e){return"function"==typeof e.throw&&"function"==typeof e.return&&"function"==typeof e.next}(e))return"generator";switch(t=M.call(e)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return t.slice(8,-1).toLowerCase().replace(/\s/g,"")}(t)){case"boolean":case"date":case"function":case"null":case"number":return!0;case"undefined":return!1;case"regexp":return"(?:)"!==t.source&&""!==t.source;case"buffer":return""!==t.toString();case"error":return""!==t.message;case"string":case"arguments":return 0!==t.length;case"file":case"map":case"set":return 0!==t.size;case"array":case"object":for(const r of Object.keys(t))if(e(t[r]))return!0;return!1;default:return!0}},D=function(e,t,r){return!(null==(n=e)||"object"!=typeof n&&"function"!=typeof n&&!Array.isArray(n)||"string"!=typeof t&&!Array.isArray(t))&&C(function(e,t,r){if(x(r)||(r={default:r}),!F(e))return void 0!==r.default?r.default:e;"number"==typeof t&&(t=String(t));const n=Array.isArray(t),o="string"==typeof t,i=r.separator||".",s=r.joinChar||("string"==typeof i?i:".");if(!o&&!n)return e;if(o&&t in e)return L(t,e,r)?e[t]:r.default;let c=n?t:function(e,t,r){return"function"==typeof r.split?r.split(e):e.split(t)}(t,i,r),a=c.length,f=0;do{let t=c[f];for("number"==typeof t&&(t=String(t));t&&"\\"===t.slice(-1);)t=I([t.slice(0,-1),c[++f]||""],s,r);if(t in e){if(!L(t,e,r))return r.default;e=e[t]}else{let n=!1,o=f+1;for(;o<a;)if(n=(t=I([t,c[o++]],s,r))in e){if(!L(t,e,r))return r.default;e=e[t],f=o-1;break}if(!n)return r.default}}while(++f<a&&F(e));return f===a?e:r.default}(e,t,r));var n};const X=e=>{if((e=>"__proto__"===e||"constructor"===e||"prototype"===e)(e))throw new Error(`Cannot set unsafe key: "${e}"`)};var B=function(e,t){if(null==(r=e)||"object"!=typeof r||!1!==Array.isArray(r))throw new TypeError("expected an object.");var r,n=Array.isArray(t);if(!n&&e.hasOwnProperty(t))return delete e[t],!0;if(D(e,t)){for(var o=n?t.slice():t.split("."),i=o.pop();o.length&&"\\"===o[o.length-1].slice(-1);)i=o.pop().slice(0,-1)+"."+i;for(;o.length;)t=o.shift(),X(t),e=e[t];return delete e[i]}return!0},U={};Object.defineProperty(U,"__esModule",{value:!0}),U.boolean=void 0,U.boolean=function(e){switch(Object.prototype.toString.call(e)){case"[object String]":return["true","t","yes","y","on","1"].includes(e.trim().toLowerCase());case"[object Number]":return 1===e.valueOf();case"[object Boolean]":return e.valueOf();default:return!1}};var W={};Object.defineProperty(W,"__esModule",{value:!0}),W.isBooleanable=void 0,W.isBooleanable=function(e){switch(Object.prototype.toString.call(e)){case"[object String]":return["true","t","yes","y","on","1","false","f","no","n","off","0"].includes(e.trim().toLowerCase());case"[object Number]":return[0,1].includes(e.valueOf());case"[object Boolean]":return!0;default:return!1}};var z={};Object.defineProperty(z,"__esModule",{value:!0}),z.boolean=void 0,Object.defineProperty(z,"boolean",{enumerable:!0,get:function(){return U.boolean}}),Object.defineProperty(z,"isBooleanable",{enumerable:!0,get:function(){return W.isBooleanable}});var R,H,K,V="10.0.2",G=R={};function J(){throw new Error("setTimeout has not been defined")}function $(){throw new Error("clearTimeout has not been defined")}function q(e){if(H===setTimeout)return setTimeout(e,0);if((H===J||!H)&&setTimeout)return H=setTimeout,setTimeout(e,0);try{return H(e,0)}catch(t){try{return H.call(null,e,0)}catch(t){return H.call(this,e,0)}}}!function(){try{H="function"==typeof setTimeout?setTimeout:J}catch(e){H=J}try{K="function"==typeof clearTimeout?clearTimeout:$}catch(e){K=$}}();var Q,Y=[],Z=!1,ee=-1;function te(){Z&&Q&&(Z=!1,Q.length?Y=Q.concat(Y):ee=-1,Y.length&&re())}function re(){if(!Z){var e=q(te);Z=!0;for(var t=Y.length;t;){for(Q=Y,Y=[];++ee<t;)Q&&Q[ee].run();ee=-1,t=Y.length}Q=null,Z=!1,function(e){if(K===clearTimeout)return clearTimeout(e);if((K===$||!K)&&clearTimeout)return K=clearTimeout,clearTimeout(e);try{K(e)}catch(t){try{return K.call(null,e)}catch(t){return K.call(this,e)}}}(e)}}function ne(e,t){this.fun=e,this.array=t}function oe(){}G.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];Y.push(new ne(e,t)),1!==Y.length||Z||q(re)},ne.prototype.run=function(){this.fun.apply(null,this.array)},G.title="browser",G.browser=!0,G.env={},G.argv=[],G.version="",G.versions={},G.on=oe,G.addListener=oe,G.once=oe,G.off=oe,G.removeListener=oe,G.removeAllListeners=oe,G.emit=oe,G.prependListener=oe,G.prependOnceListener=oe,G.listeners=function(e){return[]},G.binding=function(e){throw new Error("process.binding is not supported")},G.cwd=function(){return"/"},G.chdir=function(e){throw new Error("process.chdir is not supported")},G.umask=function(){return 0};var ie={};return function(e){(function(){const{boolean:r}=z,n=new Set(["config","log"]),i=["trace","debug","info","warn","error","fatal"],s={warning:"warn",err:"error"},c="`level` invalid, must be: "+i.join(", ");function a(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t)||Symbol.toStringTag in e||Symbol.iterator in e)}function h(e){return null==e||"object"==typeof e&&0===Object.keys(e).length||"string"==typeof e&&0===e.trim().length}function y(e){return void 0===e}function d(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function v(e){return"string"==typeof e}ie=class{constructor(){var t=this;let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const s={};if(e.env.AXE_REMAPPED_META_FIELDS){const t=e.env.AXE_REMAPPED_META_FIELDS.split(",").map(e=>e.split(":"));for(const[e,r]of t)s[e]=r}this.config=function(){const e=O(A(m),this!==b&&this||{},m);let t={_:{}};for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];for(const i of n)if(void 0!==i){if(!p(i))throw new TypeError("`"+i+"` is not an Option Object");t=O(t,{_:i},e)}return t._}({showStack:!e.env.AXE_SHOW_STACK||r(e.env.AXE_SHOW_STACK),meta:Object.assign({show:!e.env.AXE_SHOW_META||r(e.env.AXE_SHOW_META),remappedFields:s,omittedFields:e.env.AXE_OMIT_META_FIELDS?e.env.AXE_OMIT_META_FIELDS.split(",").map(e=>e.trim()):["level","err","app","args"],pickedFields:e.env.AXE_PICK_META_FIELDS?e.env.AXE_PICK_META_FIELDS.split(",").map(e=>e.trim()):[],cleanupRemapping:!0},"object"==typeof o.meta?o.meta:{}),version:V,silent:!1,logger:console,name:!1,level:"info",levels:["info","warn","error","fatal"],appInfo:!e.env.AXE_APP_INFO||r(e.env.AXE_APP_INFO),hooks:Object.assign({pre:[],post:[]},"object"==typeof o.hooks?o.hooks:{})},o),this.appInfo=!!this.config.appInfo&&"function"==typeof S&&S(),this.log=this.log.bind(this);const c=Object.keys(this.config.logger).filter(e=>!n.has(e));for(const e of c)this[e]=this.config.logger[e];for(const e of i)"function"!=typeof this.config.logger[e]&&("fatal"===e?this.config.logger.fatal=this.config.logger.error||this.config.logger.info||this.config.logger.log:this.config.logger[e]=this.config.logger.info||this.config.logger.log),this[e]=function(){for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return t.log(e,...Array.prototype.slice.call(n))};this.setLevel=this.setLevel.bind(this),this.getNormalizedLevel=this.getNormalizedLevel.bind(this),this.setName=this.setName.bind(this),this.config.name&&this.setName(this.config.name),this.setLevel(this.config.level),this.err=this.error,this.warning=this.warn,this.pre=function(e,t){this.config.hooks.pre.push((function(r){for(var n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return e!==r?[...o]:t(...o)}))},this.post=function(e,t){this.config.hooks.post.push((function(r){for(var n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return e!==r?[...o]:t(...o)}))}}setLevel(e){if(!v(e)||-1===i.indexOf(e))throw new Error(c);v(this.config.logger.logLevel)?this.config.logger.logLevel=e:this.config.logger.level=e,this.config.levels=i.slice(i.indexOf(e))}getNormalizedLevel(e){return v(e)?v(s[e])?s[e]:-1===i.indexOf(e)?"info":e:"info"}setName(e){if(!v(e))throw new Error("`name` must be a String");v(this.config.logger.scope)?this.config.logger.scope=e:this.config.logger.name=e}log(e,r,n){const c=[],p=[];y(e)||c.push(e),y(r)||c.push(r),y(n)||c.push(n);for(var b=arguments.length,m=new Array(b>3?b-3:0),A=3;A<b;A++)m[A-3]=arguments[A];for(const t of Array.prototype.slice.call(m))c.push(t);const{config:j}=this;let O=0;if(v(e)&&v(s[e])?e=s[e]:g(e)?(n=r,r=e,e="error"):v(e)&&-1!==i.indexOf(e)||(n=r,r=e,e=this.getNormalizedLevel(e),O=-1),-1===j.levels.indexOf(e))return;let E,S=!1;if((d(r)||Array.isArray(r))&&v(n)){S=!0;const e=n;n=r,r=v(e)&&c.length>=3+O?f(...c.slice(2+O)):e}if(y(r)&&(r=e),1!==c.slice(1+O).length||v(r)||g(r))if(!S&&c.length>=4+O){r=void 0,n={};const t=[];for(const e of c)g(e)?p.push(e):v(e)&&t.push(e);0===p.length&&t.length>0?r=f(...t):p.length>0&&"log"===e&&(e="error")}else if(!S&&c.length===3+O&&v(r)&&l.some(e=>-1!==r.indexOf(e)))r=f(r,n),n={};else if(g(r)){if(g(n)){p.push(n);for(const e of c.slice(2+O))n!==e&&g(e)&&p.push(e);n={}}}else g(n)?(p.push(n),n={}):d(n)||y(n)||null===n?v(r)||(r=f(r)):(r=f(r,n),n={});else n={message:r},r=e;y(n)||d(n)?d(n)||(n={}):n={original_meta:n},g(r)&&(p.unshift(r),r=void 0),d(n.err)&&(g(n.err)&&p.push(n.err),n.original_err=g(n.err)?_(n.err):n.err),p.length>0&&(E=function(e){if(0!==(e=e.filter(o)).length)return 1===e.length?e[0]:new t(e)}(p),n.err=_(E),v(r)||(r=E.message)),n.args=c,n.level=e,this.appInfo&&(n.app=this.appInfo);const T=-1===O?"log":e;if(!h(this.config.meta.remappedFields))for(const t of Object.keys(this.config.meta.remappedFields))if(P(n,this.config.meta.remappedFields[t],u(n,t)),B(n,t),this.config.meta.cleanupRemapping){const e=t.lastIndexOf(".");if(-1===e)continue;const r=t.slice(0,e);h(u(n,r))&&B(n,r)}if(!h(this.config.meta.omittedFields)||!h(this.config.meta.pickedFields)){const e=function(e){const t=[];return function e(r,n){for(const o of Object.keys(r)){const i=r[o],s=n?n+"."+o:o;a(i)?e(i,s):t.push(s)}}(e),t}(n);if(!h(this.config.meta.omittedFields))for(const t of this.config.meta.omittedFields){let r=e.length;for(;r--;)e[r]!==t&&0!==e[r].indexOf(t+".")||e.splice(r,1)}if(!h(this.config.meta.pickedFields))for(const t of this.config.meta.pickedFields){const r=t.indexOf("."),n=t.slice(0,r+1);if(-1!==r){let t=e.length;for(;t--;)0===e[t].indexOf(n)&&e.splice(t,1)}-1===e.indexOf(t)&&e.push(t)}n=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:".";if(n=e,"[object Object]"!==Object.prototype.toString.call(n)||!t||!Array.isArray(t)&&"string"!=typeof t)return{};var n;const{length:o}=t;if("string"==typeof t||o<2){const n="string"==typeof t?t:t[0],o=u(e,n,r);return void 0!==o?P({},n,o,r):{}}return((e,t,r,n)=>{const o={};for(let i=0;i<r;i++){const r=t[i],s=u(e,r,n);void 0!==s&&P(o,r,s,n)}return o})(e,t,o,r)}(n,e)}for(const t of this.config.hooks.pre)[E,r,n]=t(T,E,r,n);j.silent||(g(E)&&j.showStack?!j.meta.show||h(n)?this.config.logger[T](E):this.config.logger[T](E,n):!j.meta.show||h(n)?this.config.logger[T](r):this.config.logger[T](r,n)),w(this.config.hooks.post,e=>e(T,E,r,n)).then().catch(e=>{this.config.logger.error(e)})}}}).call(this)}.call(this,R),ie}));
|
package/lib/index.js
CHANGED
|
@@ -2,64 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
// eslint-disable-next-line import/no-unassigned-import
|
|
4
4
|
require('console-polyfill');
|
|
5
|
-
|
|
6
5
|
const combine = require('maybe-combine-errors');
|
|
7
|
-
|
|
8
6
|
const format = require('@ladjs/format-util');
|
|
9
|
-
|
|
10
7
|
const formatSpecifiers = require('format-specifiers');
|
|
11
|
-
|
|
12
8
|
const get = require('@strikeentco/get');
|
|
13
|
-
|
|
14
9
|
const isError = require('iserror');
|
|
15
|
-
|
|
16
10
|
const mergeOptions = require('merge-options');
|
|
17
|
-
|
|
18
11
|
const pMapSeries = require('p-map-series');
|
|
19
|
-
|
|
20
12
|
const parseAppInfo = require('parse-app-info');
|
|
21
|
-
|
|
22
13
|
const parseErr = require('parse-err');
|
|
23
|
-
|
|
24
14
|
const pickDeep = require('pick-deep');
|
|
25
|
-
|
|
26
15
|
const set = require('@strikeentco/set');
|
|
27
|
-
|
|
28
16
|
const unset = require('unset-value');
|
|
29
|
-
|
|
30
17
|
const {
|
|
31
18
|
boolean
|
|
32
19
|
} = require('boolean');
|
|
33
|
-
|
|
34
20
|
const pkg = require('../package.json');
|
|
35
|
-
|
|
36
21
|
const omittedLoggerKeys = new Set(['config', 'log']);
|
|
37
22
|
const levels = ['trace', 'debug', 'info', 'warn', 'error', 'fatal'];
|
|
38
23
|
const aliases = {
|
|
39
24
|
warning: 'warn',
|
|
40
25
|
err: 'error'
|
|
41
26
|
};
|
|
42
|
-
const levelError = `\`level\` invalid, must be: ${levels.join(', ')}`;
|
|
27
|
+
const levelError = `\`level\` invalid, must be: ${levels.join(', ')}`;
|
|
43
28
|
|
|
29
|
+
// <https://github.com/sindresorhus/is-plain-obj/blob/main/index.js>
|
|
44
30
|
function isPlainObject(value) {
|
|
45
31
|
if (typeof value !== 'object' || value === null) {
|
|
46
32
|
return false;
|
|
47
33
|
}
|
|
48
|
-
|
|
49
34
|
const prototype = Object.getPrototypeOf(value);
|
|
50
35
|
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
51
|
-
}
|
|
52
|
-
|
|
36
|
+
}
|
|
53
37
|
|
|
38
|
+
// <https://github.com/GeenenTijd/dotify/blob/master/dotify.js>
|
|
54
39
|
function dotifyToArray(obj) {
|
|
55
40
|
const res = [];
|
|
56
|
-
|
|
57
41
|
function recurse(obj, current) {
|
|
58
42
|
for (const key of Object.keys(obj)) {
|
|
59
43
|
const value = obj[key];
|
|
60
44
|
const newKey = current ? current + '.' + key : key; // joined key with dot
|
|
61
45
|
// if (value && typeof value === 'object' && !(value instanceof Date) && !ObjectID.isValid(value)) {
|
|
62
|
-
|
|
63
46
|
if (isPlainObject(value)) {
|
|
64
47
|
recurse(value, newKey); // it's a nested object, so do it again
|
|
65
48
|
} else {
|
|
@@ -67,51 +50,40 @@ function dotifyToArray(obj) {
|
|
|
67
50
|
}
|
|
68
51
|
}
|
|
69
52
|
}
|
|
70
|
-
|
|
71
53
|
recurse(obj);
|
|
72
54
|
return res;
|
|
73
|
-
}
|
|
74
|
-
|
|
55
|
+
}
|
|
75
56
|
|
|
57
|
+
// <https://stackoverflow.com/a/43233163>
|
|
76
58
|
function isEmpty(value) {
|
|
77
59
|
return value === undefined || value === null || typeof value === 'object' && Object.keys(value).length === 0 || typeof value === 'string' && value.trim().length === 0;
|
|
78
60
|
}
|
|
79
|
-
|
|
80
61
|
function isNull(value) {
|
|
81
62
|
return value === null;
|
|
82
63
|
}
|
|
83
|
-
|
|
84
64
|
function isUndefined(value) {
|
|
85
65
|
return typeof value === 'undefined';
|
|
86
66
|
}
|
|
87
|
-
|
|
88
67
|
function isObject(value) {
|
|
89
68
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
90
69
|
}
|
|
91
|
-
|
|
92
70
|
function isString(value) {
|
|
93
71
|
return typeof value === 'string';
|
|
94
72
|
}
|
|
95
|
-
|
|
96
73
|
function isFunction(value) {
|
|
97
74
|
return typeof value === 'function';
|
|
98
75
|
}
|
|
99
|
-
|
|
100
76
|
class Axe {
|
|
101
77
|
constructor() {
|
|
102
78
|
var _this = this;
|
|
103
|
-
|
|
104
79
|
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
105
80
|
const remappedFields = {};
|
|
106
|
-
|
|
107
81
|
if (process.env.AXE_REMAPPED_META_FIELDS) {
|
|
108
82
|
const arr = process.env.AXE_REMAPPED_META_FIELDS.split(',').map(v => v.split(':'));
|
|
109
|
-
|
|
110
83
|
for (const [prop, value] of arr) {
|
|
111
84
|
remappedFields[prop] = value;
|
|
112
85
|
}
|
|
113
86
|
}
|
|
114
|
-
|
|
115
87
|
this.config = mergeOptions({
|
|
116
88
|
showStack: process.env.AXE_SHOW_STACK ? boolean(process.env.AXE_SHOW_STACK) : true,
|
|
117
89
|
meta: Object.assign({
|
|
@@ -134,15 +106,15 @@ class Axe {
|
|
|
134
106
|
}, typeof config.hooks === 'object' ? config.hooks : {})
|
|
135
107
|
}, config);
|
|
136
108
|
this.appInfo = this.config.appInfo ? isFunction(parseAppInfo) ? parseAppInfo() : false : false;
|
|
137
|
-
this.log = this.log.bind(this);
|
|
109
|
+
this.log = this.log.bind(this);
|
|
138
110
|
|
|
111
|
+
// Inherit methods from parent logger
|
|
139
112
|
const methods = Object.keys(this.config.logger).filter(key => !omittedLoggerKeys.has(key));
|
|
140
|
-
|
|
141
113
|
for (const element of methods) {
|
|
142
114
|
this[element] = this.config.logger[element];
|
|
143
|
-
}
|
|
144
|
-
|
|
115
|
+
}
|
|
145
116
|
|
|
117
|
+
// Bind helper functions for each log level
|
|
146
118
|
for (const element of levels) {
|
|
147
119
|
// Ensure function exists in logger passed
|
|
148
120
|
if (typeof this.config.logger[element] !== 'function') {
|
|
@@ -151,95 +123,87 @@ class Axe {
|
|
|
151
123
|
} else {
|
|
152
124
|
this.config.logger[element] = this.config.logger.info || this.config.logger.log;
|
|
153
125
|
}
|
|
154
|
-
}
|
|
155
|
-
|
|
126
|
+
}
|
|
156
127
|
|
|
128
|
+
// Bind log handler which normalizes args and populates meta
|
|
157
129
|
this[element] = function () {
|
|
158
130
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
159
131
|
args[_key] = arguments[_key];
|
|
160
132
|
}
|
|
161
|
-
|
|
162
133
|
return _this.log(element, ...Array.prototype.slice.call(args));
|
|
163
134
|
};
|
|
164
135
|
}
|
|
165
|
-
|
|
166
136
|
this.setLevel = this.setLevel.bind(this);
|
|
167
137
|
this.getNormalizedLevel = this.getNormalizedLevel.bind(this);
|
|
168
|
-
this.setName = this.setName.bind(this);
|
|
138
|
+
this.setName = this.setName.bind(this);
|
|
169
139
|
|
|
170
|
-
|
|
140
|
+
// Set the logger name
|
|
141
|
+
if (this.config.name) this.setName(this.config.name);
|
|
171
142
|
|
|
172
|
-
|
|
143
|
+
// Set the logger level
|
|
144
|
+
this.setLevel(this.config.level);
|
|
173
145
|
|
|
146
|
+
// Aliases
|
|
174
147
|
this.err = this.error;
|
|
175
|
-
this.warning = this.warn;
|
|
148
|
+
this.warning = this.warn;
|
|
176
149
|
|
|
150
|
+
// Pre and Post Hooks
|
|
177
151
|
this.pre = function (level, fn) {
|
|
178
152
|
this.config.hooks.pre.push(function (_level) {
|
|
179
153
|
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
180
154
|
args[_key2 - 1] = arguments[_key2];
|
|
181
155
|
}
|
|
182
|
-
|
|
183
156
|
if (level !== _level) return [...args];
|
|
184
157
|
return fn(...args);
|
|
185
158
|
});
|
|
186
159
|
};
|
|
187
|
-
|
|
188
160
|
this.post = function (level, fn) {
|
|
189
161
|
this.config.hooks.post.push(function (_level) {
|
|
190
162
|
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
191
163
|
args[_key3 - 1] = arguments[_key3];
|
|
192
164
|
}
|
|
193
|
-
|
|
194
165
|
if (level !== _level) return [...args];
|
|
195
166
|
return fn(...args);
|
|
196
167
|
});
|
|
197
168
|
};
|
|
198
169
|
}
|
|
199
|
-
|
|
200
170
|
setLevel(level) {
|
|
201
|
-
if (!isString(level) || levels.indexOf(level) === -1) throw new Error(levelError);
|
|
202
|
-
|
|
203
|
-
if (isString(this.config.logger.logLevel)) this.config.logger.logLevel = level;else this.config.logger.level = level;
|
|
171
|
+
if (!isString(level) || levels.indexOf(level) === -1) throw new Error(levelError);
|
|
172
|
+
// Support signale logger and other loggers that use `logLevel`
|
|
173
|
+
if (isString(this.config.logger.logLevel)) this.config.logger.logLevel = level;else this.config.logger.level = level;
|
|
174
|
+
// Adjusts `this.config.levels` array
|
|
204
175
|
// so that it has all proceeding (inclusive)
|
|
205
|
-
|
|
206
176
|
this.config.levels = levels.slice(levels.indexOf(level));
|
|
207
177
|
}
|
|
208
|
-
|
|
209
178
|
getNormalizedLevel(level) {
|
|
210
179
|
if (!isString(level)) return 'info';
|
|
211
180
|
if (isString(aliases[level])) return aliases[level];
|
|
212
181
|
if (levels.indexOf(level) === -1) return 'info';
|
|
213
182
|
return level;
|
|
214
183
|
}
|
|
215
|
-
|
|
216
184
|
setName(name) {
|
|
217
|
-
if (!isString(name)) throw new Error('`name` must be a String');
|
|
218
|
-
|
|
185
|
+
if (!isString(name)) throw new Error('`name` must be a String');
|
|
186
|
+
// Support signale logger and other loggers that use `scope`
|
|
219
187
|
if (isString(this.config.logger.scope)) this.config.logger.scope = name;else this.config.logger.name = name;
|
|
220
|
-
}
|
|
221
|
-
|
|
188
|
+
}
|
|
222
189
|
|
|
190
|
+
// eslint-disable-next-line complexity
|
|
223
191
|
log(level, message, meta) {
|
|
224
192
|
const originalArgs = [];
|
|
225
193
|
const errors = [];
|
|
226
194
|
if (!isUndefined(level)) originalArgs.push(level);
|
|
227
195
|
if (!isUndefined(message)) originalArgs.push(message);
|
|
228
196
|
if (!isUndefined(meta)) originalArgs.push(meta);
|
|
229
|
-
|
|
230
197
|
for (var _len4 = arguments.length, args = new Array(_len4 > 3 ? _len4 - 3 : 0), _key4 = 3; _key4 < _len4; _key4++) {
|
|
231
198
|
args[_key4 - 3] = arguments[_key4];
|
|
232
199
|
}
|
|
233
|
-
|
|
234
200
|
for (const arg of Array.prototype.slice.call(args)) {
|
|
235
201
|
originalArgs.push(arg);
|
|
236
202
|
}
|
|
237
|
-
|
|
238
203
|
const {
|
|
239
204
|
config
|
|
240
205
|
} = this;
|
|
241
206
|
let modifier = 0;
|
|
242
|
-
|
|
243
207
|
if (isString(level) && isString(aliases[level])) {
|
|
244
208
|
level = aliases[level];
|
|
245
209
|
} else if (isError(level)) {
|
|
@@ -251,24 +215,25 @@ class Axe {
|
|
|
251
215
|
message = level;
|
|
252
216
|
level = this.getNormalizedLevel(level);
|
|
253
217
|
modifier = -1;
|
|
254
|
-
}
|
|
255
|
-
|
|
218
|
+
}
|
|
256
219
|
|
|
257
|
-
|
|
220
|
+
// Return early if it is not a valid logging level
|
|
221
|
+
if (config.levels.indexOf(level) === -1) return;
|
|
258
222
|
|
|
223
|
+
// Bunyan support (meta, message, ...args)
|
|
259
224
|
let isBunyan = false;
|
|
260
|
-
|
|
261
225
|
if ((isObject(message) || Array.isArray(message)) && isString(meta)) {
|
|
262
226
|
isBunyan = true;
|
|
263
227
|
const _meta = meta;
|
|
264
228
|
meta = message;
|
|
265
229
|
message = isString(_meta) && originalArgs.length >= 3 + modifier ? format(...originalArgs.slice(2 + modifier)) : _meta;
|
|
266
|
-
}
|
|
230
|
+
}
|
|
267
231
|
|
|
232
|
+
// If message was undefined then set it to level
|
|
233
|
+
if (isUndefined(message)) message = level;
|
|
268
234
|
|
|
269
|
-
|
|
235
|
+
// If only `message` was passed then if it was an Object
|
|
270
236
|
// preserve it as an Object by setting it as meta
|
|
271
|
-
|
|
272
237
|
if (originalArgs.slice(1 + modifier).length === 1 && !isString(message) && !isError(message)) {
|
|
273
238
|
meta = {
|
|
274
239
|
message
|
|
@@ -278,11 +243,9 @@ class Axe {
|
|
|
278
243
|
message = undefined;
|
|
279
244
|
meta = {};
|
|
280
245
|
const messages = [];
|
|
281
|
-
|
|
282
246
|
for (const arg of originalArgs) {
|
|
283
247
|
if (isError(arg)) errors.push(arg);else if (isString(arg)) messages.push(arg);
|
|
284
248
|
}
|
|
285
|
-
|
|
286
249
|
if (errors.length === 0 && messages.length > 0) message = format(...messages);else if (errors.length > 0 && level === 'log') level = 'error';
|
|
287
250
|
} else if (!isBunyan && originalArgs.length === 3 + modifier && isString(message) && formatSpecifiers.some(t => message.indexOf(t) !== -1)) {
|
|
288
251
|
// Otherwise if there are three args and if the `message` contains
|
|
@@ -305,49 +268,48 @@ class Axe {
|
|
|
305
268
|
message = format(message);
|
|
306
269
|
}
|
|
307
270
|
} else if (isError(meta)) {
|
|
308
|
-
errors.push(meta);
|
|
309
|
-
|
|
271
|
+
errors.push(meta);
|
|
272
|
+
// handle additional args
|
|
310
273
|
for (const arg of originalArgs.slice(2 + modifier)) {
|
|
311
274
|
// should skip this better with slice and modifier adjustment
|
|
312
275
|
if (meta === arg) continue;
|
|
313
276
|
if (isError(arg)) errors.push(arg);
|
|
314
277
|
}
|
|
315
|
-
|
|
316
278
|
meta = {};
|
|
317
279
|
}
|
|
318
|
-
|
|
319
280
|
if (!isUndefined(meta) && !isObject(meta)) meta = {
|
|
320
281
|
original_meta: meta
|
|
321
282
|
};else if (!isObject(meta)) meta = {};
|
|
322
|
-
|
|
323
283
|
if (isError(message)) {
|
|
324
284
|
errors.unshift(message);
|
|
325
285
|
message = undefined;
|
|
326
|
-
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//
|
|
327
289
|
// rewrite `meta.err` to `meta.original_err` for consistency
|
|
328
290
|
// (in case someone has an object with `.err` property on it with an error)
|
|
329
291
|
//
|
|
330
|
-
|
|
331
|
-
|
|
332
292
|
if (isObject(meta.err)) {
|
|
333
293
|
if (isError(meta.err)) errors.push(meta.err);
|
|
334
294
|
meta.original_err = isError(meta.err) ? parseErr(meta.err) : meta.err;
|
|
335
295
|
}
|
|
336
|
-
|
|
337
296
|
let err;
|
|
338
|
-
|
|
339
297
|
if (errors.length > 0) {
|
|
340
298
|
err = combine(errors);
|
|
341
299
|
meta.err = parseErr(err);
|
|
342
300
|
if (!isString(message)) message = err.message;
|
|
343
|
-
}
|
|
301
|
+
}
|
|
344
302
|
|
|
303
|
+
// Set `args` prop with original arguments passed
|
|
304
|
+
meta.args = originalArgs;
|
|
345
305
|
|
|
346
|
-
|
|
306
|
+
// Set default level on meta
|
|
307
|
+
meta.level = level;
|
|
347
308
|
|
|
348
|
-
|
|
309
|
+
// Add `app` object to metadata
|
|
310
|
+
if (this.appInfo) meta.app = this.appInfo;
|
|
349
311
|
|
|
350
|
-
|
|
312
|
+
//
|
|
351
313
|
// determine log method to use
|
|
352
314
|
//
|
|
353
315
|
// if we didn't pass a level as a method
|
|
@@ -356,8 +318,9 @@ class Axe {
|
|
|
356
318
|
//
|
|
357
319
|
// and fatal should use error (e.g. in browser)
|
|
358
320
|
//
|
|
321
|
+
const method = modifier === -1 ? 'log' : level;
|
|
359
322
|
|
|
360
|
-
|
|
323
|
+
//
|
|
361
324
|
// NOTE: using lodash _.omit and _.pick would have been _very slow_
|
|
362
325
|
//
|
|
363
326
|
// const omittedAndPickedFields = {
|
|
@@ -373,8 +336,8 @@ class Axe {
|
|
|
373
336
|
if (!isEmpty(this.config.meta.remappedFields)) {
|
|
374
337
|
for (const key of Object.keys(this.config.meta.remappedFields)) {
|
|
375
338
|
set(meta, this.config.meta.remappedFields[key], get(meta, key));
|
|
376
|
-
unset(meta, key);
|
|
377
|
-
|
|
339
|
+
unset(meta, key);
|
|
340
|
+
// cleanup empty objects after remapping
|
|
378
341
|
if (this.config.meta.cleanupRemapping) {
|
|
379
342
|
const index = key.lastIndexOf('.');
|
|
380
343
|
if (index === -1) continue;
|
|
@@ -383,9 +346,9 @@ class Axe {
|
|
|
383
346
|
}
|
|
384
347
|
}
|
|
385
348
|
}
|
|
386
|
-
|
|
387
349
|
if (!isEmpty(this.config.meta.omittedFields) || !isEmpty(this.config.meta.pickedFields)) {
|
|
388
|
-
const dotified = dotifyToArray(meta);
|
|
350
|
+
const dotified = dotifyToArray(meta);
|
|
351
|
+
// dotified = [
|
|
389
352
|
// 'err.name',
|
|
390
353
|
// 'err.message',
|
|
391
354
|
// 'err.stack',
|
|
@@ -401,13 +364,11 @@ class Axe {
|
|
|
401
364
|
for (const prop of this.config.meta.omittedFields) {
|
|
402
365
|
// <https://stackoverflow.com/a/9882349>
|
|
403
366
|
let i = dotified.length;
|
|
404
|
-
|
|
405
367
|
while (i--) {
|
|
406
368
|
if (dotified[i] === prop || dotified[i].indexOf(`${prop}.`) === 0) dotified.splice(i, 1);
|
|
407
369
|
}
|
|
408
370
|
}
|
|
409
371
|
}
|
|
410
|
-
|
|
411
372
|
if (!isEmpty(this.config.meta.pickedFields)) {
|
|
412
373
|
for (const prop of this.config.meta.pickedFields) {
|
|
413
374
|
// response.headers.boop
|
|
@@ -419,30 +380,28 @@ class Axe {
|
|
|
419
380
|
// so we need to split by the first period and omit any keys from dotified starting with it
|
|
420
381
|
const index = prop.indexOf('.');
|
|
421
382
|
const key = prop.slice(0, index + 1);
|
|
422
|
-
|
|
423
383
|
if (index !== -1) {
|
|
424
384
|
let i = dotified.length;
|
|
425
|
-
|
|
426
385
|
while (i--) {
|
|
427
386
|
if (dotified[i].indexOf(key) === 0) dotified.splice(i, 1);
|
|
428
387
|
}
|
|
429
|
-
}
|
|
430
|
-
|
|
388
|
+
}
|
|
431
389
|
|
|
390
|
+
// finally add it if it did not already exist
|
|
432
391
|
if (dotified.indexOf(prop) === -1) dotified.push(prop);
|
|
433
392
|
}
|
|
434
|
-
}
|
|
435
|
-
|
|
393
|
+
}
|
|
436
394
|
|
|
395
|
+
// now we call pick-deep using the final array
|
|
437
396
|
meta = pickDeep(meta, dotified);
|
|
438
|
-
}
|
|
439
|
-
|
|
397
|
+
}
|
|
440
398
|
|
|
399
|
+
// pre-hooks
|
|
441
400
|
for (const hook of this.config.hooks.pre) {
|
|
442
401
|
[err, message, meta] = hook(method, err, message, meta);
|
|
443
|
-
}
|
|
444
|
-
|
|
402
|
+
}
|
|
445
403
|
|
|
404
|
+
// only invoke logger methods if it was not silent
|
|
446
405
|
if (!config.silent) {
|
|
447
406
|
// Show stack trace if necessary (along with any metadata)
|
|
448
407
|
if (isError(err) && config.showStack) {
|
|
@@ -456,14 +415,12 @@ class Axe {
|
|
|
456
415
|
} else {
|
|
457
416
|
this.config.logger[method](message, meta);
|
|
458
417
|
}
|
|
459
|
-
}
|
|
460
|
-
|
|
418
|
+
}
|
|
461
419
|
|
|
420
|
+
// post-hooks
|
|
462
421
|
pMapSeries(this.config.hooks.post, hook => hook(method, err, message, meta)).then().catch(err => {
|
|
463
422
|
this.config.logger.error(err);
|
|
464
423
|
});
|
|
465
424
|
}
|
|
466
|
-
|
|
467
425
|
}
|
|
468
|
-
|
|
469
426
|
module.exports = Axe;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axe",
|
|
3
3
|
"description": "Axe is a logger-agnostic wrapper that normalizes logs regardless of argument style. Great for large development teams, old and new projects, and works with Pino, Bunyan, Winston, console, and more. It is lightweight, performant, highly-configurable, and automatically adds OS, CPU, and Git information to your logs. It supports hooks (useful for masking sensitive data) and dot-notation remapping, omitting, and picking of log metadata properties. Made for Forward Email, Lad, and Cabin.",
|
|
4
|
-
"version": "10.0.
|
|
4
|
+
"version": "10.0.2",
|
|
5
5
|
"author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com)",
|
|
6
6
|
"browser": {
|
|
7
7
|
"parse-app-info": false
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"rimraf": "^3.0.2",
|
|
61
61
|
"signale": "^1.4.0",
|
|
62
62
|
"sinon": "^14.0.0",
|
|
63
|
-
"tinyify": "
|
|
63
|
+
"tinyify": "3.0.0",
|
|
64
64
|
"xo": "^0.50.0"
|
|
65
65
|
},
|
|
66
66
|
"engines": {
|