Created
January 29, 2020 16:11
-
-
Save Aleksey-Danchin/722df20ad92b7ae1d4fb7c6983496879 to your computer and use it in GitHub Desktop.
logStatisticRaport
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function () { | |
'use strict' | |
const state = {} | |
const baseClasses = [ | |
{ | |
type: Number, | |
label: "Number", | |
prototypes: ["toExponential", "toFixed", "toLocaleString", "toPrecision", "toSource", "toString", "valueOf"], | |
funcs: ["isFinite", "isInteger", "isNaN", "isSafeInteger", "parseFloat", "parseInt"] | |
}, | |
{ | |
type: Boolean, | |
label: "Boolean", | |
prototypes: ["toString", "valueOf"], | |
funcs: [] | |
}, | |
{ | |
type: Intl, | |
label: "Intl", | |
prototypes: [], | |
funcs: ["Collator", "DateTimeFormat", "NumberFormat"] | |
}, | |
{ | |
type: Promise, | |
label: "Promise", | |
prototypes: ["catch", "finally", "then"], | |
funcs: ["all", "allSettled", "race", "reject", "resolve"] | |
}, | |
{ | |
type: JSON, | |
label: "JSON", | |
prototypes: [], | |
funcs: ["stringify", "parse"] | |
}, | |
{ | |
type: Map, | |
label: "Map", | |
prototypes: [], | |
funcs: ["clear", "delete", "entries", "forEach", "get", "has", "keys", "set", "values"] | |
}, | |
{ | |
type: Set, | |
label: "Set", | |
prototypes: [], | |
funcs: ["add", "clear", "delete", "entries", "forEach", "has", "values"] | |
}, | |
{ | |
type: Math, | |
label: "Math", | |
prototypes: [], | |
funcs: ["abs", "acos", "acosh", "asin", "asinh", "atan", "atan2", "atanh", "cbrt", "ceil", "clz32", "cos", "cosh", "exp", "expm1", "floor", "fround", "hypot", "imul", "log", "log10", "log1p", "log2", "max", "min", "pow", "random", "round", "sign", "sin", "sinh", "sqrt", "tan", "tanh", "trunc"] | |
}, | |
{ | |
type: Array, | |
label: "Array", | |
prototypes: ["concat", "copyWithin", "entries", "every", "fill", "filter", "find", "findIndex", "flat", "flatMap", "forEach", "includes", "indexOf", "join", "keys", "lastIndexOf", "map", "pop", "push", "reduce", "reduceRight", "reverse", "shift", "slice", "some", "sort", "splice", "toLocaleString", "toSourse", "toString", "unshift", "values"], | |
funcs: [] | |
}, | |
{ | |
type: Date, | |
label: "Date", | |
prototypes: ["getDate", "getDay", "getFullYear", "getHours", "getMilliseconds", "getMinutes", "getMonth", "getSeconds", "getTime", "getYear", "setDate", "setFullYear", "setHours", "setMilliseconds", "setMinutes", "setMonth", "setSeconds", "setTime", "setYear", "toJSON", "toString", "valueOf"], | |
funcs: [] | |
}, | |
{ | |
type: String, | |
label: "String", | |
prototypes: ["charAt", "charCodeAt", "codePointAt", "concat", "endsWith", "includes", "indexOf", "lastIndexOf", "match", "padEnd", "padStart", "repeat", "replace", "search", "slice", "split", "startsWith", "substring", "substr", "trim", "trimRight", "trimLeft"], | |
funcs: ["fromCharCode", "fromCodePoint"] | |
} | |
] | |
for (const { type, label, prototypes, funcs, getters } of baseClasses) { | |
for (const prototype of prototypes) { | |
const originalFunction = type.prototype[prototype] | |
const key = `${label}.prototype.${prototype}` | |
if (!originalFunction) { | |
console.warn(`${key} feil`) | |
continue | |
} | |
state[key] = 0 | |
type.prototype[prototype] = function (...args) { | |
state[key]++ | |
return originalFunction.call(this, ...args) | |
} | |
} | |
for (const func of funcs) { | |
const originalFunction = type[func] | |
const key = `${label}.${func}` | |
if (!originalFunction) { | |
console.warn(`${key} feil`) | |
continue | |
} | |
state[key] = 0 | |
type[func] = function (...args) { | |
state[key]++ | |
return originalFunction.call(this, ...args) | |
} | |
} | |
} | |
window.logStatisticRaport = function logStatisticRaport () { | |
console.table(state) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment