@cardsgame/utils
Advanced tools
Comparing version 0.11.0 to 0.12.0
/** | ||
* Returns the last item of an array | ||
*/ | ||
export declare const lastItem: <T = any>(array: T[]) => T; | ||
/** | ||
* Compares if two arrays contain same elements. | ||
@@ -3,0 +7,0 @@ */ |
@@ -24,4 +24,11 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pickMostCommonProp = exports.arrayWith = exports.shuffle = exports.sortAlphaNumerically = exports.sortAlphabetically = exports.compare = void 0; | ||
exports.pickMostCommonProp = exports.arrayWith = exports.shuffle = exports.sortAlphaNumerically = exports.sortAlphabetically = exports.compare = exports.lastItem = void 0; | ||
/** | ||
* Returns the last item of an array | ||
*/ | ||
var lastItem = function (array) { | ||
return Array.isArray(array) ? array[array.length - 1] : undefined; | ||
}; | ||
exports.lastItem = lastItem; | ||
/** | ||
* Compares if two arrays contain same elements. | ||
@@ -28,0 +35,0 @@ */ |
export * from "./arrays"; | ||
export * from "./entities"; | ||
export * from "./functions"; | ||
export * from "./logs"; | ||
@@ -4,0 +5,0 @@ export * from "./numbers"; |
@@ -15,2 +15,3 @@ "use strict"; | ||
__exportStar(require("./entities"), exports); | ||
__exportStar(require("./functions"), exports); | ||
__exportStar(require("./logs"), exports); | ||
@@ -17,0 +18,0 @@ __exportStar(require("./numbers"), exports); |
import Chalk from "chalk"; | ||
/** | ||
* Ditch chrome dev node debugging. It was an adventure, | ||
* but cli logs are enough. | ||
* @deprecated | ||
*/ | ||
export declare const IS_SERVER_DEBUGGER_CHROME: boolean; | ||
export declare const chalk: Chalk.Chalk; | ||
@@ -21,4 +15,12 @@ export declare enum LogLevels { | ||
info: (...args: any[]) => void; | ||
/** | ||
* @deprecated use `log()` instead | ||
*/ | ||
notice: (...args: any[]) => void; | ||
log: (...args: any[]) => void; | ||
/** | ||
* @deprecated use `debug()` instead | ||
*/ | ||
verbose: (...args: any[]) => void; | ||
debug: (...args: any[]) => void; | ||
group: (...args: any[]) => void; | ||
@@ -32,4 +34,12 @@ groupCollapsed: (...args: any[]) => void; | ||
info: (...any: any[]) => void; | ||
/** | ||
* @deprecated use `log()` instead | ||
*/ | ||
notice: (...any: any[]) => void; | ||
log: (...any: any[]) => void; | ||
/** | ||
* @deprecated use `debug()` instead | ||
*/ | ||
verbose: (...any: any[]) => void; | ||
debug: (...any: any[]) => void; | ||
group: (...any: any[]) => void; | ||
@@ -36,0 +46,0 @@ groupCollapsed: (...any: any[]) => void; |
181
lib/logs.js
@@ -27,22 +27,10 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Logs = exports.logs = exports.LogLevels = exports.chalk = exports.IS_SERVER_DEBUGGER_CHROME = void 0; | ||
exports.Logs = exports.logs = exports.LogLevels = exports.chalk = void 0; | ||
var chalk_1 = __importDefault(require("chalk")); | ||
var utils_1 = require("./utils"); | ||
var isBrowser = new Function("try {return this===window;}catch(e){ return false;}")(); | ||
/** | ||
* Ditch chrome dev node debugging. It was an adventure, | ||
* but cli logs are enough. | ||
* @deprecated | ||
*/ | ||
exports.IS_SERVER_DEBUGGER_CHROME = (function () { | ||
try { | ||
return process ? Boolean(process.env.LOGS_CHROME) : false; | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
})(); | ||
var functions_1 = require("./functions"); | ||
var utils_1 = require("./logger/utils"); | ||
exports.chalk = new chalk_1.default.Instance({ | ||
level: isBrowser ? 0 : exports.IS_SERVER_DEBUGGER_CHROME ? 0 : 1, | ||
level: utils_1.isBrowser ? 0 : 1, | ||
}); | ||
var BROWSER_DEBUG_STYLE = "margin-left:2em;"; | ||
var LogLevels; | ||
@@ -86,10 +74,3 @@ (function (LogLevels) { | ||
}; | ||
var minifyEntity = function (_a) { | ||
var type = _a.type, name = _a.name; | ||
return type + ":" + name; | ||
}; | ||
var syntaxHighlight = function (arg) { | ||
if (exports.IS_SERVER_DEBUGGER_CHROME) { | ||
return arg; | ||
} | ||
if (typeof arg === "string") { | ||
@@ -106,3 +87,3 @@ return exports.chalk.gray(arg); | ||
if (arg && arg._state) { | ||
return exports.chalk.yellow(minifyEntity(arg)); | ||
return exports.chalk.yellow(utils_1.minifyEntity(arg)); | ||
} | ||
@@ -116,6 +97,8 @@ return arg; | ||
var logsPreExport; | ||
if (isBrowser) { | ||
if (utils_1.isBrowser) { | ||
logsPreExport = { | ||
verbose: console.debug.bind(window.console), | ||
debug: console.debug.bind(window.console), | ||
notice: console.log.bind(window.console), | ||
log: console.log.bind(window.console), | ||
info: console.info.bind(window.console), | ||
@@ -129,3 +112,3 @@ warn: console.warn.bind(window.console), | ||
} | ||
else if (!exports.IS_SERVER_DEBUGGER_CHROME) { | ||
else { | ||
logsPreExport = { | ||
@@ -142,2 +125,12 @@ verbose: function () { | ||
}, | ||
debug: function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
console.debug.apply(console, __spreadArray([ | ||
_getIndent(), | ||
"\t" | ||
], __read(args.map(function (arg) { return exports.chalk.gray(arg); })))); | ||
}, | ||
notice: function (first) { | ||
@@ -158,2 +151,17 @@ var args = []; | ||
}, | ||
log: function (first) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
if (args.length > 0) { | ||
console.log.apply(console, __spreadArray([ | ||
_getIndent(), | ||
first + ":" | ||
], __read(args.map(syntaxHighlight)))); | ||
} | ||
else { | ||
console.log.call(console, exports.chalk.gray(_getIndent() + first)); | ||
} | ||
}, | ||
info: function (first) { | ||
@@ -191,3 +199,3 @@ var args = []; | ||
} | ||
logsPreExport.notice.apply(logsPreExport, __spreadArray(["\u250D\u2501" + first], __read(args))); | ||
logsPreExport.log.apply(logsPreExport, __spreadArray(["\u250D\u2501" + first], __read(args))); | ||
_indentLevel++; | ||
@@ -200,3 +208,3 @@ }, | ||
} | ||
logsPreExport.notice.apply(logsPreExport, __spreadArray(["\u250D\u2501" + first], __read(args))); | ||
logsPreExport.log.apply(logsPreExport, __spreadArray(["\u250D\u2501" + first], __read(args))); | ||
_indentLevel++; | ||
@@ -211,56 +219,11 @@ }, | ||
_indentLevel = Math.max(_indentLevel - 1, 0); | ||
logsPreExport.notice.apply(logsPreExport, __spreadArray(["\u2515\u2501" + first], __read(args))); | ||
logsPreExport.log.apply(logsPreExport, __spreadArray(["\u2515\u2501" + first], __read(args))); | ||
}, | ||
}; | ||
} | ||
else { | ||
var styles_1 = { | ||
common: "padding: 1px 5px; margin: -1px 0;", | ||
info: "color: white; background: #2196f3", | ||
}; | ||
logsPreExport = { | ||
verbose: console.debug.bind(console), | ||
notice: console.log.bind(console), | ||
info: function (first) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
return console.info.apply(console, __spreadArray([ | ||
"%c " + first + " ", | ||
styles_1.common + styles_1.info | ||
], __read(args.map(syntaxHighlight)))); | ||
}, | ||
warn: console.warn.bind(console), | ||
error: console.error.bind(console), | ||
group: function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
// Silence one-off console.log | ||
var tmp = console.log; | ||
global.console.log = utils_1.noop; | ||
global.console.group.apply(console, args); | ||
global.console.log = tmp; | ||
}, | ||
groupCollapsed: function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
// Silence one-off console.log | ||
var tmp = console.log; | ||
global.console.log = utils_1.noop; | ||
global.console.groupCollapsed.apply(console, args); | ||
global.console.log = tmp; | ||
}, | ||
groupEnd: console.groupEnd.bind(console), | ||
}; | ||
} | ||
try { | ||
if (isBrowser && localStorage && localStorage.getItem("cardsDebug")) { | ||
if (utils_1.isBrowser && localStorage && localStorage.getItem("cardsDebug")) { | ||
setLogLevel(localStorage.getItem("cardsDebug")); | ||
} | ||
else if (!isBrowser) { | ||
else if (!utils_1.isBrowser) { | ||
setLogLevel(process.env.LOGS); | ||
@@ -274,15 +237,17 @@ } | ||
if (logLevel < LogLevels.error) { | ||
logsPreExport.error = utils_1.noop; | ||
logsPreExport.error = functions_1.noop; | ||
} | ||
if (logLevel < LogLevels.warn) { | ||
logsPreExport.warn = utils_1.noop; | ||
logsPreExport.warn = functions_1.noop; | ||
} | ||
if (logLevel < LogLevels.info) { | ||
logsPreExport.info = utils_1.noop; | ||
logsPreExport.info = functions_1.noop; | ||
} | ||
if (logLevel < LogLevels.notice) { | ||
logsPreExport.notice = utils_1.noop; | ||
logsPreExport.notice = functions_1.noop; | ||
logsPreExport.log = functions_1.noop; | ||
} | ||
if (logLevel < LogLevels.verbose) { | ||
logsPreExport.verbose = utils_1.noop; | ||
logsPreExport.verbose = functions_1.noop; | ||
logsPreExport.debug = functions_1.noop; | ||
} | ||
@@ -294,3 +259,3 @@ exports.logs = logsPreExport; | ||
this.enabled = enabled; | ||
if (isBrowser) { | ||
if (utils_1.isBrowser) { | ||
this.setupBrowserLogs(name, options.browserStyle); | ||
@@ -309,3 +274,3 @@ } | ||
logLevel < LogLevels.error && this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: function (first) { | ||
@@ -322,3 +287,3 @@ var args = []; | ||
logLevel < LogLevels.warn && this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: function (first) { | ||
@@ -335,3 +300,3 @@ var args = []; | ||
logLevel < LogLevels.info && this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: function (first) { | ||
@@ -346,5 +311,5 @@ var args = []; | ||
}; | ||
this["notice"] = | ||
this["log"] = this["notice"] = | ||
logLevel < LogLevels.notice && this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: function (first) { | ||
@@ -364,6 +329,6 @@ var args = []; | ||
}; | ||
var notice = this["notice"]; | ||
this["verbose"] = | ||
var _log = this["log"]; | ||
this["debug"] = this["verbose"] = | ||
logLevel < LogLevels.verbose && this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: function () { | ||
@@ -379,3 +344,3 @@ var args = []; | ||
this["group"] = !this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: function (first) { | ||
@@ -386,7 +351,7 @@ var args = []; | ||
} | ||
notice.apply(void 0, __spreadArray(["\u250D\u2501" + first], __read(args))); | ||
_log.apply(void 0, __spreadArray(["\u250D\u2501" + first], __read(args))); | ||
indentLevel++; | ||
}; | ||
this["groupCollapsed"] = !this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: function (first) { | ||
@@ -397,7 +362,7 @@ var args = []; | ||
} | ||
notice.apply(void 0, __spreadArray(["\u250D\u2501" + first], __read(args))); | ||
_log.apply(void 0, __spreadArray(["\u250D\u2501" + first], __read(args))); | ||
indentLevel++; | ||
}; | ||
this["groupEnd"] = !this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: function (first) { | ||
@@ -410,3 +375,3 @@ if (first === void 0) { first = "────────────"; } | ||
indentLevel = Math.max(indentLevel - 1, 0); | ||
notice.apply(void 0, __spreadArray(["\u2515\u2501" + first], __read(args))); | ||
_log.apply(void 0, __spreadArray(["\u2515\u2501" + first], __read(args))); | ||
}; | ||
@@ -417,3 +382,3 @@ }; | ||
logLevel < LogLevels.error && this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: (function () { | ||
@@ -424,3 +389,3 @@ return Function.prototype.bind.call(console.error, console, "%c " + name + " ", style); | ||
logLevel < LogLevels.warn && this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: (function () { | ||
@@ -431,26 +396,26 @@ return Function.prototype.bind.call(console.warn, console, "%c " + name + " ", style); | ||
logLevel < LogLevels.info && this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: (function () { | ||
return Function.prototype.bind.call(console.info, console, "%c " + name + " ", style); | ||
})(); | ||
this["notice"] = | ||
this["log"] = this["notice"] = | ||
logLevel < LogLevels.notice && this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: (function () { | ||
return Function.prototype.bind.call(console.log, console, "%c " + name + " ", style); | ||
})(); | ||
this["verbose"] = | ||
this["debug"] = this["verbose"] = | ||
logLevel < LogLevels.verbose && this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: (function () { | ||
return Function.prototype.bind.call(console.debug, console, "%c " + name + " ", style); | ||
return Function.prototype.bind.call(console.debug, console, "%c " + name + " ", style + BROWSER_DEBUG_STYLE); | ||
})(); | ||
this["group"] = !this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: console.group.bind(console, "%c " + name + " ", style); | ||
this["groupCollapsed"] = !this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: console.groupCollapsed.bind(console, "%c " + name + " ", style); | ||
this["groupEnd"] = !this.enabled | ||
? utils_1.noop | ||
? functions_1.noop | ||
: (function () { | ||
@@ -457,0 +422,0 @@ return Function.prototype.bind.call(console.groupEnd, console); |
@@ -7,4 +7,8 @@ export declare const deepClone: (value: unknown) => any; | ||
/** | ||
* @returns new object only with provided `keys` | ||
*/ | ||
export declare const pick: (object: Record<string, any>, keys: string[]) => Record<string, any>; | ||
/** | ||
* Resolves target object/property given source object and path. | ||
*/ | ||
export declare const resolve: (sourceObject: Record<string, any>, path: (string | number)[] | string, separator?: string) => any; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolve = exports.omit = exports.deepClone = void 0; | ||
exports.resolve = exports.pick = exports.omit = exports.deepClone = void 0; | ||
var deepClone = function (value) { | ||
@@ -34,2 +34,14 @@ if (typeof value === "function") { | ||
/** | ||
* @returns new object only with provided `keys` | ||
*/ | ||
var pick = function (object, keys) { | ||
return Object.keys(object) | ||
.filter(function (key) { return keys.includes(key); }) | ||
.reduce(function (obj, key) { | ||
obj[key] = object[key]; | ||
return obj; | ||
}, {}); | ||
}; | ||
exports.pick = pick; | ||
/** | ||
* Resolves target object/property given source object and path. | ||
@@ -36,0 +48,0 @@ */ |
@@ -6,3 +6,2 @@ /// <reference types="@cardsgame/types" /> | ||
export declare const def: <T>(...values: T[]) => T; | ||
export declare const noop: () => void; | ||
/** | ||
@@ -15,8 +14,2 @@ * Calls each function with the current argument | ||
/** | ||
* Executes function multiple times | ||
* @param length number of times function will be executed | ||
* @param func a function | ||
*/ | ||
export declare const times: (length: number, func: (idx: number) => any) => void; | ||
/** | ||
* Simple delay of execution. Use like this: `await timeout(50)` | ||
@@ -23,0 +16,0 @@ * @param ms milliseconds |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.applyMixins = exports.isObject = exports.isSet = exports.isMap = exports.timeout = exports.times = exports.compose = exports.noop = exports.def = void 0; | ||
exports.applyMixins = exports.isObject = exports.isSet = exports.isMap = exports.timeout = exports.compose = exports.def = void 0; | ||
/** | ||
@@ -15,4 +15,2 @@ * Returns first, *defined* value | ||
exports.def = def; | ||
var noop = function () { }; | ||
exports.noop = noop; | ||
/** | ||
@@ -42,11 +40,2 @@ * Calls each function with the current argument | ||
/** | ||
* Executes function multiple times | ||
* @param length number of times function will be executed | ||
* @param func a function | ||
*/ | ||
var times = function (length, func) { | ||
Array.from({ length: length }, func); | ||
}; | ||
exports.times = times; | ||
/** | ||
* Simple delay of execution. Use like this: `await timeout(50)` | ||
@@ -53,0 +42,0 @@ * @param ms milliseconds |
{ | ||
"name": "@cardsgame/utils", | ||
"version": "0.11.0", | ||
"version": "0.12.0", | ||
"description": "", | ||
@@ -26,3 +26,3 @@ "author": "Darek Greenly (https://darekgreenly.com)", | ||
"dependencies": { | ||
"@cardsgame/types": "^0.11.0", | ||
"@cardsgame/types": "^0.12.0", | ||
"chalk": "^4.1.0" | ||
@@ -33,3 +33,3 @@ }, | ||
}, | ||
"gitHead": "233b849950af0d5d62ef28974d011d164fad109e" | ||
"gitHead": "516bb1e6555bab3f8096a50511f3cec119952a17" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
36
1021
1
0
60569
+ Added@cardsgame/types@0.12.17(transitive)
- Removed@cardsgame/types@0.11.0(transitive)
Updated@cardsgame/types@^0.12.0