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