UNPKG

@localazy/api-client

Version:

Official Node.js client for the Localazy API, providing a simple and type-safe way to integrate localization features into your JavaScript and TypeScript projects.

1,406 lines 129 kB
/* @localazy/api-client@2.2.0 * (c) 2026 Localazy <team@localazy.com> * @license MIT */ //#region src/api/methods/api-base.ts var ApiBase = class { api; constructor(api) { this.api = api; } static getId(val, prop) { const id = typeof val === "string" ? val : val.id || ""; if (!id) throw new Error(`Invalid ${prop} ID.`); return id; } }; //#endregion //#region src/api/methods/api-ai.ts var ApiAi = class extends ApiBase { /** * Translate provided items from the source language to the target language * using Localazy AI and considering the provided context, project-defined * style guide and glossary. * * @param request AI translate request config. * @param config Request config. * * @see {@link https://localazy.com/docs/api/ai-translation#translate Localazy API Docs} */ async translate(request, config) { const { project, ...data } = request; const projectId = ApiBase.getId(project, "project"); return await this.api.client.post(`/projects/${projectId}/ai`, data, config); } }; //#endregion //#region src/api/methods/api-export.ts var ApiExport = class ApiExport extends ApiBase { /** * Export translated keys as JSON object. * * @param request Export JSON request config. * @param config Request config. */ async json(request, config) { const { project, file, langs } = request; const result = await Promise.all(langs.map((lang) => this.api.files.listKeys({ project, file, lang }, config))); return Object.fromEntries(ApiExport.mapLanguages(langs, result)); } static mapLanguages(languages, result) { return languages.map((lang, index) => [lang, ApiExport.mapResult(result[index])]); } static mapResult(keysList) { return keysList.reduce((acc, cur) => { const parts = cur.key; if (parts.length <= 1) { const only = parts[0]; if (only !== void 0) acc[only] = cur.value; return acc; } let node = acc; for (let i = 0; i < parts.length; i++) { const seg = parts[i]; const isLast = i === parts.length - 1; if (seg !== void 0) if (isLast) node[seg] = cur.value; else { if (node[seg] === void 0) node[seg] = {}; node = node[seg]; } } return acc; }, {}); } }; //#endregion //#region src/api/methods/api-files.ts var ApiFiles = class extends ApiBase { /** * List all {@link File files} in the project. * * @param request Files list request config. * @param config Request config. * * @see {@link https://localazy.com/docs/api/files#list-files-in-project Localazy API Docs} */ async list(request, config) { const { project } = request; const projectId = ApiBase.getId(project, "project"); return await this.api.client.get(`/projects/${projectId}/files`, config); } /** * First {@link File file} in the project. * * @param request Files list request config. * @param config Request config. * @throws Error At least one file must exist, otherwise an error is thrown. * * @see {@link https://localazy.com/docs/api/files#list-files-in-project Localazy API Docs} */ async first(request, config) { const files = await this.list(request, config); if (typeof files[0] !== "undefined") return files[0]; throw new Error("File not found."); } /** * List all {@link Key keys} for the language in the {@link File file}. * * @param request File list keys request config. * @param config Request config. * * @see {@link https://localazy.com/docs/api/files#retrieve-a-list-of-keys-and-translations-from-file * | Localazy API Docs} */ async listKeys(request, config) { const keys = []; let pageResult = { keys: [], next: "" }; do { pageResult = await this.listKeysPage({ ...request, next: pageResult.next }, config); keys.push(...pageResult.keys); } while (pageResult.next); return keys; } /** * List all {@link Key keys} for the language in the {@link File file}. Result is paginated. * * @param request File list keys request config. * @param config Request config. * * @see {@link https://localazy.com/docs/api/files#retrieve-a-list-of-keys-and-translations-from-file * | Localazy API Docs} */ async listKeysPage(request, config) { const { project, file, lang, ...params } = request; const projectId = ApiBase.getId(project, "project"); const fileId = ApiBase.getId(file, "file"); return await this.api.client.get(`/projects/${projectId}/files/${fileId}/keys/${lang}`, { ...config, params }); } /** * List {@link Key keys} for the language in the {@link File file} with event-based filtering. * Fetches all keys with `event=true`, computes the maximum event number, and optionally * filters to only keys changed since a given event cursor. * * This method is designed for incremental sync: pass `sinceEvent` from a previous sync * to receive only keys that have changed since then. * * @param request File list keys since event request config. * @param config Request config. * @returns An object containing the filtered keys and the maximum event number. */ async listKeysSinceEvent(request, config) { const { sinceEvent, ...rest } = request; const allKeys = await this.listKeys({ ...rest, event: true }, config); const keysWithEvent = allKeys.filter((key) => key.event !== void 0 && key.event !== null); const maxEvent = keysWithEvent.length > 0 ? keysWithEvent.reduce((max, key) => Math.max(max, key.event ?? -Infinity), -Infinity) : null; return { keys: sinceEvent !== null && sinceEvent !== void 0 ? allKeys.filter((key) => key.event !== void 0 && key.event !== null && key.event > sinceEvent) : allKeys, maxEvent }; } /** * Get the contents of the {@link File file}. * * @param request File get contents request config. * @param config Request config. * * @see {@link https://localazy.com/docs/api/files#list-file-content Localazy API Docs} */ async getContents(request, config) { const { project, file, lang } = request; const projectId = ApiBase.getId(project, "project"); const fileId = ApiBase.getId(file, "file"); return await this.api.client.get(`/projects/${projectId}/files/${fileId}/download/${lang}`, { ...config, responseType: "blob" }); } }; //#endregion //#region src/api/methods/api-formats.ts var ApiFormats = class extends ApiBase { /** * List all {@link Format formats} and related options. * * @param config Request config. * * @see {@link https://localazy.com/docs/api/import#list-available-file-types Localazy API Docs} */ async list(config) { return await this.api.client.get("/import/formats", config); } }; //#endregion //#region src/api/methods/api-glossary.ts var ApiGlossary = class extends ApiBase { /** * List all {@link GlossaryRecord glossary records} in the project. * * @param request Glossary records list request config. * @param config Request config. * * @see {@link https://localazy.com/docs/api/glossary#list-all-glossary-terms Localazy API Docs} */ async list(request, config) { const { project } = request; const projectId = ApiBase.getId(project, "project"); return (await this.api.client.get(`/projects/${projectId}/glossary`, config)).glossaries; } /** * Find {@link GlossaryRecord glossary record} specified by `id`. * * @param request Glossary record find request config. * @param config Request config. * * @see {@link https://localazy.com/docs/api/glossary#get-glossary-term Localazy API Docs} */ async find(request, config) { const { project, glossaryRecord } = request; const projectId = ApiBase.getId(project, "project"); const id = typeof glossaryRecord === "string" ? glossaryRecord : glossaryRecord.id; return await this.api.client.get(`/projects/${projectId}/glossary/${id}`, config); } /** * Create {@link GlossaryRecord glossary record}. * There is a limit of 1000 glossary records per project. * * @param request Glossary record create request config. * @param config Request config. * * @see {@link https://localazy.com/docs/api/glossary#create-new-glossary-term Localazy API Docs} */ async create(request, config) { const { project, ...data } = request; const projectId = ApiBase.getId(project, "project"); return (await this.api.client.post(`/projects/${projectId}/glossary`, data, config)).result; } /** * Update {@link GlossaryRecord glossary record} specified by `id`. * * @param request Glossary record update request config. * @param config Request config. * * @see {@link https://localazy.com/docs/api/glossary#update-glossary-term Localazy API Docs} */ async update(request, config) { const { project, glossaryRecord, ...data } = request; const projectId = ApiBase.getId(project, "project"); const id = typeof glossaryRecord === "string" ? glossaryRecord : glossaryRecord.id; await this.api.client.put(`/projects/${projectId}/glossary/${id}`, data, config); } /** * Delete {@link GlossaryRecord glossary record} specified by `id`. * * @param request Glossary record delete request config. * @param config Request config. * * @see {@link https://localazy.com/docs/api/glossary#delete-glossary-term Localazy API Docs} */ async delete(request, config) { const { project, glossaryRecord } = request; const projectId = ApiBase.getId(project, "project"); const id = typeof glossaryRecord === "string" ? glossaryRecord : glossaryRecord.id; await this.api.client.delete(`/projects/${projectId}/glossary/${id}`, config); } }; //#endregion //#region src/types/import-data-factory.ts var importDataFactory = (request, chunks) => ({ ...request.i18nOptions, files: [...chunks.map((chunk) => ({ name: "content.json", ...request.fileOptions, content: { type: "json", ...request.contentOptions, ...chunk } }))] }); //#endregion //#region src/utils/delay.ts var delay = (ms = 150) => new Promise((resolve) => { setTimeout(resolve, ms); }); //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/predicate/isSymbol.mjs /** * Check whether a value is a symbol. * * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `symbol`. * * @param {unknown} value The value to check. * @returns {value is symbol} Returns `true` if `value` is a symbol, else `false`. * @example * isSymbol(Symbol.iterator); * // => true * * isSymbol('abc'); * // => false */ function isSymbol(value) { return typeof value === "symbol" || value instanceof Symbol; } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/predicate/isPlainObject.mjs /** * Checks if a given value is a plain object. * * A plain object is an object created by the `{}` literal, `new Object()`, or * `Object.create(null)`. * * This function also handles objects with custom * `Symbol.toStringTag` properties. * * `Symbol.toStringTag` is a built-in symbol that a constructor can use to customize the * default string description of objects. * * @param {any} [object] - The value to check. * @returns {boolean} - True if the value is a plain object, otherwise false. * * @example * console.log(isPlainObject({})); // true * console.log(isPlainObject([])); // false * console.log(isPlainObject(null)); // false * console.log(isPlainObject(Object.create(null))); // true * console.log(isPlainObject(new Map())); // false */ function isPlainObject(object) { if (typeof object !== "object") return false; if (object == null) return false; if (Object.getPrototypeOf(object) === null) return true; if (Object.prototype.toString.call(object) !== "[object Object]") { const tag = object[Symbol.toStringTag]; if (tag == null) return false; if (!Object.getOwnPropertyDescriptor(object, Symbol.toStringTag)?.writable) return false; return object.toString() === `[object ${tag}]`; } let proto = object; while (Object.getPrototypeOf(proto) !== null) proto = Object.getPrototypeOf(proto); return Object.getPrototypeOf(object) === proto; } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/_internal/isEqualsSameValueZero.mjs /** * Performs a `SameValueZero` comparison between two values to determine if they are equivalent. * * @param {any} value - The value to compare. * @param {any} other - The other value to compare. * @returns {boolean} Returns `true` if the values are equivalent, else `false`. * * @example * eq(1, 1); // true * eq(0, -0); // true * eq(NaN, NaN); // true * eq('a', Object('a')); // false */ function isEqualsSameValueZero(value, other) { return value === other || Number.isNaN(value) && Number.isNaN(other); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/function/noop.mjs /** * A no-operation function that does nothing. * This can be used as a placeholder or default function. * * @example * noop(); // Does nothing * * @returns {void} This function does not return anything. */ function noop() {} //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/_internal/getSymbols.mjs function getSymbols(object) { return Object.getOwnPropertySymbols(object).filter((symbol) => Object.prototype.propertyIsEnumerable.call(object, symbol)); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/_internal/getTag.mjs /** * Gets the `toStringTag` of `value`. * * @private * @param {T} value The value to query. * @returns {string} Returns the `Object.prototype.toString.call` result. */ function getTag(value) { if (value == null) return value === void 0 ? "[object Undefined]" : "[object Null]"; return Object.prototype.toString.call(value); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/_internal/tags.mjs var regexpTag = "[object RegExp]"; var stringTag = "[object String]"; var numberTag = "[object Number]"; var booleanTag = "[object Boolean]"; var argumentsTag = "[object Arguments]"; var symbolTag = "[object Symbol]"; var dateTag = "[object Date]"; var mapTag = "[object Map]"; var setTag = "[object Set]"; var arrayTag = "[object Array]"; var arrayBufferTag = "[object ArrayBuffer]"; var objectTag = "[object Object]"; var dataViewTag = "[object DataView]"; var uint8ArrayTag = "[object Uint8Array]"; var uint8ClampedArrayTag = "[object Uint8ClampedArray]"; var uint16ArrayTag = "[object Uint16Array]"; var uint32ArrayTag = "[object Uint32Array]"; var int8ArrayTag = "[object Int8Array]"; var int16ArrayTag = "[object Int16Array]"; var int32ArrayTag = "[object Int32Array]"; var float32ArrayTag = "[object Float32Array]"; var float64ArrayTag = "[object Float64Array]"; //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/_internal/globalThis.mjs var globalThis_ = typeof globalThis === "object" && globalThis || typeof window === "object" && window || typeof self === "object" && self || typeof global === "object" && global || (function() { return this; })() || Function("return this")(); //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/predicate/isBuffer.mjs /** * Checks if the given value is a Buffer instance. * * This function tests whether the provided value is an instance of Buffer. * It returns `true` if the value is a Buffer, and `false` otherwise. * * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Buffer`. * * @param {unknown} x - The value to check if it is a Buffer. * @returns {boolean} Returns `true` if `x` is a Buffer, else `false`. * * @example * const buffer = Buffer.from("test"); * console.log(isBuffer(buffer)); // true * * const notBuffer = "not a buffer"; * console.log(isBuffer(notBuffer)); // false */ function isBuffer(x) { return typeof globalThis_.Buffer !== "undefined" && globalThis_.Buffer.isBuffer(x); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/predicate/isLength.mjs /** * Checks if a given value is a valid length. * * A valid length is of type `number`, is a non-negative integer, and is less than or equal to * JavaScript's maximum safe integer (`Number.MAX_SAFE_INTEGER`). * It returns `true` if the value is a valid length, and `false` otherwise. * * This function can also serve as a type predicate in TypeScript, narrowing the type of the * argument to a valid length (`number`). * * @param {any} value The value to check. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. * * @example * isLength(0); // true * isLength(42); // true * isLength(-1); // false * isLength(1.5); // false * isLength(Number.MAX_SAFE_INTEGER); // true * isLength(Number.MAX_SAFE_INTEGER + 1); // false */ function isLength(value) { return Number.isSafeInteger(value) && value >= 0; } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/predicate/isArrayLike.mjs /** * Checks if `value` is array-like. * * @param {any} value The value to check. * @returns {boolean} Returns `true` if `value` is array-like, else `false`. * * @example * isArrayLike([1, 2, 3]); // true * isArrayLike('abc'); // true * isArrayLike({ 0: 'a', length: 1 }); // true * isArrayLike({}); // false * isArrayLike(null); // false * isArrayLike(undefined); // false */ function isArrayLike(value) { return value != null && typeof value !== "function" && isLength(value.length); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/array/chunk.mjs /** * Splits an array into smaller arrays of a specified length. * * This function takes an input array and divides it into multiple smaller arrays, * each of a specified length. If the input array cannot be evenly divided, * the final sub-array will contain the remaining elements. * * @template T The type of elements in the array. * @param {T[]} arr - The array to be chunked into smaller arrays. * @param {number} size - The size of each smaller array. Must be a positive integer. * @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`. * @throws {Error} Throws an error if `size` is not a positive integer. * * @example * // Splits an array of numbers into sub-arrays of length 2 * chunk([1, 2, 3, 4, 5], 2); * // Returns: [[1, 2], [3, 4], [5]] * * @example * // Splits an array of strings into sub-arrays of length 3 * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3); * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']] */ function chunk$1(arr, size) { if (!Number.isInteger(size) || size <= 0) throw new Error("Size must be an integer greater than zero."); const chunkLength = Math.ceil(arr.length / size); const result = Array(chunkLength); for (let index = 0; index < chunkLength; index++) { const start = index * size; const end = start + size; result[index] = arr.slice(start, end); } return result; } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/_internal/toArray.mjs function toArray(value) { return Array.isArray(value) ? value : Array.from(value); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/array/chunk.mjs /** * Splits an array into smaller arrays of a specified length. * * This function takes an input array and divides it into multiple smaller arrays, * each of a specified length. If the input array cannot be evenly divided, * the final sub-array will contain the remaining elements. * * @template T The type of elements in the array. * @param {ArrayLike<T> | null | undefined} arr - The array to be chunked into smaller arrays. * @param {number} size - The size of each smaller array. Must be a positive integer. * @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`. * * @example * // Splits an array of numbers into sub-arrays of length 2 * chunk([1, 2, 3, 4, 5], 2); * // Returns: [[1, 2], [3, 4], [5]] * * @example * // Splits an array of strings into sub-arrays of length 3 * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3); * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']] */ function chunk(arr, size = 1) { size = Math.max(Math.floor(size), 0); if (size === 0 || !isArrayLike(arr)) return []; return chunk$1(toArray(arr), size); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/util/toString.mjs /** * Converts `value` to a string. * * An empty string is returned for `null` and `undefined` values. * The sign of `-0` is preserved. * * @param {any} value - The value to convert. * @returns {string} Returns the converted string. * * @example * toString(null) // returns '' * toString(undefined) // returns '' * toString(-0) // returns '-0' * toString([1, 2, -0]) // returns '1,2,-0' * toString([Symbol('a'), Symbol('b')]) // returns 'Symbol(a),Symbol(b)' */ function toString(value) { if (value == null) return ""; if (typeof value === "string") return value; if (Array.isArray(value)) return value.map(toString).join(","); const result = String(value); if (result === "0" && Object.is(Number(value), -0)) return "-0"; return result; } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/_internal/toKey.mjs /** * Converts `value` to a string key if it's not a string or symbol. * * @private * @param {*} value The value to inspect. * @returns {string|symbol} Returns the key. */ function toKey(value) { if (typeof value === "string" || typeof value === "symbol") return value; if (Object.is(value?.valueOf?.(), -0)) return "-0"; return String(value); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/util/toPath.mjs /** * Converts a deep key string into an array of path segments. * * This function takes a string representing a deep key (e.g., 'a.b.c' or 'a[b][c]') and breaks it down into an array of strings, each representing a segment of the path. * * @param {any} deepKey - The deep key string to convert. * @returns {string[]} An array of strings, each representing a segment of the path. * * Examples: * * toPath('a.b.c') // Returns ['a', 'b', 'c'] * toPath('a[b][c]') // Returns ['a', 'b', 'c'] * toPath('.a.b.c') // Returns ['', 'a', 'b', 'c'] * toPath('a["b.c"].d') // Returns ['a', 'b.c', 'd'] * toPath('') // Returns [] * toPath('.a[b].c.d[e]["f.g"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h'] */ function toPath(deepKey) { if (Array.isArray(deepKey)) return deepKey.map(toKey); if (typeof deepKey === "symbol") return [deepKey]; deepKey = toString(deepKey); const result = []; const length = deepKey.length; if (length === 0) return result; let index = 0; let key = ""; let quoteChar = ""; let bracket = false; if (deepKey.charCodeAt(0) === 46) { result.push(""); index++; } while (index < length) { const char = deepKey[index]; if (quoteChar) if (char === "\\" && index + 1 < length) { index++; key += deepKey[index]; } else if (char === quoteChar) quoteChar = ""; else key += char; else if (bracket) if (char === "\"" || char === "'") quoteChar = char; else if (char === "]") { bracket = false; result.push(key); key = ""; } else key += char; else if (char === "[") { bracket = true; if (key) { result.push(key); key = ""; } } else if (char === ".") { if (key) { result.push(key); key = ""; } } else key += char; index++; } if (key) result.push(key); return result; } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs /** * Checks if a property key is unsafe to modify directly. * * This function is used in functions like `merge` to prevent prototype pollution attacks * by identifying property keys that could modify the object's prototype chain or constructor. * * @param key - The property key to check * @returns `true` if the property is unsafe to modify directly, `false` otherwise * @internal */ function isUnsafeProperty(key) { return key === "__proto__"; } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/_internal/isDeepKey.mjs /** * Checks if a given key is a deep key. * * A deep key is a string that contains a dot (.) or square brackets with a property accessor. * * @param {PropertyKey} key - The key to check. * @returns {boolean} - Returns true if the key is a deep key, otherwise false. * * Examples: * * isDeepKey('a.b') // true * isDeepKey('a[b]') // true * isDeepKey('a') // false * isDeepKey(123) // false * isDeepKey('a.b.c') // true * isDeepKey('a[b][c]') // true */ function isDeepKey(key) { switch (typeof key) { case "number": case "symbol": return false; case "string": return key.includes(".") || key.includes("[") || key.includes("]"); } } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/object/get.mjs /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. * * @param {any} object - The object to query. * @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to get. * @param {any} [defaultValue] - The value returned if the resolved value is undefined. * @returns {any} Returns the resolved value. * * @example * const object = { a: { b: { c: 1 } } }; * get(object, 'a.b.c'); * // => 1 * * get(object, ['a', 'b', 'c']); * // => 1 * * get(object, 'a.b.d', 'default'); * // => 'default' */ function get(object, path, defaultValue) { if (object == null) return defaultValue; switch (typeof path) { case "string": { if (isUnsafeProperty(path)) return defaultValue; const result = object[path]; if (result === void 0) if (isDeepKey(path)) return get(object, toPath(path), defaultValue); else return defaultValue; return result; } case "number": case "symbol": { if (typeof path === "number") path = toKey(path); const result = object[path]; if (result === void 0) return defaultValue; return result; } default: { if (Array.isArray(path)) return getWithPath(object, path, defaultValue); if (Object.is(path?.valueOf(), -0)) path = "-0"; else path = String(path); if (isUnsafeProperty(path)) return defaultValue; const result = object[path]; if (result === void 0) return defaultValue; return result; } } } function getWithPath(object, path, defaultValue) { if (path.length === 0) return defaultValue; let current = object; for (let index = 0; index < path.length; index++) { if (current == null) return defaultValue; if (isUnsafeProperty(path[index])) return defaultValue; current = current[path[index]]; } if (current === void 0) return defaultValue; return current; } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/predicate/isObject.mjs /** * Checks if the given value is an object. An object is a value that is * not a primitive type (string, number, boolean, symbol, null, or undefined). * * This function tests whether the provided value is an object or not. * It returns `true` if the value is an object, and `false` otherwise. * * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object value. * * @param {any} value - The value to check if it is an object. * @returns {value is object} `true` if the value is an object, `false` otherwise. * * @example * const value1 = {}; * const value2 = [1, 2, 3]; * const value3 = () => {}; * const value4 = null; * * console.log(isObject(value1)); // true * console.log(isObject(value2)); // true * console.log(isObject(value3)); // true * console.log(isObject(value4)); // false */ function isObject(value) { return value !== null && (typeof value === "object" || typeof value === "function"); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/predicate/isPrimitive.mjs /** * Checks whether a value is a JavaScript primitive. * JavaScript primitives include null, undefined, strings, numbers, booleans, symbols, and bigints. * * @param {unknown} value The value to check. * @returns {value is * null * | undefined * | string * | number * | boolean * | symbol * | bigint} Returns true if `value` is a primitive, false otherwise. * * @example * isPrimitive(null); // true * isPrimitive(undefined); // true * isPrimitive('123'); // true * isPrimitive(false); // true * isPrimitive(true); // true * isPrimitive(Symbol('a')); // true * isPrimitive(123n); // true * isPrimitive({}); // false * isPrimitive(new Date()); // false * isPrimitive(new Map()); // false * isPrimitive(new Set()); // false * isPrimitive([1, 2, 3]); // false */ function isPrimitive(value) { return value == null || typeof value !== "object" && typeof value !== "function"; } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/predicate/isTypedArray.mjs /** * Checks if a value is a TypedArray. * @param {unknown} x The value to check. * @returns {x is * Uint8Array * | Uint8ClampedArray * | Uint16Array * | Uint32Array * | BigUint64Array * | Int8Array * | Int16Array * | Int32Array * | BigInt64Array * | Float32Array * | Float64Array} Returns true if `x` is a TypedArray, false otherwise. * * @example * const arr = new Uint8Array([1, 2, 3]); * isTypedArray(arr); // true * * const regularArray = [1, 2, 3]; * isTypedArray(regularArray); // false * * const buffer = new ArrayBuffer(16); * isTypedArray(buffer); // false */ function isTypedArray$1(x) { return ArrayBuffer.isView(x) && !(x instanceof DataView); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/object/cloneDeepWith.mjs /** * Deeply clones the given object. * * You can customize the deep cloning process using the `cloneValue` function. * The function takes the current value `value`, the property name `key`, and the entire object `obj` as arguments. * If the function returns a value, that value is used; * if it returns `undefined`, the default cloning method is used. * * @template T - The type of the object. * @param {T} obj - The object to clone. * @param {Function} [cloneValue] - A function to customize the cloning process. * @returns {T} - A deep clone of the given object. * * @example * // Clone a primitive value * const num = 29; * const clonedNum = cloneDeepWith(num); * console.log(clonedNum); // 29 * console.log(clonedNum === num); // true * * @example * // Clone an object with a customizer * const obj = { a: 1, b: 2 }; * const clonedObj = cloneDeepWith(obj, (value) => { * if (typeof value === 'number') { * return value * 2; // Double the number * } * }); * console.log(clonedObj); // { a: 2, b: 4 } * console.log(clonedObj === obj); // false * * @example * // Clone an array with a customizer * const arr = [1, 2, 3]; * const clonedArr = cloneDeepWith(arr, (value) => { * return value + 1; // Increment each value * }); * console.log(clonedArr); // [2, 3, 4] * console.log(clonedArr === arr); // false */ function cloneDeepWith$1(obj, cloneValue) { return cloneDeepWithImpl(obj, void 0, obj, /* @__PURE__ */ new Map(), cloneValue); } function cloneDeepWithImpl(valueToClone, keyToClone, objectToClone, stack = /* @__PURE__ */ new Map(), cloneValue = void 0) { const cloned = cloneValue?.(valueToClone, keyToClone, objectToClone, stack); if (cloned !== void 0) return cloned; if (isPrimitive(valueToClone)) return valueToClone; if (stack.has(valueToClone)) return stack.get(valueToClone); if (Array.isArray(valueToClone)) { const result = new Array(valueToClone.length); stack.set(valueToClone, result); for (let i = 0; i < valueToClone.length; i++) result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue); if (Object.hasOwn(valueToClone, "index")) result.index = valueToClone.index; if (Object.hasOwn(valueToClone, "input")) result.input = valueToClone.input; return result; } if (valueToClone instanceof Date) return new Date(valueToClone.getTime()); if (valueToClone instanceof RegExp) { const result = new RegExp(valueToClone.source, valueToClone.flags); result.lastIndex = valueToClone.lastIndex; return result; } if (valueToClone instanceof Map) { const result = /* @__PURE__ */ new Map(); stack.set(valueToClone, result); for (const [key, value] of valueToClone) result.set(key, cloneDeepWithImpl(value, key, objectToClone, stack, cloneValue)); return result; } if (valueToClone instanceof Set) { const result = /* @__PURE__ */ new Set(); stack.set(valueToClone, result); for (const value of valueToClone) result.add(cloneDeepWithImpl(value, void 0, objectToClone, stack, cloneValue)); return result; } if (isBuffer(valueToClone)) return valueToClone.subarray(); if (isTypedArray$1(valueToClone)) { const result = new (Object.getPrototypeOf(valueToClone)).constructor(valueToClone.length); stack.set(valueToClone, result); for (let i = 0; i < valueToClone.length; i++) result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue); return result; } if (valueToClone instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && valueToClone instanceof SharedArrayBuffer) return valueToClone.slice(0); if (valueToClone instanceof DataView) { const result = new DataView(valueToClone.buffer.slice(0), valueToClone.byteOffset, valueToClone.byteLength); stack.set(valueToClone, result); copyProperties(result, valueToClone, objectToClone, stack, cloneValue); return result; } if (typeof File !== "undefined" && valueToClone instanceof File) { const result = new File([valueToClone], valueToClone.name, { type: valueToClone.type }); stack.set(valueToClone, result); copyProperties(result, valueToClone, objectToClone, stack, cloneValue); return result; } if (typeof Blob !== "undefined" && valueToClone instanceof Blob) { const result = new Blob([valueToClone], { type: valueToClone.type }); stack.set(valueToClone, result); copyProperties(result, valueToClone, objectToClone, stack, cloneValue); return result; } if (valueToClone instanceof Error) { const result = structuredClone(valueToClone); stack.set(valueToClone, result); result.message = valueToClone.message; result.name = valueToClone.name; result.stack = valueToClone.stack; result.cause = valueToClone.cause; result.constructor = valueToClone.constructor; copyProperties(result, valueToClone, objectToClone, stack, cloneValue); return result; } if (valueToClone instanceof Boolean) { const result = new Boolean(valueToClone.valueOf()); stack.set(valueToClone, result); copyProperties(result, valueToClone, objectToClone, stack, cloneValue); return result; } if (valueToClone instanceof Number) { const result = new Number(valueToClone.valueOf()); stack.set(valueToClone, result); copyProperties(result, valueToClone, objectToClone, stack, cloneValue); return result; } if (valueToClone instanceof String) { const result = new String(valueToClone.valueOf()); stack.set(valueToClone, result); copyProperties(result, valueToClone, objectToClone, stack, cloneValue); return result; } if (typeof valueToClone === "object" && isCloneableObject(valueToClone)) { const result = Object.create(Object.getPrototypeOf(valueToClone)); stack.set(valueToClone, result); copyProperties(result, valueToClone, objectToClone, stack, cloneValue); return result; } return valueToClone; } function copyProperties(target, source, objectToClone = target, stack, cloneValue) { const keys = [...Object.keys(source), ...getSymbols(source)]; for (let i = 0; i < keys.length; i++) { const key = keys[i]; const descriptor = Object.getOwnPropertyDescriptor(target, key); if (descriptor == null || descriptor.writable) target[key] = cloneDeepWithImpl(source[key], key, objectToClone, stack, cloneValue); } } function isCloneableObject(object) { switch (getTag(object)) { case argumentsTag: case arrayTag: case arrayBufferTag: case dataViewTag: case booleanTag: case dateTag: case float32ArrayTag: case float64ArrayTag: case int8ArrayTag: case int16ArrayTag: case int32ArrayTag: case mapTag: case numberTag: case objectTag: case regexpTag: case setTag: case stringTag: case symbolTag: case uint8ArrayTag: case uint8ClampedArrayTag: case uint16ArrayTag: case uint32ArrayTag: return true; default: return false; } } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/object/cloneDeepWith.mjs /** * Creates a deep clone of the given object using a customizer function. * * @template T - The type of the object. * @param {T} obj - The object to clone. * @param {Function} [cloneValue] - A function to customize the cloning process. * @returns {T} - A deep clone of the given object. * * @example * // Clone a primitive value * const num = 29; * const clonedNum = cloneDeepWith(num); * console.log(clonedNum); // 29 * console.log(clonedNum === num); // true * * @example * // Clone an object with a customizer * const obj = { a: 1, b: 2 }; * const clonedObj = cloneDeepWith(obj, (value) => { * if (typeof value === 'number') { * return value * 2; // Double the number * } * }); * console.log(clonedObj); // { a: 2, b: 4 } * console.log(clonedObj === obj); // false * * @example * // Clone an array with a customizer * const arr = [1, 2, 3]; * const clonedArr = cloneDeepWith(arr, (value) => { * return value + 1; // Increment each value * }); * console.log(clonedArr); // [2, 3, 4] * console.log(clonedArr === arr); // false */ function cloneDeepWith(obj, customizer) { return cloneDeepWith$1(obj, (value, key, object, stack) => { const cloned = customizer?.(value, key, object, stack); if (cloned !== void 0) return cloned; if (typeof obj !== "object") return; if (getTag(obj) === "[object Object]" && typeof obj.constructor !== "function") { const result = {}; stack.set(obj, result); copyProperties(result, obj, object, stack); return result; } switch (Object.prototype.toString.call(obj)) { case numberTag: case stringTag: case booleanTag: { const result = new obj.constructor(obj?.valueOf()); copyProperties(result, obj); return result; } case argumentsTag: { const result = {}; copyProperties(result, obj); result.length = obj.length; result[Symbol.iterator] = obj[Symbol.iterator]; return result; } default: return; } }); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/object/cloneDeep.mjs /** * Creates a deep clone of the given object. * * @template T - The type of the object. * @param {T} obj - The object to clone. * @returns {T} - A deep clone of the given object. * * @example * // Clone a primitive values * const num = 29; * const clonedNum = clone(num); * console.log(clonedNum); // 29 * console.log(clonedNum === num); // true * * @example * // Clone an array * const arr = [1, 2, 3]; * const clonedArr = clone(arr); * console.log(clonedArr); // [1, 2, 3] * console.log(clonedArr === arr); // false * * @example * // Clone an array with nested objects * const arr = [1, { a: 1 }, [1, 2, 3]]; * const clonedArr = clone(arr); * arr[1].a = 2; * console.log(arr); // [2, { a: 2 }, [1, 2, 3]] * console.log(clonedArr); // [1, { a: 1 }, [1, 2, 3]] * console.log(clonedArr === arr); // false * * @example * // Clone an object * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] }; * const clonedObj = clone(obj); * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] } * console.log(clonedObj === obj); // false * * @example * // Clone an object with nested objects * const obj = { a: 1, b: { c: 1 } }; * const clonedObj = clone(obj); * obj.b.c = 2; * console.log(obj); // { a: 1, b: { c: 2 } } * console.log(clonedObj); // { a: 1, b: { c: 1 } } * console.log(clonedObj === obj); // false */ function cloneDeep(obj) { return cloneDeepWith(obj); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/predicate/isArguments.mjs /** * Checks if the given value is an arguments object. * * This function tests whether the provided value is an arguments object or not. * It returns `true` if the value is an arguments object, and `false` otherwise. * * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an arguments object. * * @param {any} value - The value to test if it is an arguments object. * @returns {value is IArguments} `true` if the value is an arguments, `false` otherwise. * * @example * const args = (function() { return arguments; })(); * const strictArgs = (function() { 'use strict'; return arguments; })(); * const value = [1, 2, 3]; * * console.log(isArguments(args)); // true * console.log(isArguments(strictArgs)); // true * console.log(isArguments(value)); // false */ function isArguments(value) { return value !== null && typeof value === "object" && getTag(value) === "[object Arguments]"; } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/_internal/isIndex.mjs var IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/; function isIndex(value, length = Number.MAX_SAFE_INTEGER) { switch (typeof value) { case "number": return Number.isInteger(value) && value >= 0 && value < length; case "symbol": return false; case "string": return IS_UNSIGNED_INTEGER.test(value); } } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/predicate/isObjectLike.mjs /** * Checks if the given value is object-like. * * A value is object-like if its type is object and it is not null. * * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object-like value. * * @param {any} value - The value to test if it is an object-like. * @returns {boolean} `true` if the value is an object-like, `false` otherwise. * * @example * const value1 = { a: 1 }; * const value2 = [1, 2, 3]; * const value3 = 'abc'; * const value4 = () => {}; * const value5 = null; * * console.log(isObjectLike(value1)); // true * console.log(isObjectLike(value2)); // true * console.log(isObjectLike(value3)); // false * console.log(isObjectLike(value4)); // false * console.log(isObjectLike(value5)); // false */ function isObjectLike(value) { return typeof value === "object" && value !== null; } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/predicate/isArrayLikeObject.mjs /** * Checks if the given value is a non-primitive, array-like object. * * @param {any} value The value to check. * @returns {boolean} `true` if the value is a non-primitive, array-like object, `false` otherwise. * * @example * isArrayLikeObject([1, 2, 3]); // true * isArrayLikeObject({ 0: 'a', length: 1 }); // true * isArrayLikeObject('abc'); // false * isArrayLikeObject(()=>{}); // false */ function isArrayLikeObject(value) { return isObjectLike(value) && isArrayLike(value); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/_internal/isKey.mjs /** Matches any deep property path. (e.g. `a.b[0].c`)*/ var regexIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/; /** Matches any word character (alphanumeric & underscore).*/ var regexIsPlainProp = /^\w*$/; /** * Checks if `value` is a property name and not a property path. (It's ok that the `value` is not in the keys of the `object`) * @param {unknown} value The value to check. * @param {unknown} object The object to query. * @returns {boolean} Returns `true` if `value` is a property name, else `false`. * * @example * isKey('a', { a: 1 }); * // => true * * isKey('a.b', { a: { b: 2 } }); * // => false */ function isKey(value, object) { if (Array.isArray(value)) return false; if (typeof value === "number" || typeof value === "boolean" || value == null || isSymbol(value)) return true; return typeof value === "string" && (regexIsPlainProp.test(value) || !regexIsDeepProp.test(value)) || object != null && Object.hasOwn(object, value); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/_internal/assignValue.mjs var assignValue = (object, key, value) => { const objValue = object[key]; if (!(Object.hasOwn(object, key) && isEqualsSameValueZero(objValue, value)) || value === void 0 && !(key in object)) object[key] = value; }; //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/object/updateWith.mjs /** * Updates the value at the specified path of the given object using an updater function and a customizer. * If any part of the path does not exist, it will be created. * * @template T - The type of the object. * @template R - The type of the return value. * @param {T} obj - The object to modify. * @param {PropertyPath} path - The path of the property to update. * @param {(value: any) => any} updater - The function to produce the updated value. * @param {(value: any, key: string, object: T) => any} customizer - The function to customize the update process. * @returns {T | R} - The modified object. * * @example * const object = { 'a': [{ 'b': { 'c': 3 } }] }; * updateWith(object, 'a[0].b.c', (n) => n * n); * // => { 'a': [{ 'b': { 'c': 9 } }] } */ function updateWith(obj, path, updater, customizer) { if (obj == null && !isObject(obj)) return obj; let resolvedPath; if (isKey(path, obj)) resolvedPath = [path]; else if (Array.isArray(path)) resolvedPath = path; else resolvedPath = toPath(path); const updateValue = updater(get(obj, resolvedPath)); let current = obj; for (let i = 0; i < resolvedPath.length && current != null; i++) { const key = toKey(resolvedPath[i]); if (isUnsafeProperty(key)) continue; let newValue; if (i === resolvedPath.length - 1) newValue = updateValue; else { const objValue = current[key]; const customizerResult = customizer?.(objValue, key, obj); newValue = customizerResult !== void 0 ? customizerResult : isObject(objValue) ? objValue : isIndex(resolvedPath[i + 1]) ? [] : {}; } assignValue(current, key, newValue); current = current[key]; } return obj; } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/predicate/isTypedArray.mjs /** * Checks if a value is a TypedArray. * @param {any} x The value to check. * @returns {boolean} Returns true if `x` is a TypedArray, false otherwise. * * @example * const arr = new Uint8Array([1, 2, 3]); * isTypedArray(arr); // true * * const regularArray = [1, 2, 3]; * isTypedArray(regularArray); // false * * const buffer = new ArrayBuffer(16); * isTypedArray(buffer); // false */ function isTypedArray(x) { return isTypedArray$1(x); } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/object/clone.mjs /** * Creates a shallow clone of the given object. * * @template T - The type of the object. * @param {T} obj - The object to clone. * @returns {T} - A shallow clone of the given object. * * @example * // Clone a primitive values * const num = 29; * const clonedNum = clone(num); * console.log(clonedNum); // 29 * console.log(clonedNum === num); // true * * @example * // Clone an array * const arr = [1, 2, 3]; * const clonedArr = clone(arr); * console.log(clonedArr); // [1, 2, 3] * console.log(clonedArr === arr); // false * * @example * // Clone an object * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] }; * const clonedObj = clone(obj); * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] } * console.log(clonedObj === obj); // false */ function clone(obj) { if (isPrimitive(obj)) return obj; if (Array.isArray(obj) || isTypedArray$1(obj) || obj instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && obj instanceof SharedArrayBuffer) return obj.slice(0); const prototype = Object.getPrototypeOf(obj); if (prototype == null) return Object.assign(Object.create(prototype), obj); const Constructor = prototype.constructor; if (obj instanceof Date || obj instanceof Map || obj instanceof Set) return new Constructor(obj); if (obj instanceof RegExp) { const newRegExp = new Constructor(obj); newRegExp.lastIndex = obj.lastIndex; return newRegExp; } if (obj instanceof DataView) return new Constructor(obj.buffer.slice(0)); if (obj instanceof Error) { let newError; if (obj instanceof AggregateError) newError = new Constructor(obj.errors, obj.message, { cause: obj.cause }); else newError = new Constructor(obj.message, { cause: obj.cause }); newError.stack = obj.stack; Object.assign(newError, obj); return newError; } if (typeof File !== "undefined" && obj instanceof File) return new Constructor([obj], obj.name, { type: obj.type, lastModified: obj.lastModified }); if (typeof obj === "object") return Object.assign(Object.create(prototype), obj); return obj; } //#endregion //#region node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/object/mergeWith.mjs /** * Merges the properties of one or more source objects into the target object using a customizer function. * * This function performs a deep merge, recursively merging nested objects and arrays. * If a property in the source object is an array or object and the corresponding property in the target object is also an array or object, they will be merged. * If a property in the source object is `undefined`, it will not overwrite a defined property in the target object. * * You can provide a custom `merge` function to control how properties are merged. The `merge` function is called for each property that is being merged and receives the following arguments: * * - `targetValue`: The current value of the property in the target object. * - `sourceValue`: The value of the property in the source object. * - `key`: The key of the property being merged. * - `target`: The target object. * - `source`: The source object. * - `stack`: A `Ma