@cardsgame/utils
Advanced tools
Comparing version 1.7.2 to 1.7.4
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pickMostCommonProp = exports.arrayWith = exports.shuffle = exports.sortAlphaNumerically = exports.sortAlphabetically = exports.compare = exports.lastItem = void 0; | ||
/** | ||
@@ -9,6 +6,5 @@ * Returns the last item of an array | ||
*/ | ||
const lastItem = (array) => { | ||
export const lastItem = (array) => { | ||
return Array.isArray(array) ? array[array.length - 1] : undefined; | ||
}; | ||
exports.lastItem = lastItem; | ||
/** | ||
@@ -19,4 +15,3 @@ * Compares if two arrays contain same elements. | ||
*/ | ||
const compare = (arrayA, arrayB) => arrayA.length === arrayB.length && arrayA.every((a) => arrayB.includes(a)); | ||
exports.compare = compare; | ||
export const compare = (arrayA, arrayB) => arrayA.length === arrayB.length && arrayA.every((a) => arrayB.includes(a)); | ||
/** | ||
@@ -27,3 +22,3 @@ * Function for `array.sort()`. | ||
*/ | ||
const sortAlphabetically = (a, b) => { | ||
export const sortAlphabetically = (a, b) => { | ||
if (a < b) { | ||
@@ -38,3 +33,2 @@ return -1; | ||
}; | ||
exports.sortAlphabetically = sortAlphabetically; | ||
/** | ||
@@ -45,3 +39,3 @@ * Function for `array.sort()`. | ||
*/ | ||
const sortAlphaNumerically = (a, b) => { | ||
export const sortAlphaNumerically = (a, b) => { | ||
const numA = parseInt(a) || false; | ||
@@ -61,3 +55,2 @@ const numB = parseInt(b) || false; | ||
}; | ||
exports.sortAlphaNumerically = sortAlphaNumerically; | ||
/** | ||
@@ -68,3 +61,3 @@ * Returns new array with items shuffled around. | ||
*/ | ||
const shuffle = (array) => { | ||
export const shuffle = (array) => { | ||
const res = [...array]; | ||
@@ -79,3 +72,2 @@ for (let i = res.length - 1; i > 0; i--) { | ||
}; | ||
exports.shuffle = shuffle; | ||
/** | ||
@@ -88,4 +80,3 @@ * Returns an array which holds `count` items, each being the index | ||
*/ | ||
const arrayWith = (count) => [...Array(count).keys()]; | ||
exports.arrayWith = arrayWith; | ||
export const arrayWith = (count) => [...Array(count).keys()]; | ||
/** | ||
@@ -104,3 +95,3 @@ * Grabs you most common `propKey` in your `collection` of `T`, | ||
*/ | ||
function pickMostCommonProp(collection, propKey, condition) { | ||
export function pickMostCommonProp(collection, propKey, condition) { | ||
const map = new Map(); | ||
@@ -124,3 +115,2 @@ collection | ||
} | ||
exports.pickMostCommonProp = pickMostCommonProp; | ||
//# sourceMappingURL=arrays.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sortByIdx = exports.pickByIdx = void 0; | ||
/** | ||
@@ -9,4 +6,3 @@ * Finding function, for `find()` iteration | ||
*/ | ||
const pickByIdx = (idx) => (child) => child?.idx === idx; | ||
exports.pickByIdx = pickByIdx; | ||
export const pickByIdx = (idx) => (child) => child?.idx === idx; | ||
/** | ||
@@ -17,4 +13,3 @@ * Sorting function, for `sort()` | ||
*/ | ||
const sortByIdx = (a, b) => a?.idx - b?.idx; | ||
exports.sortByIdx = sortByIdx; | ||
export const sortByIdx = (a, b) => a?.idx - b?.idx; | ||
//# sourceMappingURL=entities.js.map |
@@ -1,11 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.runAll = exports.times = exports.noop = void 0; | ||
/** | ||
* @category Function | ||
*/ | ||
const noop = () => { | ||
export const noop = () => { | ||
// It's a noop, leave it be | ||
}; | ||
exports.noop = noop; | ||
/** | ||
@@ -17,6 +13,5 @@ * Executes function multiple times | ||
*/ | ||
const times = (length, func) => { | ||
export const times = (length, func) => { | ||
Array.from({ length }, func); | ||
}; | ||
exports.times = times; | ||
/** | ||
@@ -28,6 +23,5 @@ * @param functions Array of functions to call one by one | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
const runAll = (functions) => { | ||
export const runAll = (functions) => { | ||
functions.forEach((fn) => fn()); | ||
}; | ||
exports.runAll = runAll; | ||
//# sourceMappingURL=functions.js.map |
@@ -1,26 +0,10 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./arrays.js"), exports); | ||
__exportStar(require("./entities.js"), exports); | ||
__exportStar(require("./functions.js"), exports); | ||
__exportStar(require("./logs.js"), exports); | ||
__exportStar(require("./numbers.js"), exports); | ||
__exportStar(require("./objects.js"), exports); | ||
__exportStar(require("./random.js"), exports); | ||
__exportStar(require("./strings.js"), exports); | ||
__exportStar(require("./utils.js"), exports); | ||
export * from "./arrays.js"; | ||
export * from "./entities.js"; | ||
export * from "./functions.js"; | ||
export * from "./logs.js"; | ||
export * from "./numbers.js"; | ||
export * from "./objects.js"; | ||
export * from "./random.js"; | ||
export * from "./strings.js"; | ||
export * from "./utils.js"; | ||
//# sourceMappingURL=index.js.map |
@@ -1,7 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.minifyEntity = exports.isBrowser = void 0; | ||
exports.isBrowser = new Function("try {return this===window;}catch(e){ return false;}")(); | ||
const minifyEntity = ({ type, name, }) => `${type}:${name}`; | ||
exports.minifyEntity = minifyEntity; | ||
export const isBrowser = new Function("try {return this===window;}catch(e){ return false;}")(); | ||
export const minifyEntity = ({ type, name, }) => `${type}:${name}`; | ||
//# sourceMappingURL=utils.js.map |
@@ -1,10 +0,4 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Logs = exports.logs = exports.LogLevels = exports.chalk = void 0; | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const functions_js_1 = require("./functions.js"); | ||
const utils_js_1 = require("./logger/utils.js"); | ||
import Chalk from "chalk"; | ||
import { noop } from "./functions.js"; | ||
import { isBrowser, minifyEntity } from "./logger/utils.js"; | ||
/** | ||
@@ -15,4 +9,4 @@ * `Chalk` instance used internally by server-side lib. | ||
*/ | ||
exports.chalk = new chalk_1.default.Instance({ | ||
level: utils_js_1.isBrowser ? 0 : 1, | ||
export const chalk = new Chalk.Instance({ | ||
level: isBrowser ? 0 : 1, | ||
}); | ||
@@ -23,3 +17,3 @@ const BROWSER_DEBUG_STYLE = "margin-left:2em;"; | ||
*/ | ||
var LogLevels; | ||
export var LogLevels; | ||
(function (LogLevels) { | ||
@@ -32,3 +26,3 @@ LogLevels[LogLevels["silent"] = 0] = "silent"; | ||
LogLevels[LogLevels["verbose"] = 5] = "verbose"; | ||
})(LogLevels = exports.LogLevels || (exports.LogLevels = {})); | ||
})(LogLevels || (LogLevels = {})); | ||
let logLevel = LogLevels.silent; | ||
@@ -65,13 +59,13 @@ const setLogLevel = (val) => { | ||
if (typeof arg === "string") { | ||
return exports.chalk.gray(arg); | ||
return chalk.gray(arg); | ||
} | ||
if (typeof arg === "number") { | ||
return exports.chalk.red.bold(arg.toString()); | ||
return chalk.red.bold(arg.toString()); | ||
} | ||
if (typeof arg === "boolean") { | ||
return exports.chalk.green.bold(arg.toString()); | ||
return chalk.green.bold(arg.toString()); | ||
} | ||
// It must be some Entity | ||
if (arg && arg._state) { | ||
return exports.chalk.yellow((0, utils_js_1.minifyEntity)(arg)); | ||
return chalk.yellow(minifyEntity(arg)); | ||
} | ||
@@ -85,3 +79,3 @@ return arg; | ||
let logsPreExport; | ||
if (utils_js_1.isBrowser) { | ||
if (isBrowser) { | ||
logsPreExport = { | ||
@@ -106,3 +100,3 @@ verbose: console.debug.bind(window.console), | ||
`\t`, | ||
...args.map((arg) => exports.chalk.gray(arg)), | ||
...args.map((arg) => chalk.gray(arg)), | ||
]); | ||
@@ -114,3 +108,3 @@ }, | ||
`\t`, | ||
...args.map((arg) => exports.chalk.gray(arg)), | ||
...args.map((arg) => chalk.gray(arg)), | ||
]); | ||
@@ -127,3 +121,3 @@ }, | ||
else { | ||
console.log.call(console, exports.chalk.gray(_getIndent() + first)); | ||
console.log.call(console, chalk.gray(_getIndent() + first)); | ||
} | ||
@@ -140,3 +134,3 @@ }, | ||
else { | ||
console.log.call(console, exports.chalk.gray(_getIndent() + first)); | ||
console.log.call(console, chalk.gray(_getIndent() + first)); | ||
} | ||
@@ -146,3 +140,3 @@ }, | ||
console.info.apply(console, [ | ||
_getIndent() + exports.chalk.bgBlue.black(` ${first} `), | ||
_getIndent() + chalk.bgBlue.black(` ${first} `), | ||
...args.map(syntaxHighlight), | ||
@@ -153,3 +147,3 @@ ]); | ||
console.warn.apply(console, [ | ||
_getIndent() + exports.chalk.bgYellow.black(` ${first} `), | ||
_getIndent() + chalk.bgYellow.black(` ${first} `), | ||
...args.map(syntaxHighlight), | ||
@@ -160,3 +154,3 @@ ]); | ||
console.error.apply(console, [ | ||
_getIndent() + exports.chalk.bgRed.white(` ${first} `), | ||
_getIndent() + chalk.bgRed.white(` ${first} `), | ||
...args.map(syntaxHighlight), | ||
@@ -180,6 +174,6 @@ ]); | ||
try { | ||
if (utils_js_1.isBrowser && localStorage && localStorage.getItem("cardsDebug")) { | ||
if (isBrowser && localStorage && localStorage.getItem("cardsDebug")) { | ||
setLogLevel(localStorage.getItem("cardsDebug")); | ||
} | ||
else if (!utils_js_1.isBrowser) { | ||
else if (!isBrowser) { | ||
setLogLevel(process.env.LOGS); | ||
@@ -193,23 +187,23 @@ } | ||
if (logLevel < LogLevels.error) { | ||
logsPreExport.error = functions_js_1.noop; | ||
logsPreExport.error = noop; | ||
} | ||
if (logLevel < LogLevels.warn) { | ||
logsPreExport.warn = functions_js_1.noop; | ||
logsPreExport.warn = noop; | ||
} | ||
if (logLevel < LogLevels.info) { | ||
logsPreExport.info = functions_js_1.noop; | ||
logsPreExport.info = noop; | ||
} | ||
if (logLevel < LogLevels.notice) { | ||
logsPreExport.notice = functions_js_1.noop; | ||
logsPreExport.log = functions_js_1.noop; | ||
logsPreExport.notice = noop; | ||
logsPreExport.log = noop; | ||
} | ||
if (logLevel < LogLevels.verbose) { | ||
logsPreExport.verbose = functions_js_1.noop; | ||
logsPreExport.debug = functions_js_1.noop; | ||
logsPreExport.verbose = noop; | ||
logsPreExport.debug = noop; | ||
} | ||
exports.logs = logsPreExport; | ||
class Logs { | ||
export const logs = logsPreExport; | ||
export class Logs { | ||
constructor(name, enabled = false, options = {}) { | ||
this.enabled = enabled; | ||
if (utils_js_1.isBrowser) { | ||
if (isBrowser) { | ||
this.setupBrowserLogs(name, options.browserStyle); | ||
@@ -221,3 +215,3 @@ } | ||
} | ||
setupServerLogs(name, style = chalk_1.default.dim) { | ||
setupServerLogs(name, style = Chalk.dim) { | ||
let indentLevel = 0; | ||
@@ -233,7 +227,7 @@ const getIndent = () => { | ||
style(getIndent() + | ||
exports.chalk.bgRed.white(` ${name ? nameAndFirst(first) : first} `)), | ||
chalk.bgRed.white(` ${name ? nameAndFirst(first) : first} `)), | ||
...args.map(syntaxHighlight), | ||
]); | ||
} | ||
: functions_js_1.noop; | ||
: noop; | ||
this["warn"] = | ||
@@ -244,7 +238,7 @@ this.enabled && logLevel >= LogLevels.warn | ||
style(getIndent() + | ||
exports.chalk.bgYellow.black(` ${name ? nameAndFirst(first) : first} `)), | ||
chalk.bgYellow.black(` ${name ? nameAndFirst(first) : first} `)), | ||
...args.map(syntaxHighlight), | ||
]); | ||
} | ||
: functions_js_1.noop; | ||
: noop; | ||
this["info"] = | ||
@@ -255,7 +249,7 @@ this.enabled && logLevel >= LogLevels.info | ||
style(getIndent() + | ||
exports.chalk.bgBlue.black(` ${name ? nameAndFirst(first) : first} `)), | ||
chalk.bgBlue.black(` ${name ? nameAndFirst(first) : first} `)), | ||
...args.map(syntaxHighlight), | ||
]); | ||
} | ||
: functions_js_1.noop; | ||
: noop; | ||
this["log"] = this["notice"] = | ||
@@ -271,6 +265,6 @@ this.enabled && logLevel >= LogLevels.notice | ||
else { | ||
console.log.call(console, style(exports.chalk.gray(getIndent() + first))); | ||
console.log.call(console, style(chalk.gray(getIndent() + first))); | ||
} | ||
} | ||
: functions_js_1.noop; | ||
: noop; | ||
const _log = this["log"]; | ||
@@ -282,6 +276,6 @@ this["debug"] = this["verbose"] = | ||
style(`${getIndent()}\t`), | ||
...args.map((arg) => exports.chalk.gray(arg)), | ||
...args.map((arg) => chalk.gray(arg)), | ||
]); | ||
} | ||
: functions_js_1.noop; | ||
: noop; | ||
this["group"] = this.enabled | ||
@@ -292,3 +286,3 @@ ? function (first, ...args) { | ||
} | ||
: functions_js_1.noop; | ||
: noop; | ||
this["groupCollapsed"] = this.enabled | ||
@@ -299,3 +293,3 @@ ? function (first, ...args) { | ||
} | ||
: functions_js_1.noop; | ||
: noop; | ||
this["groupEnd"] = this.enabled | ||
@@ -306,3 +300,3 @@ ? function (first = "────────────", ...args) { | ||
} | ||
: functions_js_1.noop; | ||
: noop; | ||
} | ||
@@ -315,3 +309,3 @@ setupBrowserLogs(name, style) { | ||
})() | ||
: functions_js_1.noop; | ||
: noop; | ||
this["warn"] = | ||
@@ -322,3 +316,3 @@ this.enabled && logLevel >= LogLevels.warn | ||
})() | ||
: functions_js_1.noop; | ||
: noop; | ||
this["info"] = | ||
@@ -329,3 +323,3 @@ this.enabled && logLevel >= LogLevels.info | ||
})() | ||
: functions_js_1.noop; | ||
: noop; | ||
this["log"] = this["notice"] = | ||
@@ -336,3 +330,3 @@ this.enabled && logLevel >= LogLevels.notice | ||
})() | ||
: functions_js_1.noop; | ||
: noop; | ||
this["debug"] = this["verbose"] = | ||
@@ -343,9 +337,9 @@ this.enabled && logLevel >= LogLevels.verbose | ||
})() | ||
: functions_js_1.noop; | ||
: noop; | ||
this["group"] = this.enabled | ||
? console.group.bind(console, `%c ${name} `, style) | ||
: functions_js_1.noop; | ||
: noop; | ||
this["groupCollapsed"] = this.enabled | ||
? console.groupCollapsed.bind(console, `%c ${name} `, style) | ||
: functions_js_1.noop; | ||
: noop; | ||
this["groupEnd"] = this.enabled | ||
@@ -355,6 +349,5 @@ ? (function () { | ||
})() | ||
: functions_js_1.noop; | ||
: noop; | ||
} | ||
} | ||
exports.Logs = Logs; | ||
//# sourceMappingURL=logs.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.distance = exports.lerp = exports.decimal = exports.px2cm = exports.cm2px = exports.deg2rad = exports.rad2deg = exports.wrap = exports.limit = void 0; | ||
/** | ||
@@ -9,3 +6,3 @@ * Limits `val` to fin within range from `min` to `max` | ||
*/ | ||
const limit = (val, min = 0, max = 1) => { | ||
export const limit = (val, min = 0, max = 1) => { | ||
if (val < min) { | ||
@@ -21,3 +18,2 @@ return min; | ||
}; | ||
exports.limit = limit; | ||
/** | ||
@@ -29,3 +25,3 @@ * Wraps `val` around to fit within 0 and `max` | ||
// TODO: maybe allow negative values as min? | ||
const wrap = (val, max = 1) => { | ||
export const wrap = (val, max = 1) => { | ||
if (max === 0) { | ||
@@ -38,3 +34,2 @@ return val; | ||
}; | ||
exports.wrap = wrap; | ||
/** | ||
@@ -55,6 +50,5 @@ * Converts radians to degrees | ||
*/ | ||
const rad2deg = (angle) => { | ||
export const rad2deg = (angle) => { | ||
return angle * 57.29577951308232; // angle / Math.PI * 180 | ||
}; | ||
exports.rad2deg = rad2deg; | ||
/** | ||
@@ -75,6 +69,5 @@ * Converts degrees to radians | ||
*/ | ||
const deg2rad = (angle) => { | ||
export const deg2rad = (angle) => { | ||
return angle * 0.017453292519943295; // (angle / 180) * Math.PI | ||
}; | ||
exports.deg2rad = deg2rad; | ||
/** | ||
@@ -84,4 +77,3 @@ * | ||
*/ | ||
const cm2px = (value) => value * 11.5; | ||
exports.cm2px = cm2px; | ||
export const cm2px = (value) => value * 11.5; | ||
/** | ||
@@ -91,4 +83,3 @@ * | ||
*/ | ||
const px2cm = (value) => value / 11.5; | ||
exports.px2cm = px2cm; | ||
export const px2cm = (value) => value / 11.5; | ||
/** | ||
@@ -104,7 +95,6 @@ * Limits the number of digits "after comma" | ||
*/ | ||
const decimal = (value, maxZeroes = 2) => { | ||
export const decimal = (value, maxZeroes = 2) => { | ||
const pow = Math.pow(10, maxZeroes); | ||
return Math.round(value * pow) / pow; | ||
}; | ||
exports.decimal = decimal; | ||
/** | ||
@@ -114,6 +104,5 @@ * | ||
*/ | ||
const lerp = (a, b, t) => { | ||
export const lerp = (a, b, t) => { | ||
return a * (1 - t) + b * t; | ||
}; | ||
exports.lerp = lerp; | ||
/** | ||
@@ -123,3 +112,3 @@ * | ||
*/ | ||
const distance = (ax, ay, bx, by) => { | ||
export const distance = (ax, ay, bx, by) => { | ||
const dx = ax - bx; | ||
@@ -129,3 +118,2 @@ const dy = ay - by; | ||
}; | ||
exports.distance = distance; | ||
//# sourceMappingURL=numbers.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolve = exports.pick = exports.omit = exports.deepClone = void 0; | ||
/** | ||
@@ -8,3 +5,3 @@ * | ||
*/ | ||
const deepClone = (value) => { | ||
export const deepClone = (value) => { | ||
if (typeof value === "function") { | ||
@@ -15,3 +12,3 @@ return value; | ||
const arrResult = []; | ||
value.forEach((v) => arrResult.push((0, exports.deepClone)(v))); | ||
value.forEach((v) => arrResult.push(deepClone(v))); | ||
return arrResult; | ||
@@ -21,3 +18,3 @@ } | ||
const objResult = {}; | ||
Object.keys(value).forEach((key) => (objResult[key] = (0, exports.deepClone)(value[key]))); | ||
Object.keys(value).forEach((key) => (objResult[key] = deepClone(value[key]))); | ||
return objResult; | ||
@@ -27,3 +24,2 @@ } | ||
}; | ||
exports.deepClone = deepClone; | ||
/** | ||
@@ -33,3 +29,3 @@ * @returns new object without provided `keys` | ||
*/ | ||
const omit = (object, keys) => Object.keys(object) | ||
export const omit = (object, keys) => Object.keys(object) | ||
.filter((key) => !keys.includes(key)) | ||
@@ -40,3 +36,2 @@ .reduce((obj, key) => { | ||
}, {}); | ||
exports.omit = omit; | ||
/** | ||
@@ -46,3 +41,3 @@ * @returns new object only with provided `keys` | ||
*/ | ||
const pick = (object, keys) => Object.keys(object) | ||
export const pick = (object, keys) => Object.keys(object) | ||
.filter((key) => keys.includes(key)) | ||
@@ -53,3 +48,2 @@ .reduce((obj, key) => { | ||
}, {}); | ||
exports.pick = pick; | ||
/** | ||
@@ -59,7 +53,6 @@ * Resolves target object/property given source object and path. | ||
*/ | ||
const resolve = (sourceObject, path, separator = ".") => { | ||
export const resolve = (sourceObject, path, separator = ".") => { | ||
const properties = Array.isArray(path) ? path : path.split(separator); | ||
return properties.reduce((prev, curr) => prev && prev[curr], sourceObject); | ||
}; | ||
exports.resolve = resolve; | ||
//# sourceMappingURL=objects.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.randomInt = exports.randomFloat = void 0; | ||
/** | ||
@@ -8,4 +5,3 @@ * Random float number in range `min` to `max` | ||
*/ | ||
const randomFloat = (min = 0, max = 1) => Math.random() * (max - min) + min; | ||
exports.randomFloat = randomFloat; | ||
export const randomFloat = (min = 0, max = 1) => Math.random() * (max - min) + min; | ||
/** | ||
@@ -15,4 +11,3 @@ * Random number in range `min` to `max`, without the remainder | ||
*/ | ||
const randomInt = (min = 0, max = 1) => Math.floor(Math.random() * (max - min) + min); | ||
exports.randomInt = randomInt; | ||
export const randomInt = (min = 0, max = 1) => Math.floor(Math.random() * (max - min) + min); | ||
//# sourceMappingURL=random.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sentenceCase = exports.camelCase = exports.randomName = exports.trim = void 0; | ||
/** | ||
@@ -9,3 +6,3 @@ * Trim long string with nice ell… | ||
*/ | ||
const trim = (string = "", maxLength = 7) => { | ||
export const trim = (string = "", maxLength = 7) => { | ||
if (typeof string !== "string") { | ||
@@ -20,3 +17,2 @@ return ""; | ||
}; | ||
exports.trim = trim; | ||
/** | ||
@@ -26,7 +22,6 @@ * For now it's just 3 random letters | ||
*/ | ||
const randomName = () => { | ||
export const randomName = () => { | ||
const randomLetter = () => String.fromCharCode(Math.random() * (90 - 65) + 65); | ||
return randomLetter() + randomLetter() + randomLetter(); | ||
}; | ||
exports.randomName = randomName; | ||
/** | ||
@@ -36,7 +31,6 @@ * Convert string to "camelCase" | ||
*/ | ||
const camelCase = (str = "") => str | ||
export const camelCase = (str = "") => str | ||
.replace(/\s(.)/g, ($1) => $1.toUpperCase()) | ||
.replace(/\s/g, "") | ||
.replace(/^(.)/, ($1) => $1.toLowerCase()); | ||
exports.camelCase = camelCase; | ||
/** | ||
@@ -46,6 +40,5 @@ * Convert string to "SentenceCase" (first letter capital) | ||
*/ | ||
const sentenceCase = (str = "") => str | ||
export const sentenceCase = (str = "") => str | ||
.replace(/\s(.)/g, ($1) => $1.toUpperCase()) | ||
.replace(/^(.)/, ($1) => $1.toUpperCase()); | ||
exports.sentenceCase = sentenceCase; | ||
//# sourceMappingURL=strings.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.applyMixins = exports.isSet = exports.isMapLike = exports.isMap = exports.timeout = exports.compose = exports.def = void 0; | ||
/** | ||
@@ -15,4 +12,3 @@ * Returns first, *defined* value | ||
*/ | ||
const def = (...values) => values.find((value) => typeof value !== "undefined"); | ||
exports.def = def; | ||
export const def = (...values) => values.find((value) => typeof value !== "undefined"); | ||
/** | ||
@@ -24,3 +20,3 @@ * Calls each function with the current argument | ||
*/ | ||
const compose = (value, ...functions) => { | ||
export const compose = (value, ...functions) => { | ||
return functions.reduce((arg, fn) => { | ||
@@ -38,3 +34,2 @@ if (typeof fn === "function") { | ||
}; | ||
exports.compose = compose; | ||
/** | ||
@@ -45,8 +40,7 @@ * Simple delay of execution. Use like this: `await timeout(50)` | ||
*/ | ||
const timeout = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | ||
exports.timeout = timeout; | ||
export const timeout = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | ||
/** | ||
* @category Util | ||
*/ | ||
const isMap = (thing) => { | ||
export const isMap = (thing) => { | ||
try { | ||
@@ -61,3 +55,2 @@ // throws if o is not an object or has no [[MapData]] | ||
}; | ||
exports.isMap = isMap; | ||
/** | ||
@@ -67,4 +60,4 @@ * Has somewhat same interface to native Map | ||
*/ | ||
const isMapLike = (thing) => { | ||
if ((0, exports.isMap)(thing)) { | ||
export const isMapLike = (thing) => { | ||
if (isMap(thing)) { | ||
return true; | ||
@@ -82,7 +75,6 @@ } | ||
}; | ||
exports.isMapLike = isMapLike; | ||
/** | ||
* @category Util | ||
*/ | ||
const isSet = (thing) => { | ||
export const isSet = (thing) => { | ||
try { | ||
@@ -97,7 +89,6 @@ // throws if o is not an object or has no [[SetData]] | ||
}; | ||
exports.isSet = isSet; | ||
/** | ||
* @category Util | ||
*/ | ||
function applyMixins(derivedCtor, baseCtors) { | ||
export function applyMixins(derivedCtor, baseCtors) { | ||
baseCtors.forEach((baseCtor) => { | ||
@@ -109,3 +100,2 @@ Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => { | ||
} | ||
exports.applyMixins = applyMixins; | ||
//# sourceMappingURL=utils.js.map |
@@ -37,3 +37,3 @@ import Chalk from "chalk"; | ||
}; | ||
export interface Logs { | ||
export interface ILogs { | ||
error: (...any: any[]) => void; | ||
@@ -63,5 +63,15 @@ warn: (...any: any[]) => void; | ||
}; | ||
export declare class Logs { | ||
export declare class Logs implements ILogs { | ||
private readonly enabled; | ||
constructor(name: string, enabled?: boolean, options?: LogsOptions); | ||
error: (...any: any[]) => void; | ||
warn: (...any: any[]) => void; | ||
info: (...any: any[]) => void; | ||
notice: (...any: any[]) => void; | ||
log: (...any: any[]) => void; | ||
verbose: (...any: any[]) => void; | ||
debug: (...any: any[]) => void; | ||
group: (...any: any[]) => void; | ||
groupCollapsed: (...any: any[]) => void; | ||
groupEnd: (...any: any[]) => void; | ||
setupServerLogs(name: string, style?: Chalk.Chalk): void; | ||
@@ -68,0 +78,0 @@ setupBrowserLogs(name: string, style: string): void; |
{ | ||
"name": "@cardsgame/utils", | ||
"version": "1.7.2", | ||
"version": "1.7.4", | ||
"description": "", | ||
@@ -14,2 +14,3 @@ "author": "Darek Greenly (https://darekgreenly.com)", | ||
}, | ||
"type": "module", | ||
"main": "lib/cjs/index.cjs", | ||
@@ -23,3 +24,5 @@ "module": "lib/esm/index.js", | ||
"scripts": { | ||
"build": "tsc -p tsconfig.build.json & tsc -p tsconfig.build.cjs.json & wait && ../../scripts/mapToCjs.sh ./lib/cjs", | ||
"build": "concurrently npm:build:esm npm:build:cjs", | ||
"build:esm": "tsc -p tsconfig.build.json", | ||
"build:cjs": "tsc -p tsconfig.build.cjs.json && ../../scripts/mapToCjs.sh ./lib/cjs", | ||
"build:watch": "echo \"only for ESM!\" && tsc -p tsconfig.build.json --watch", | ||
@@ -30,8 +33,8 @@ "test": "jest", | ||
"dependencies": { | ||
"@cardsgame/types": "^1.7.1", | ||
"@cardsgame/types": "^1.7.4", | ||
"chalk": "^4.1.2" | ||
}, | ||
"devDependencies": { | ||
"@cardsgame/base-configs": "^1.7.2", | ||
"@types/node": "^18.11.0" | ||
"@cardsgame/base-configs": "^1.7.4", | ||
"@types/node": "^20.8.10" | ||
}, | ||
@@ -91,3 +94,3 @@ "exports": { | ||
}, | ||
"gitHead": "f78ad1db9213d6dd9038a976f789168e23af39c9" | ||
"gitHead": "ae8057a8f855f061ebfc1601503eed7970451172" | ||
} |
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
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
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
Yes
155253
1965
Updated@cardsgame/types@^1.7.4