UNPKG

@mathrunet/masamune

Version:

Manages packages for the server portion (NodeJS) of the Masamune framework.

106 lines 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isDynamicMap = isDynamicMap; exports.parse = parse; exports.uuid = uuid; exports.splitArray = splitArray; const crypto_1 = require("crypto"); /** * Checks if [value] is {[key: string]: any}. * * [value]が{[key: string]: any}であるかどうかをチェックします。 * * @param value * Value to be checked. * * チェックしたい値。 * * @returns * If [value] is {[key: string]: any}, returns true; otherwise, returns false. * * [value]が{[key: string]: any}ならtrue、そうでなければfalseを返します。 */ function isDynamicMap(value) { return value !== null && typeof value === 'object' && !(value instanceof Array); } /** * Converts strings, numbers, etc. to the appropriate type. * * 文字列や数値などを適切な型に変換します。 * * @param {string | number} value * Strings and numbers. * 文字列か数値。 * * @return {bool | number | string} * If it is a string, a numeric value is returned; * otherwise, the input value is returned. * 文字列なら数値、そうでなければ入力値が返却されます。 */ function parse(value) { if (typeof value === "string") { if (value === "false") { return false; } else if (value === "true") { return true; } else if (value.match(new RegExp("^[0-9]+$"))) { const i = parseInt(value); if (isNaN(i)) { return value; } else { return i; } } else { return value; } } else { return value; } } /** * Generates a UUIDv4. * * UUIDv4を生成します。 * * @return {string} * UUIDv4. */ function uuid() { return (0, crypto_1.randomUUID)().replace(/-/g, ""); } /** * Divides an array into pieces of the specified size. * * 配列を指定したサイズで分割します。 * * @param array * Array to be divided. * * 分割したい配列。 * * @param chunkSize * Size of each piece. * * 1つのピースのサイズ。 * * @returns {T[][]} * Array divided into pieces. * * 分割された配列。 */ function splitArray(array, chunkSize) { let index = 0; let arrayLength = array.length; let tempArray = []; for (index = 0; index < arrayLength; index += chunkSize) { let chunk = array.slice(index, index + chunkSize); tempArray.push(chunk); } return tempArray; } //# sourceMappingURL=utils.js.map