Add settings page for managing forecasting API key and URL via UI

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-20 14:37:36 +00:00
parent cae411eae7
commit 1c411e402e
19809 changed files with 1962608 additions and 97 deletions

View file

@ -0,0 +1,111 @@
//#region src/compat/object/assign.d.ts
/**
* Assigns properties from one source object to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the source object.
* @param object - The target object to which properties will be assigned.
* @param source - The source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source object assigned.
*
* @example
* const target = { a: 1, b: 2 };
* const source = { b: 3, c: 4 };
* const result = assign(target, source);
* // => { a: 1, b: 3, c: 4 }
*/
declare function assign<T, U>(object: T, source: U): T & U;
/**
* Assigns properties from two source objects to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const result = assign(target, source1, source2);
* // => { a: 1, b: 2, c: 3 }
*/
declare function assign<T, U, V>(object: T, source1: U, source2: V): T & U & V;
/**
* Assigns properties from three source objects to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const result = assign(target, source1, source2, source3);
* // => { a: 1, b: 2, c: 3, d: 4 }
*/
declare function assign<T, U, V, W>(object: T, source1: U, source2: V, source3: W): T & U & V & W;
/**
* Assigns properties from four source objects to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @template X - The type of the fourth source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @param source4 - The fourth source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const source4 = { e: 5 };
* const result = assign(target, source1, source2, source3, source4);
* // => { a: 1, b: 2, c: 3, d: 4, e: 5 }
*/
declare function assign<T, U, V, W, X>(object: T, source1: U, source2: V, source3: W, source4: X): T & U & V & W & X;
/**
* Assigns properties from a target object to itself.
*
* @template T - The type of the target object.
* @param object - The target object.
* @returns The target object.
*
* @example
* const target = { a: 1, b: 2 };
* const result = assign(target);
* // => { a: 1, b: 2 }
*/
declare function assign<T>(object: T): T;
/**
* Assigns properties from multiple source objects to a target object.
*
* @param object - The target object to which properties will be assigned.
* @param otherArgs - The source objects whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assign(target, { b: 2 }, { c: 3 }, { d: 4 });
* // => { a: 1, b: 2, c: 3, d: 4 }
*/
declare function assign(object: any, ...otherArgs: any[]): any;
//#endregion
export { assign };

View file

@ -0,0 +1,111 @@
//#region src/compat/object/assign.d.ts
/**
* Assigns properties from one source object to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the source object.
* @param object - The target object to which properties will be assigned.
* @param source - The source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source object assigned.
*
* @example
* const target = { a: 1, b: 2 };
* const source = { b: 3, c: 4 };
* const result = assign(target, source);
* // => { a: 1, b: 3, c: 4 }
*/
declare function assign<T, U>(object: T, source: U): T & U;
/**
* Assigns properties from two source objects to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const result = assign(target, source1, source2);
* // => { a: 1, b: 2, c: 3 }
*/
declare function assign<T, U, V>(object: T, source1: U, source2: V): T & U & V;
/**
* Assigns properties from three source objects to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const result = assign(target, source1, source2, source3);
* // => { a: 1, b: 2, c: 3, d: 4 }
*/
declare function assign<T, U, V, W>(object: T, source1: U, source2: V, source3: W): T & U & V & W;
/**
* Assigns properties from four source objects to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @template X - The type of the fourth source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @param source4 - The fourth source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const source4 = { e: 5 };
* const result = assign(target, source1, source2, source3, source4);
* // => { a: 1, b: 2, c: 3, d: 4, e: 5 }
*/
declare function assign<T, U, V, W, X>(object: T, source1: U, source2: V, source3: W, source4: X): T & U & V & W & X;
/**
* Assigns properties from a target object to itself.
*
* @template T - The type of the target object.
* @param object - The target object.
* @returns The target object.
*
* @example
* const target = { a: 1, b: 2 };
* const result = assign(target);
* // => { a: 1, b: 2 }
*/
declare function assign<T>(object: T): T;
/**
* Assigns properties from multiple source objects to a target object.
*
* @param object - The target object to which properties will be assigned.
* @param otherArgs - The source objects whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assign(target, { b: 2 }, { c: 3 }, { d: 4 });
* // => { a: 1, b: 2, c: 3, d: 4 }
*/
declare function assign(object: any, ...otherArgs: any[]): any;
//#endregion
export { assign };

View file

@ -0,0 +1,33 @@
const require_isEqualsSameValueZero = require("../../_internal/isEqualsSameValueZero.js");
require("../util/eq.js");
const require_keys = require("./keys.js");
//#region src/compat/object/assign.ts
/**
* Assigns properties from multiple source objects to a target object.
*
* This function merges the properties of the source objects into the target object.
* If a property in the source objects is equal to the corresponding property in the target object,
* it will not be overwritten.
*
* @param object - The target object to which properties will be assigned.
* @param sources - The source objects whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assign(target, { b: 2 }, { c: 3 });
* console.log(result); // Output: { a: 1, b: 2, c: 3 }
*/
function assign(object, ...sources) {
for (let i = 0; i < sources.length; i++) assignImpl(object, sources[i]);
return object;
}
function assignImpl(object, source) {
const keys$1 = require_keys.keys(source);
for (let i = 0; i < keys$1.length; i++) {
const key = keys$1[i];
if (!(key in object) || !require_isEqualsSameValueZero.isEqualsSameValueZero(object[key], source[key])) object[key] = source[key];
}
}
//#endregion
exports.assign = assign;

View file

@ -0,0 +1,33 @@
import { isEqualsSameValueZero } from "../../_internal/isEqualsSameValueZero.mjs";
import "../util/eq.mjs";
import { keys } from "./keys.mjs";
//#region src/compat/object/assign.ts
/**
* Assigns properties from multiple source objects to a target object.
*
* This function merges the properties of the source objects into the target object.
* If a property in the source objects is equal to the corresponding property in the target object,
* it will not be overwritten.
*
* @param object - The target object to which properties will be assigned.
* @param sources - The source objects whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assign(target, { b: 2 }, { c: 3 });
* console.log(result); // Output: { a: 1, b: 2, c: 3 }
*/
function assign(object, ...sources) {
for (let i = 0; i < sources.length; i++) assignImpl(object, sources[i]);
return object;
}
function assignImpl(object, source) {
const keys$1 = keys(source);
for (let i = 0; i < keys$1.length; i++) {
const key = keys$1[i];
if (!(key in object) || !isEqualsSameValueZero(object[key], source[key])) object[key] = source[key];
}
}
//#endregion
export { assign };

View file

@ -0,0 +1,112 @@
//#region src/compat/object/assignIn.d.ts
/**
* Assigns own and inherited properties from one source object to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the source object.
* @param object - The target object to which properties will be assigned.
* @param source - The source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source object assigned.
*
* @example
* const target = { a: 1, b: 2 };
* const source = { b: 3, c: 4 };
* const result = assignIn(target, source);
* // => { a: 1, b: 3, c: 4 }
*/
declare function assignIn<T, U>(object: T, source: U): T & U;
/**
* Assigns own and inherited properties from two source objects to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const result = assignIn(target, source1, source2);
* // => { a: 1, b: 2, c: 3 }
*/
declare function assignIn<T, U, V>(object: T, source1: U, source2: V): T & U & V;
/**
* Assigns own and inherited properties from three source objects to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const result = assignIn(target, source1, source2, source3);
* // => { a: 1, b: 2, c: 3, d: 4 }
*/
declare function assignIn<T, U, V, W>(object: T, source1: U, source2: V, source3: W): T & U & V & W;
/**
* Assigns own and inherited properties from four source objects to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @template X - The type of the fourth source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @param source4 - The fourth source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const source4 = { e: 5 };
* const result = assignIn(target, source1, source2, source3, source4);
* // => { a: 1, b: 2, c: 3, d: 4, e: 5 }
*/
declare function assignIn<T, U, V, W, X>(object: T, source1: U, source2: V, source3: W, source4: X): T & U & V & W & X;
/**
* Returns the target object as-is.
*
* @template T - The type of the target object.
* @param object - The target object.
* @returns The target object.
*
* @example
* const target = { a: 1, b: 2 };
* const result = assignIn(target);
* // => { a: 1, b: 2 }
*/
declare function assignIn<T>(object: T): T;
/**
* Assigns own and inherited properties from multiple source objects to a target object.
*
* @template R - The type of the result.
* @param object - The target object to which properties will be assigned.
* @param otherArgs - The source objects whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assignIn(target, { b: 2 }, { c: 3 }, { d: 4 });
* // => { a: 1, b: 2, c: 3, d: 4 }
*/
declare function assignIn<R>(object: any, ...otherArgs: any[]): R;
//#endregion
export { assignIn };

View file

@ -0,0 +1,112 @@
//#region src/compat/object/assignIn.d.ts
/**
* Assigns own and inherited properties from one source object to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the source object.
* @param object - The target object to which properties will be assigned.
* @param source - The source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source object assigned.
*
* @example
* const target = { a: 1, b: 2 };
* const source = { b: 3, c: 4 };
* const result = assignIn(target, source);
* // => { a: 1, b: 3, c: 4 }
*/
declare function assignIn<T, U>(object: T, source: U): T & U;
/**
* Assigns own and inherited properties from two source objects to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const result = assignIn(target, source1, source2);
* // => { a: 1, b: 2, c: 3 }
*/
declare function assignIn<T, U, V>(object: T, source1: U, source2: V): T & U & V;
/**
* Assigns own and inherited properties from three source objects to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const result = assignIn(target, source1, source2, source3);
* // => { a: 1, b: 2, c: 3, d: 4 }
*/
declare function assignIn<T, U, V, W>(object: T, source1: U, source2: V, source3: W): T & U & V & W;
/**
* Assigns own and inherited properties from four source objects to a target object.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @template X - The type of the fourth source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @param source4 - The fourth source object whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const source4 = { e: 5 };
* const result = assignIn(target, source1, source2, source3, source4);
* // => { a: 1, b: 2, c: 3, d: 4, e: 5 }
*/
declare function assignIn<T, U, V, W, X>(object: T, source1: U, source2: V, source3: W, source4: X): T & U & V & W & X;
/**
* Returns the target object as-is.
*
* @template T - The type of the target object.
* @param object - The target object.
* @returns The target object.
*
* @example
* const target = { a: 1, b: 2 };
* const result = assignIn(target);
* // => { a: 1, b: 2 }
*/
declare function assignIn<T>(object: T): T;
/**
* Assigns own and inherited properties from multiple source objects to a target object.
*
* @template R - The type of the result.
* @param object - The target object to which properties will be assigned.
* @param otherArgs - The source objects whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assignIn(target, { b: 2 }, { c: 3 }, { d: 4 });
* // => { a: 1, b: 2, c: 3, d: 4 }
*/
declare function assignIn<R>(object: any, ...otherArgs: any[]): R;
//#endregion
export { assignIn };

View file

@ -0,0 +1,33 @@
const require_isEqualsSameValueZero = require("../../_internal/isEqualsSameValueZero.js");
require("../util/eq.js");
const require_keysIn = require("./keysIn.js");
//#region src/compat/object/assignIn.ts
/**
* Assigns properties from multiple source objects to a target object.
*
* This function merges the properties of the source objects into the target object,
* including properties from the prototype chain. If a property in the source objects
* is equal to the corresponding property in the target object, it will not be overwritten.
*
* @param object - The target object to which properties will be assigned.
* @param sources - The source objects whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assignIn(target, { b: 2 }, { c: 3 });
* console.log(result); // Output: { a: 1, b: 2, c: 3 }
*/
function assignIn(object, ...sources) {
for (let i = 0; i < sources.length; i++) assignInImpl(object, sources[i]);
return object;
}
function assignInImpl(object, source) {
const keys = require_keysIn.keysIn(source);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (!(key in object) || !require_isEqualsSameValueZero.isEqualsSameValueZero(object[key], source[key])) object[key] = source[key];
}
}
//#endregion
exports.assignIn = assignIn;

View file

@ -0,0 +1,33 @@
import { isEqualsSameValueZero } from "../../_internal/isEqualsSameValueZero.mjs";
import "../util/eq.mjs";
import { keysIn } from "./keysIn.mjs";
//#region src/compat/object/assignIn.ts
/**
* Assigns properties from multiple source objects to a target object.
*
* This function merges the properties of the source objects into the target object,
* including properties from the prototype chain. If a property in the source objects
* is equal to the corresponding property in the target object, it will not be overwritten.
*
* @param object - The target object to which properties will be assigned.
* @param sources - The source objects whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assignIn(target, { b: 2 }, { c: 3 });
* console.log(result); // Output: { a: 1, b: 2, c: 3 }
*/
function assignIn(object, ...sources) {
for (let i = 0; i < sources.length; i++) assignInImpl(object, sources[i]);
return object;
}
function assignInImpl(object, source) {
const keys = keysIn(source);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (!(key in object) || !isEqualsSameValueZero(object[key], source[key])) object[key] = source[key];
}
}
//#endregion
export { assignIn };

View file

@ -0,0 +1,127 @@
//#region src/compat/object/assignInWith.d.ts
type AssignCustomizer = (objectValue: any, sourceValue: any, key?: string, object?: {}, source?: {}) => any;
/**
* Assigns own and inherited properties from one source object to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the source object.
* @param object - The target object to which properties will be assigned.
* @param source - The source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source object assigned.
*
* @example
* const target = { a: 1, b: 2 };
* const source = { b: 3, c: 4 };
* const result = assignInWith(target, source, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 4 }
*/
declare function assignInWith<T, U>(object: T, source: U, customizer: AssignCustomizer): T & U;
/**
* Assigns own and inherited properties from two source objects to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const result = assignInWith(target, source1, source2, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3 }
*/
declare function assignInWith<T, U, V>(object: T, source1: U, source2: V, customizer: AssignCustomizer): T & U & V;
/**
* Assigns own and inherited properties from three source objects to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const result = assignInWith(target, source1, source2, source3, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3, d: 4 }
*/
declare function assignInWith<T, U, V, W>(object: T, source1: U, source2: V, source3: W, customizer: AssignCustomizer): T & U & V & W;
/**
* Assigns own and inherited properties from four source objects to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @template X - The type of the fourth source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @param source4 - The fourth source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const source4 = { e: 5 };
* const result = assignInWith(target, source1, source2, source3, source4, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3, d: 4, e: 5 }
*/
declare function assignInWith<T, U, V, W, X>(object: T, source1: U, source2: V, source3: W, source4: X, customizer: AssignCustomizer): T & U & V & W & X;
/**
* Returns the target object as-is.
*
* @template T - The type of the target object.
* @param object - The target object.
* @returns The target object.
*
* @example
* const target = { a: 1, b: 2 };
* const result = assignInWith(target);
* // => { a: 1, b: 2 }
*/
declare function assignInWith<T>(object: T): T;
/**
* Assigns own and inherited properties from multiple source objects to a target object using a customizer function.
*
* @template R - The type of the result.
* @param object - The target object to which properties will be assigned.
* @param otherArgs - The source objects and customizer function.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assignInWith(target, { b: 2 }, { c: 3 }, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3 }
*/
declare function assignInWith<R>(object: any, ...otherArgs: any[]): R;
//#endregion
export { assignInWith };

View file

@ -0,0 +1,127 @@
//#region src/compat/object/assignInWith.d.ts
type AssignCustomizer = (objectValue: any, sourceValue: any, key?: string, object?: {}, source?: {}) => any;
/**
* Assigns own and inherited properties from one source object to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the source object.
* @param object - The target object to which properties will be assigned.
* @param source - The source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source object assigned.
*
* @example
* const target = { a: 1, b: 2 };
* const source = { b: 3, c: 4 };
* const result = assignInWith(target, source, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 4 }
*/
declare function assignInWith<T, U>(object: T, source: U, customizer: AssignCustomizer): T & U;
/**
* Assigns own and inherited properties from two source objects to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const result = assignInWith(target, source1, source2, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3 }
*/
declare function assignInWith<T, U, V>(object: T, source1: U, source2: V, customizer: AssignCustomizer): T & U & V;
/**
* Assigns own and inherited properties from three source objects to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const result = assignInWith(target, source1, source2, source3, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3, d: 4 }
*/
declare function assignInWith<T, U, V, W>(object: T, source1: U, source2: V, source3: W, customizer: AssignCustomizer): T & U & V & W;
/**
* Assigns own and inherited properties from four source objects to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @template X - The type of the fourth source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @param source4 - The fourth source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const source4 = { e: 5 };
* const result = assignInWith(target, source1, source2, source3, source4, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3, d: 4, e: 5 }
*/
declare function assignInWith<T, U, V, W, X>(object: T, source1: U, source2: V, source3: W, source4: X, customizer: AssignCustomizer): T & U & V & W & X;
/**
* Returns the target object as-is.
*
* @template T - The type of the target object.
* @param object - The target object.
* @returns The target object.
*
* @example
* const target = { a: 1, b: 2 };
* const result = assignInWith(target);
* // => { a: 1, b: 2 }
*/
declare function assignInWith<T>(object: T): T;
/**
* Assigns own and inherited properties from multiple source objects to a target object using a customizer function.
*
* @template R - The type of the result.
* @param object - The target object to which properties will be assigned.
* @param otherArgs - The source objects and customizer function.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assignInWith(target, { b: 2 }, { c: 3 }, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3 }
*/
declare function assignInWith<R>(object: any, ...otherArgs: any[]): R;
//#endregion
export { assignInWith };

View file

@ -0,0 +1,48 @@
const require_isEqualsSameValueZero = require("../../_internal/isEqualsSameValueZero.js");
require("../util/eq.js");
const require_keysIn = require("./keysIn.js");
//#region src/compat/object/assignInWith.ts
/**
* Assigns properties from multiple source objects to a target object.
* You can provide a `getValueToAssign` function to determine what value will be assigned for each property.
*
* This function merges the properties of the source objects into the target object,
* including properties from the prototype chain. If a property in the source objects
* is equal to the corresponding property in the target object, it will not be overwritten.
*
* Unlike `assignIn`, this method accepts a `getValueToAssign` function that determines
* the final value to be assigned to each property in the target object. The return value
* of this function will be directly assigned to the corresponding property. This allows for
* more precise control over how properties are merged between objects. If not provided,
* the default behavior is equivalent to using the identity function (returning the source value).
*
* @param object - The target object to which properties will be assigned.
* @param sources - The source objects whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assignInWith(target, { b: 2 }, { c: 3 }, function(objValue, srcValue) {
* return objValue === undefined ? srcValue : objValue;
* });
* console.log(result); // Output: { a: 1, b: 2, c: 3 }
*/
function assignInWith(object, ...sources) {
let getValueToAssign = sources[sources.length - 1];
if (typeof getValueToAssign === "function") sources.pop();
else getValueToAssign = void 0;
for (let i = 0; i < sources.length; i++) assignInWithImpl(object, sources[i], getValueToAssign);
return object;
}
function assignInWithImpl(object, source, getValueToAssign) {
const keys = require_keysIn.keysIn(source);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const objValue = object[key];
const srcValue = source[key];
const newValue = getValueToAssign?.(objValue, srcValue, key, object, source) ?? srcValue;
if (!(key in object) || !require_isEqualsSameValueZero.isEqualsSameValueZero(objValue, newValue)) object[key] = newValue;
}
}
//#endregion
exports.assignInWith = assignInWith;

View file

@ -0,0 +1,48 @@
import { isEqualsSameValueZero } from "../../_internal/isEqualsSameValueZero.mjs";
import "../util/eq.mjs";
import { keysIn } from "./keysIn.mjs";
//#region src/compat/object/assignInWith.ts
/**
* Assigns properties from multiple source objects to a target object.
* You can provide a `getValueToAssign` function to determine what value will be assigned for each property.
*
* This function merges the properties of the source objects into the target object,
* including properties from the prototype chain. If a property in the source objects
* is equal to the corresponding property in the target object, it will not be overwritten.
*
* Unlike `assignIn`, this method accepts a `getValueToAssign` function that determines
* the final value to be assigned to each property in the target object. The return value
* of this function will be directly assigned to the corresponding property. This allows for
* more precise control over how properties are merged between objects. If not provided,
* the default behavior is equivalent to using the identity function (returning the source value).
*
* @param object - The target object to which properties will be assigned.
* @param sources - The source objects whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assignInWith(target, { b: 2 }, { c: 3 }, function(objValue, srcValue) {
* return objValue === undefined ? srcValue : objValue;
* });
* console.log(result); // Output: { a: 1, b: 2, c: 3 }
*/
function assignInWith(object, ...sources) {
let getValueToAssign = sources[sources.length - 1];
if (typeof getValueToAssign === "function") sources.pop();
else getValueToAssign = void 0;
for (let i = 0; i < sources.length; i++) assignInWithImpl(object, sources[i], getValueToAssign);
return object;
}
function assignInWithImpl(object, source, getValueToAssign) {
const keys = keysIn(source);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const objValue = object[key];
const srcValue = source[key];
const newValue = getValueToAssign?.(objValue, srcValue, key, object, source) ?? srcValue;
if (!(key in object) || !isEqualsSameValueZero(objValue, newValue)) object[key] = newValue;
}
}
//#endregion
export { assignInWith };

View file

@ -0,0 +1,127 @@
//#region src/compat/object/assignWith.d.ts
type AssignCustomizer = (objectValue: any, sourceValue: any, key?: string, object?: {}, source?: {}) => any;
/**
* Assigns own properties from one source object to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the source object.
* @param object - The target object to which properties will be assigned.
* @param source - The source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source object assigned.
*
* @example
* const target = { a: 1, b: 2 };
* const source = { b: 3, c: 4 };
* const result = assignWith(target, source, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 4 }
*/
declare function assignWith<T, U>(object: T, source: U, customizer: AssignCustomizer): T & U;
/**
* Assigns own properties from two source objects to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const result = assignWith(target, source1, source2, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3 }
*/
declare function assignWith<T, U, V>(object: T, source1: U, source2: V, customizer: AssignCustomizer): T & U & V;
/**
* Assigns own properties from three source objects to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const result = assignWith(target, source1, source2, source3, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3, d: 4 }
*/
declare function assignWith<T, U, V, W>(object: T, source1: U, source2: V, source3: W, customizer: AssignCustomizer): T & U & V & W;
/**
* Assigns own properties from four source objects to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @template X - The type of the fourth source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @param source4 - The fourth source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const source4 = { e: 5 };
* const result = assignWith(target, source1, source2, source3, source4, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3, d: 4, e: 5 }
*/
declare function assignWith<T, U, V, W, X>(object: T, source1: U, source2: V, source3: W, source4: X, customizer: AssignCustomizer): T & U & V & W & X;
/**
* Returns the target object as-is.
*
* @template T - The type of the target object.
* @param object - The target object.
* @returns The target object.
*
* @example
* const target = { a: 1, b: 2 };
* const result = assignWith(target);
* // => { a: 1, b: 2 }
*/
declare function assignWith<T>(object: T): T;
/**
* Assigns own properties from multiple source objects to a target object using a customizer function.
*
* @template R - The type of the result.
* @param object - The target object to which properties will be assigned.
* @param otherArgs - The source objects and customizer function.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assignWith(target, { b: 2 }, { c: 3 }, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3 }
*/
declare function assignWith<R>(object: any, ...otherArgs: any[]): R;
//#endregion
export { assignWith };

View file

@ -0,0 +1,127 @@
//#region src/compat/object/assignWith.d.ts
type AssignCustomizer = (objectValue: any, sourceValue: any, key?: string, object?: {}, source?: {}) => any;
/**
* Assigns own properties from one source object to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the source object.
* @param object - The target object to which properties will be assigned.
* @param source - The source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source object assigned.
*
* @example
* const target = { a: 1, b: 2 };
* const source = { b: 3, c: 4 };
* const result = assignWith(target, source, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 4 }
*/
declare function assignWith<T, U>(object: T, source: U, customizer: AssignCustomizer): T & U;
/**
* Assigns own properties from two source objects to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const result = assignWith(target, source1, source2, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3 }
*/
declare function assignWith<T, U, V>(object: T, source1: U, source2: V, customizer: AssignCustomizer): T & U & V;
/**
* Assigns own properties from three source objects to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const result = assignWith(target, source1, source2, source3, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3, d: 4 }
*/
declare function assignWith<T, U, V, W>(object: T, source1: U, source2: V, source3: W, customizer: AssignCustomizer): T & U & V & W;
/**
* Assigns own properties from four source objects to a target object using a customizer function.
*
* @template T - The type of the target object.
* @template U - The type of the first source object.
* @template V - The type of the second source object.
* @template W - The type of the third source object.
* @template X - The type of the fourth source object.
* @param object - The target object to which properties will be assigned.
* @param source1 - The first source object whose properties will be assigned to the target object.
* @param source2 - The second source object whose properties will be assigned to the target object.
* @param source3 - The third source object whose properties will be assigned to the target object.
* @param source4 - The fourth source object whose properties will be assigned to the target object.
* @param customizer - The function to customize assigned values.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const source1 = { b: 2 };
* const source2 = { c: 3 };
* const source3 = { d: 4 };
* const source4 = { e: 5 };
* const result = assignWith(target, source1, source2, source3, source4, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3, d: 4, e: 5 }
*/
declare function assignWith<T, U, V, W, X>(object: T, source1: U, source2: V, source3: W, source4: X, customizer: AssignCustomizer): T & U & V & W & X;
/**
* Returns the target object as-is.
*
* @template T - The type of the target object.
* @param object - The target object.
* @returns The target object.
*
* @example
* const target = { a: 1, b: 2 };
* const result = assignWith(target);
* // => { a: 1, b: 2 }
*/
declare function assignWith<T>(object: T): T;
/**
* Assigns own properties from multiple source objects to a target object using a customizer function.
*
* @template R - The type of the result.
* @param object - The target object to which properties will be assigned.
* @param otherArgs - The source objects and customizer function.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assignWith(target, { b: 2 }, { c: 3 }, (objValue, srcValue) => {
* return objValue === undefined ? srcValue : objValue;
* });
* // => { a: 1, b: 2, c: 3 }
*/
declare function assignWith<R>(object: any, ...otherArgs: any[]): R;
//#endregion
export { assignWith };

View file

@ -0,0 +1,48 @@
const require_isEqualsSameValueZero = require("../../_internal/isEqualsSameValueZero.js");
require("../util/eq.js");
const require_keys = require("./keys.js");
//#region src/compat/object/assignWith.ts
/**
* Assigns properties from multiple source objects to a target object.
* You can provide a `getValueToAssign` function to determine what value will be assigned for each property.
*
* This function merges the properties of the source objects into the target object.
* If a property in the source objects is equal to the corresponding property in the target object,
* it will not be overwritten.
*
* Unlike `assign`, this method accepts a `getValueToAssign` function that determines
* the final value to be assigned to each property in the target object. The return value
* of this function will be directly assigned to the corresponding property. This allows for
* more precise control over how properties are merged between objects. If not provided,
* the default behavior is equivalent to using the identity function (returning the source value).
*
* @param object - The target object to which properties will be assigned.
* @param sources - The source objects whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assignWith(target, { b: 2 }, { c: 3 }, function(objValue, srcValue) {
* return objValue === undefined ? srcValue : objValue;
* });
* console.log(result); // Output: { a: 1, b: 2, c: 3 }
*/
function assignWith(object, ...sources) {
let getValueToAssign = sources[sources.length - 1];
if (typeof getValueToAssign === "function") sources.pop();
else getValueToAssign = void 0;
for (let i = 0; i < sources.length; i++) assignWithImpl(object, sources[i], getValueToAssign);
return object;
}
function assignWithImpl(object, source, getValueToAssign) {
const keys$1 = require_keys.keys(source);
for (let i = 0; i < keys$1.length; i++) {
const key = keys$1[i];
const objValue = object[key];
const srcValue = source[key];
const newValue = getValueToAssign?.(objValue, srcValue, key, object, source) ?? srcValue;
if (!(key in object) || !require_isEqualsSameValueZero.isEqualsSameValueZero(objValue, newValue)) object[key] = newValue;
}
}
//#endregion
exports.assignWith = assignWith;

View file

@ -0,0 +1,48 @@
import { isEqualsSameValueZero } from "../../_internal/isEqualsSameValueZero.mjs";
import "../util/eq.mjs";
import { keys } from "./keys.mjs";
//#region src/compat/object/assignWith.ts
/**
* Assigns properties from multiple source objects to a target object.
* You can provide a `getValueToAssign` function to determine what value will be assigned for each property.
*
* This function merges the properties of the source objects into the target object.
* If a property in the source objects is equal to the corresponding property in the target object,
* it will not be overwritten.
*
* Unlike `assign`, this method accepts a `getValueToAssign` function that determines
* the final value to be assigned to each property in the target object. The return value
* of this function will be directly assigned to the corresponding property. This allows for
* more precise control over how properties are merged between objects. If not provided,
* the default behavior is equivalent to using the identity function (returning the source value).
*
* @param object - The target object to which properties will be assigned.
* @param sources - The source objects whose properties will be assigned to the target object.
* @returns The updated target object with properties from the source objects assigned.
*
* @example
* const target = { a: 1 };
* const result = assignWith(target, { b: 2 }, { c: 3 }, function(objValue, srcValue) {
* return objValue === undefined ? srcValue : objValue;
* });
* console.log(result); // Output: { a: 1, b: 2, c: 3 }
*/
function assignWith(object, ...sources) {
let getValueToAssign = sources[sources.length - 1];
if (typeof getValueToAssign === "function") sources.pop();
else getValueToAssign = void 0;
for (let i = 0; i < sources.length; i++) assignWithImpl(object, sources[i], getValueToAssign);
return object;
}
function assignWithImpl(object, source, getValueToAssign) {
const keys$1 = keys(source);
for (let i = 0; i < keys$1.length; i++) {
const key = keys$1[i];
const objValue = object[key];
const srcValue = source[key];
const newValue = getValueToAssign?.(objValue, srcValue, key, object, source) ?? srcValue;
if (!(key in object) || !isEqualsSameValueZero(objValue, newValue)) object[key] = newValue;
}
}
//#endregion
export { assignWith };

View file

@ -0,0 +1,34 @@
//#region src/compat/object/at.d.ts
type PropertyName = string | number | symbol;
type Many<T> = T | readonly T[];
type PropertyPath = Many<PropertyName>;
/**
* Gets values at given paths from a dictionary or numeric dictionary.
*
* @template T - The type of the values in the dictionary.
* @param object - The dictionary to query.
* @param props - The property paths to get values for.
* @returns Returns an array of the picked values.
*
* @example
* const object = { 'a': 1, 'b': 2, 'c': 3 };
* at(object, 'a', 'c');
* // => [1, 3]
*/
declare function at<T>(object: Record<string, T> | Record<number, T> | null | undefined, ...props: PropertyPath[]): T[];
/**
* Gets values at given keys from an object.
*
* @template T - The type of the object.
* @param object - The object to query.
* @param props - The property keys to get values for.
* @returns Returns an array of the picked values.
*
* @example
* const object = { 'a': 1, 'b': 2, 'c': 3 };
* at(object, 'a', 'c');
* // => [1, 3]
*/
declare function at<T extends object>(object: T | null | undefined, ...props: Array<Many<keyof T>>): Array<T[keyof T]>;
//#endregion
export { at };

View file

@ -0,0 +1,34 @@
//#region src/compat/object/at.d.ts
type PropertyName = string | number | symbol;
type Many<T> = T | readonly T[];
type PropertyPath = Many<PropertyName>;
/**
* Gets values at given paths from a dictionary or numeric dictionary.
*
* @template T - The type of the values in the dictionary.
* @param object - The dictionary to query.
* @param props - The property paths to get values for.
* @returns Returns an array of the picked values.
*
* @example
* const object = { 'a': 1, 'b': 2, 'c': 3 };
* at(object, 'a', 'c');
* // => [1, 3]
*/
declare function at<T>(object: Record<string, T> | Record<number, T> | null | undefined, ...props: PropertyPath[]): T[];
/**
* Gets values at given keys from an object.
*
* @template T - The type of the object.
* @param object - The object to query.
* @param props - The property keys to get values for.
* @returns Returns an array of the picked values.
*
* @example
* const object = { 'a': 1, 'b': 2, 'c': 3 };
* at(object, 'a', 'c');
* // => [1, 3]
*/
declare function at<T extends object>(object: T | null | undefined, ...props: Array<Many<keyof T>>): Array<T[keyof T]>;
//#endregion
export { at };

View file

@ -0,0 +1,37 @@
const require_isArrayLike = require("../predicate/isArrayLike.js");
const require_get = require("./get.js");
const require_isString = require("../predicate/isString.js");
//#region src/compat/object/at.ts
/**
* Returns an array of values corresponding to `paths` of `object`.
*
* @template T - The type of the object.
* @param object - The object to iterate over.
* @param [paths] - The property paths to pick.
* @returns Returns the picked values.
*
* @example
* ```js
* const object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
*
* at(object, ['a[0].b.c', 'a[1]']);
* // => [3, 4]
* ```
*/
function at(object, ...paths) {
if (paths.length === 0) return [];
const allPaths = [];
for (let i = 0; i < paths.length; i++) {
const path = paths[i];
if (!require_isArrayLike.isArrayLike(path) || require_isString.isString(path)) {
allPaths.push(path);
continue;
}
for (let j = 0; j < path.length; j++) allPaths.push(path[j]);
}
const result = [];
for (let i = 0; i < allPaths.length; i++) result.push(require_get.get(object, allPaths[i]));
return result;
}
//#endregion
exports.at = at;

View file

@ -0,0 +1,37 @@
import { isArrayLike } from "../predicate/isArrayLike.mjs";
import { get } from "./get.mjs";
import { isString } from "../predicate/isString.mjs";
//#region src/compat/object/at.ts
/**
* Returns an array of values corresponding to `paths` of `object`.
*
* @template T - The type of the object.
* @param object - The object to iterate over.
* @param [paths] - The property paths to pick.
* @returns Returns the picked values.
*
* @example
* ```js
* const object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
*
* at(object, ['a[0].b.c', 'a[1]']);
* // => [3, 4]
* ```
*/
function at(object, ...paths) {
if (paths.length === 0) return [];
const allPaths = [];
for (let i = 0; i < paths.length; i++) {
const path = paths[i];
if (!isArrayLike(path) || isString(path)) {
allPaths.push(path);
continue;
}
for (let j = 0; j < path.length; j++) allPaths.push(path[j]);
}
const result = [];
for (let i = 0; i < allPaths.length; i++) result.push(get(object, allPaths[i]));
return result;
}
//#endregion
export { at };

View file

@ -0,0 +1,32 @@
//#region src/compat/object/clone.d.ts
/**
* Creates a shallow clone of the given object.
*
* @template T - The type of the object.
* @param obj - The object to clone.
* @returns A shallow clone of the given object.
*
* @example
* // Clone a primitive object
* 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
*/
declare function clone<T>(obj: T): T;
//#endregion
export { clone };

View file

@ -0,0 +1,32 @@
//#region src/compat/object/clone.d.ts
/**
* Creates a shallow clone of the given object.
*
* @template T - The type of the object.
* @param obj - The object to clone.
* @returns A shallow clone of the given object.
*
* @example
* // Clone a primitive object
* 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
*/
declare function clone<T>(obj: T): T;
//#endregion
export { clone };

View file

@ -0,0 +1,156 @@
const require_isPrimitive = require("../../predicate/isPrimitive.js");
const require_getTag = require("../_internal/getTag.js");
const require_tags = require("../_internal/tags.js");
const require_isArray = require("../predicate/isArray.js");
const require_isTypedArray = require("../predicate/isTypedArray.js");
//#region src/compat/object/clone.ts
/**
* Creates a shallow clone of the given object.
*
* @template T - The type of the object.
* @param obj - The object to clone.
* @returns A shallow clone of the given object.
*
* @example
* // Clone a primitive object
* 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 (require_isPrimitive.isPrimitive(obj)) return obj;
const tag = require_getTag.getTag(obj);
if (!isCloneableObject(obj)) return {};
if (require_isArray.isArray(obj)) {
const result = Array.from(obj);
if (obj.length > 0 && typeof obj[0] === "string" && Object.hasOwn(obj, "index")) {
result.index = obj.index;
result.input = obj.input;
}
return result;
}
if (require_isTypedArray.isTypedArray(obj)) {
const typedArray = obj;
const Ctor = typedArray.constructor;
return new Ctor(typedArray.buffer, typedArray.byteOffset, typedArray.length);
}
if (tag === "[object ArrayBuffer]") return new ArrayBuffer(obj.byteLength);
if (tag === "[object DataView]") {
const dataView = obj;
const buffer = dataView.buffer;
const byteOffset = dataView.byteOffset;
const byteLength = dataView.byteLength;
const clonedBuffer = new ArrayBuffer(byteLength);
const srcView = new Uint8Array(buffer, byteOffset, byteLength);
new Uint8Array(clonedBuffer).set(srcView);
return new DataView(clonedBuffer);
}
if (tag === "[object Boolean]" || tag === "[object Number]" || tag === "[object String]") {
const Ctor = obj.constructor;
const clone = new Ctor(obj.valueOf());
if (tag === "[object String]") cloneStringObjectProperties(clone, obj);
else copyOwnProperties(clone, obj);
return clone;
}
if (tag === "[object Date]") return new Date(Number(obj));
if (tag === "[object RegExp]") {
const regExp = obj;
const clone = new RegExp(regExp.source, regExp.flags);
clone.lastIndex = regExp.lastIndex;
return clone;
}
if (tag === "[object Symbol]") return Object(Symbol.prototype.valueOf.call(obj));
if (tag === "[object Map]") {
const map = obj;
const result = /* @__PURE__ */ new Map();
map.forEach((obj, key) => {
result.set(key, obj);
});
return result;
}
if (tag === "[object Set]") {
const set = obj;
const result = /* @__PURE__ */ new Set();
set.forEach((obj) => {
result.add(obj);
});
return result;
}
if (tag === "[object Arguments]") {
const args = obj;
const result = {};
copyOwnProperties(result, args);
result.length = args.length;
result[Symbol.iterator] = args[Symbol.iterator];
return result;
}
const result = {};
copyPrototype(result, obj);
copyOwnProperties(result, obj);
copySymbolProperties(result, obj);
return result;
}
function isCloneableObject(object) {
switch (require_getTag.getTag(object)) {
case require_tags.argumentsTag:
case require_tags.arrayTag:
case require_tags.arrayBufferTag:
case require_tags.dataViewTag:
case require_tags.booleanTag:
case require_tags.dateTag:
case require_tags.float32ArrayTag:
case require_tags.float64ArrayTag:
case require_tags.int8ArrayTag:
case require_tags.int16ArrayTag:
case require_tags.int32ArrayTag:
case require_tags.mapTag:
case require_tags.numberTag:
case require_tags.objectTag:
case require_tags.regexpTag:
case require_tags.setTag:
case require_tags.stringTag:
case require_tags.symbolTag:
case require_tags.uint8ArrayTag:
case require_tags.uint8ClampedArrayTag:
case require_tags.uint16ArrayTag:
case require_tags.uint32ArrayTag: return true;
default: return false;
}
}
function copyOwnProperties(target, source) {
for (const key in source) if (Object.hasOwn(source, key)) target[key] = source[key];
}
function copySymbolProperties(target, source) {
const symbols = Object.getOwnPropertySymbols(source);
for (let i = 0; i < symbols.length; i++) {
const symbol = symbols[i];
if (Object.prototype.propertyIsEnumerable.call(source, symbol)) target[symbol] = source[symbol];
}
}
function cloneStringObjectProperties(target, source) {
const stringLength = source.valueOf().length;
for (const key in source) if (Object.hasOwn(source, key) && (Number.isNaN(Number(key)) || Number(key) >= stringLength)) target[key] = source[key];
}
function copyPrototype(target, source) {
const proto = Object.getPrototypeOf(source);
if (proto !== null) {
if (typeof source.constructor === "function") Object.setPrototypeOf(target, proto);
}
}
//#endregion
exports.clone = clone;

View file

@ -0,0 +1,156 @@
import { isPrimitive } from "../../predicate/isPrimitive.mjs";
import { getTag } from "../_internal/getTag.mjs";
import { argumentsTag, arrayBufferTag, arrayTag, booleanTag, dataViewTag, dateTag, float32ArrayTag, float64ArrayTag, int16ArrayTag, int32ArrayTag, int8ArrayTag, mapTag, numberTag, objectTag, regexpTag, setTag, stringTag, symbolTag, uint16ArrayTag, uint32ArrayTag, uint8ArrayTag, uint8ClampedArrayTag } from "../_internal/tags.mjs";
import { isArray } from "../predicate/isArray.mjs";
import { isTypedArray } from "../predicate/isTypedArray.mjs";
//#region src/compat/object/clone.ts
/**
* Creates a shallow clone of the given object.
*
* @template T - The type of the object.
* @param obj - The object to clone.
* @returns A shallow clone of the given object.
*
* @example
* // Clone a primitive object
* 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;
const tag = getTag(obj);
if (!isCloneableObject(obj)) return {};
if (isArray(obj)) {
const result = Array.from(obj);
if (obj.length > 0 && typeof obj[0] === "string" && Object.hasOwn(obj, "index")) {
result.index = obj.index;
result.input = obj.input;
}
return result;
}
if (isTypedArray(obj)) {
const typedArray = obj;
const Ctor = typedArray.constructor;
return new Ctor(typedArray.buffer, typedArray.byteOffset, typedArray.length);
}
if (tag === "[object ArrayBuffer]") return new ArrayBuffer(obj.byteLength);
if (tag === "[object DataView]") {
const dataView = obj;
const buffer = dataView.buffer;
const byteOffset = dataView.byteOffset;
const byteLength = dataView.byteLength;
const clonedBuffer = new ArrayBuffer(byteLength);
const srcView = new Uint8Array(buffer, byteOffset, byteLength);
new Uint8Array(clonedBuffer).set(srcView);
return new DataView(clonedBuffer);
}
if (tag === "[object Boolean]" || tag === "[object Number]" || tag === "[object String]") {
const Ctor = obj.constructor;
const clone = new Ctor(obj.valueOf());
if (tag === "[object String]") cloneStringObjectProperties(clone, obj);
else copyOwnProperties(clone, obj);
return clone;
}
if (tag === "[object Date]") return new Date(Number(obj));
if (tag === "[object RegExp]") {
const regExp = obj;
const clone = new RegExp(regExp.source, regExp.flags);
clone.lastIndex = regExp.lastIndex;
return clone;
}
if (tag === "[object Symbol]") return Object(Symbol.prototype.valueOf.call(obj));
if (tag === "[object Map]") {
const map = obj;
const result = /* @__PURE__ */ new Map();
map.forEach((obj, key) => {
result.set(key, obj);
});
return result;
}
if (tag === "[object Set]") {
const set = obj;
const result = /* @__PURE__ */ new Set();
set.forEach((obj) => {
result.add(obj);
});
return result;
}
if (tag === "[object Arguments]") {
const args = obj;
const result = {};
copyOwnProperties(result, args);
result.length = args.length;
result[Symbol.iterator] = args[Symbol.iterator];
return result;
}
const result = {};
copyPrototype(result, obj);
copyOwnProperties(result, obj);
copySymbolProperties(result, obj);
return result;
}
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;
}
}
function copyOwnProperties(target, source) {
for (const key in source) if (Object.hasOwn(source, key)) target[key] = source[key];
}
function copySymbolProperties(target, source) {
const symbols = Object.getOwnPropertySymbols(source);
for (let i = 0; i < symbols.length; i++) {
const symbol = symbols[i];
if (Object.prototype.propertyIsEnumerable.call(source, symbol)) target[symbol] = source[symbol];
}
}
function cloneStringObjectProperties(target, source) {
const stringLength = source.valueOf().length;
for (const key in source) if (Object.hasOwn(source, key) && (Number.isNaN(Number(key)) || Number(key) >= stringLength)) target[key] = source[key];
}
function copyPrototype(target, source) {
const proto = Object.getPrototypeOf(source);
if (proto !== null) {
if (typeof source.constructor === "function") Object.setPrototypeOf(target, proto);
}
}
//#endregion
export { clone };

View file

@ -0,0 +1,50 @@
//#region src/compat/object/cloneDeep.d.ts
/**
* Creates a deep clone of the given object.
*
* @template T - The type of the object.
* @param obj - The object to clone.
* @returns A deep clone of the given object.
*
* @example
* // Clone a primitive value
* 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
*/
declare function cloneDeep<T>(obj: T): T;
//#endregion
export { cloneDeep };

View file

@ -0,0 +1,50 @@
//#region src/compat/object/cloneDeep.d.ts
/**
* Creates a deep clone of the given object.
*
* @template T - The type of the object.
* @param obj - The object to clone.
* @returns A deep clone of the given object.
*
* @example
* // Clone a primitive value
* 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
*/
declare function cloneDeep<T>(obj: T): T;
//#endregion
export { cloneDeep };

View file

@ -0,0 +1,53 @@
const require_cloneDeepWith = require("./cloneDeepWith.js");
//#region src/compat/object/cloneDeep.ts
/**
* Creates a deep clone of the given object.
*
* @template T - The type of the object.
* @param obj - The object to clone.
* @returns A deep clone of the given object.
*
* @example
* // Clone a primitive value
* 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 require_cloneDeepWith.cloneDeepWith(obj);
}
//#endregion
exports.cloneDeep = cloneDeep;

View file

@ -0,0 +1,53 @@
import { cloneDeepWith } from "./cloneDeepWith.mjs";
//#region src/compat/object/cloneDeep.ts
/**
* Creates a deep clone of the given object.
*
* @template T - The type of the object.
* @param obj - The object to clone.
* @returns A deep clone of the given object.
*
* @example
* // Clone a primitive value
* 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
export { cloneDeep };

View file

@ -0,0 +1,35 @@
//#region src/compat/object/cloneDeepWith.d.ts
type CloneDeepWithCustomizer<TObject> = (value: any, key: number | string | undefined, object: TObject | undefined, stack: any) => any;
/**
* Creates a deep clone of the given value using a customizer function.
*
* @template T - The type of the value.
* @param value - The value to clone.
* @param customizer - A function to customize the cloning process.
* @returns A deep clone of the given value.
*
* @example
* const obj = { a: 1, b: 2 };
* const clonedObj = cloneDeepWith(obj, (value) => {
* if (typeof value === 'number') {
* return value * 2;
* }
* });
* // => { a: 2, b: 4 }
*/
declare function cloneDeepWith<T>(value: T, customizer: CloneDeepWithCustomizer<T>): any;
/**
* Creates a deep clone of the given value.
*
* @template T - The type of the value.
* @param value - The value to clone.
* @returns A deep clone of the given value.
*
* @example
* const obj = { a: 1, b: { c: 2 } };
* const clonedObj = cloneDeepWith(obj);
* // => { a: 1, b: { c: 2 } }
*/
declare function cloneDeepWith<T>(value: T): T;
//#endregion
export { cloneDeepWith };

View file

@ -0,0 +1,35 @@
//#region src/compat/object/cloneDeepWith.d.ts
type CloneDeepWithCustomizer<TObject> = (value: any, key: number | string | undefined, object: TObject | undefined, stack: any) => any;
/**
* Creates a deep clone of the given value using a customizer function.
*
* @template T - The type of the value.
* @param value - The value to clone.
* @param customizer - A function to customize the cloning process.
* @returns A deep clone of the given value.
*
* @example
* const obj = { a: 1, b: 2 };
* const clonedObj = cloneDeepWith(obj, (value) => {
* if (typeof value === 'number') {
* return value * 2;
* }
* });
* // => { a: 2, b: 4 }
*/
declare function cloneDeepWith<T>(value: T, customizer: CloneDeepWithCustomizer<T>): any;
/**
* Creates a deep clone of the given value.
*
* @template T - The type of the value.
* @param value - The value to clone.
* @returns A deep clone of the given value.
*
* @example
* const obj = { a: 1, b: { c: 2 } };
* const clonedObj = cloneDeepWith(obj);
* // => { a: 1, b: { c: 2 } }
*/
declare function cloneDeepWith<T>(value: T): T;
//#endregion
export { cloneDeepWith };

View file

@ -0,0 +1,71 @@
const require_getTag = require("../_internal/getTag.js");
const require_tags = require("../_internal/tags.js");
const require_cloneDeepWith = require("../../object/cloneDeepWith.js");
//#region src/compat/object/cloneDeepWith.ts
/**
* Creates a deep clone of the given object using a customizer function.
*
* @template T - The type of the object.
* @param obj - The object to clone.
* @param [cloneValue] - A function to customize the cloning process.
* @returns 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 require_cloneDeepWith.cloneDeepWith(obj, (value, key, object, stack) => {
const cloned = customizer?.(value, key, object, stack);
if (cloned !== void 0) return cloned;
if (typeof obj !== "object") return;
if (require_getTag.getTag(obj) === "[object Object]" && typeof obj.constructor !== "function") {
const result = {};
stack.set(obj, result);
require_cloneDeepWith.copyProperties(result, obj, object, stack);
return result;
}
switch (Object.prototype.toString.call(obj)) {
case require_tags.numberTag:
case require_tags.stringTag:
case require_tags.booleanTag: {
const result = new obj.constructor(obj?.valueOf());
require_cloneDeepWith.copyProperties(result, obj);
return result;
}
case require_tags.argumentsTag: {
const result = {};
require_cloneDeepWith.copyProperties(result, obj);
result.length = obj.length;
result[Symbol.iterator] = obj[Symbol.iterator];
return result;
}
default: return;
}
});
}
//#endregion
exports.cloneDeepWith = cloneDeepWith;

View file

@ -0,0 +1,71 @@
import { getTag } from "../_internal/getTag.mjs";
import { argumentsTag, booleanTag, numberTag, stringTag } from "../_internal/tags.mjs";
import { cloneDeepWith as cloneDeepWith$1, copyProperties } from "../../object/cloneDeepWith.mjs";
//#region src/compat/object/cloneDeepWith.ts
/**
* Creates a deep clone of the given object using a customizer function.
*
* @template T - The type of the object.
* @param obj - The object to clone.
* @param [cloneValue] - A function to customize the cloning process.
* @returns 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
export { cloneDeepWith };

View file

@ -0,0 +1,55 @@
//#region src/compat/object/cloneWith.d.ts
type CloneWithCustomizer<T, R> = (value: T, key: number | string | undefined, object: any, stack: any) => R;
/**
* Creates a shallow clone of a value with customizer that returns a specific result type.
*
* @template T - The type of the value to clone.
* @template R - The result type extending primitive types or objects.
* @param value - The value to clone.
* @param customizer - The function to customize cloning.
* @returns Returns the cloned value.
*
* @example
* const obj = { a: 1, b: 2 };
* const cloned = cloneWith(obj, (value) => {
* if (typeof value === 'object') {
* return JSON.parse(JSON.stringify(value));
* }
* });
* // => { a: 1, b: 2 }
*/
declare function cloneWith<T, R extends object | string | number | boolean | null>(value: T, customizer: CloneWithCustomizer<T, R>): R;
/**
* Creates a shallow clone of a value with optional customizer.
*
* @template T - The type of the value to clone.
* @template R - The result type.
* @param value - The value to clone.
* @param customizer - The function to customize cloning.
* @returns Returns the cloned value or the customized result.
*
* @example
* const obj = { a: 1, b: 2 };
* const cloned = cloneWith(obj, (value) => {
* if (typeof value === 'number') {
* return value * 2;
* }
* });
* // => { a: 2, b: 4 }
*/
declare function cloneWith<T, R>(value: T, customizer: CloneWithCustomizer<T, R | undefined>): R | T;
/**
* Creates a shallow clone of a value.
*
* @template T - The type of the value to clone.
* @param value - The value to clone.
* @returns Returns the cloned value.
*
* @example
* const obj = { a: 1, b: 2 };
* const cloned = cloneWith(obj);
* // => { a: 1, b: 2 }
*/
declare function cloneWith<T>(value: T): T;
//#endregion
export { cloneWith };

View file

@ -0,0 +1,55 @@
//#region src/compat/object/cloneWith.d.ts
type CloneWithCustomizer<T, R> = (value: T, key: number | string | undefined, object: any, stack: any) => R;
/**
* Creates a shallow clone of a value with customizer that returns a specific result type.
*
* @template T - The type of the value to clone.
* @template R - The result type extending primitive types or objects.
* @param value - The value to clone.
* @param customizer - The function to customize cloning.
* @returns Returns the cloned value.
*
* @example
* const obj = { a: 1, b: 2 };
* const cloned = cloneWith(obj, (value) => {
* if (typeof value === 'object') {
* return JSON.parse(JSON.stringify(value));
* }
* });
* // => { a: 1, b: 2 }
*/
declare function cloneWith<T, R extends object | string | number | boolean | null>(value: T, customizer: CloneWithCustomizer<T, R>): R;
/**
* Creates a shallow clone of a value with optional customizer.
*
* @template T - The type of the value to clone.
* @template R - The result type.
* @param value - The value to clone.
* @param customizer - The function to customize cloning.
* @returns Returns the cloned value or the customized result.
*
* @example
* const obj = { a: 1, b: 2 };
* const cloned = cloneWith(obj, (value) => {
* if (typeof value === 'number') {
* return value * 2;
* }
* });
* // => { a: 2, b: 4 }
*/
declare function cloneWith<T, R>(value: T, customizer: CloneWithCustomizer<T, R | undefined>): R | T;
/**
* Creates a shallow clone of a value.
*
* @template T - The type of the value to clone.
* @param value - The value to clone.
* @returns Returns the cloned value.
*
* @example
* const obj = { a: 1, b: 2 };
* const cloned = cloneWith(obj);
* // => { a: 1, b: 2 }
*/
declare function cloneWith<T>(value: T): T;
//#endregion
export { cloneWith };

View file

@ -0,0 +1,55 @@
const require_clone = require("./clone.js");
//#region src/compat/object/cloneWith.ts
/**
* Creates a shallow clone of the given object with customization.
* This method is like `_.clone` except that it accepts a customizer which
* is invoked to produce the cloned value. If customizer returns undefined,
* cloning is handled by the method instead.
*
* If no customizer is provided, it behaves like `clone`.
*
* @template T - The type of the object.
* @param value - The value to clone.
* @param [customizer] - The function to customize cloning.
* @returns A shallow clone of the given object.
*
* @example
* // Clone a primitive value
* const num = 29;
* const clonedNum = cloneWith(num);
* console.log(clonedNum); // 29
* console.log(clonedNum === num); // true
*
* @example
* // Clone an array
* const arr = [1, 2, 3];
* const clonedArr = cloneWith(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 = cloneWith(obj);
* console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
* console.log(clonedObj === obj); // false
*
* @example
* // Clone an object with a customizer
* const obj = { a: 1, b: 2 };
* const clonedObj = cloneWith(obj, (value) => {
* if (typeof value === 'number') {
* return value * 2; // Double the number
* }
* // Returning undefined uses the default cloning
* });
* console.log(clonedObj); // { a: 2, b: 4 }
*/
function cloneWith(value, customizer) {
if (!customizer) return require_clone.clone(value);
const result = customizer(value);
if (result !== void 0) return result;
return require_clone.clone(value);
}
//#endregion
exports.cloneWith = cloneWith;

View file

@ -0,0 +1,55 @@
import { clone } from "./clone.mjs";
//#region src/compat/object/cloneWith.ts
/**
* Creates a shallow clone of the given object with customization.
* This method is like `_.clone` except that it accepts a customizer which
* is invoked to produce the cloned value. If customizer returns undefined,
* cloning is handled by the method instead.
*
* If no customizer is provided, it behaves like `clone`.
*
* @template T - The type of the object.
* @param value - The value to clone.
* @param [customizer] - The function to customize cloning.
* @returns A shallow clone of the given object.
*
* @example
* // Clone a primitive value
* const num = 29;
* const clonedNum = cloneWith(num);
* console.log(clonedNum); // 29
* console.log(clonedNum === num); // true
*
* @example
* // Clone an array
* const arr = [1, 2, 3];
* const clonedArr = cloneWith(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 = cloneWith(obj);
* console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
* console.log(clonedObj === obj); // false
*
* @example
* // Clone an object with a customizer
* const obj = { a: 1, b: 2 };
* const clonedObj = cloneWith(obj, (value) => {
* if (typeof value === 'number') {
* return value * 2; // Double the number
* }
* // Returning undefined uses the default cloning
* });
* console.log(clonedObj); // { a: 2, b: 4 }
*/
function cloneWith(value, customizer) {
if (!customizer) return clone(value);
const result = customizer(value);
if (result !== void 0) return result;
return clone(value);
}
//#endregion
export { cloneWith };

View file

@ -0,0 +1,17 @@
//#region src/compat/object/create.d.ts
/**
* Creates an object that inherits from the prototype object.
*
* If `properties` are provided, they will be added to the new object.
* Only string-keyed enumerable properties directly owned by the `properties` object are copied.
* Inherited properties or those with `Symbol` keys are not copied.
*
* @template T - The prototype object type.
* @template U - The properties object type.
* @param prototype - The object to inherit from.
* @param properties - The properties to assign to the created object.
* @returns The new object.
*/
declare function create<T extends object, U extends object>(prototype: T, properties?: U): T & U;
//#endregion
export { create };

View file

@ -0,0 +1,17 @@
//#region src/compat/object/create.d.ts
/**
* Creates an object that inherits from the prototype object.
*
* If `properties` are provided, they will be added to the new object.
* Only string-keyed enumerable properties directly owned by the `properties` object are copied.
* Inherited properties or those with `Symbol` keys are not copied.
*
* @template T - The prototype object type.
* @template U - The properties object type.
* @param prototype - The object to inherit from.
* @param properties - The properties to assign to the created object.
* @returns The new object.
*/
declare function create<T extends object, U extends object>(prototype: T, properties?: U): T & U;
//#endregion
export { create };

View file

@ -0,0 +1,31 @@
const require_isObject = require("../predicate/isObject.js");
const require_assignValue = require("../_internal/assignValue.js");
const require_keys = require("./keys.js");
//#region src/compat/object/create.ts
/**
* Creates an object that inherits from the prototype object.
*
* If `properties` are provided, they will be added to the new object.
* Only string-keyed enumerable properties directly owned by the `properties` object are copied.
* Inherited properties or those with `Symbol` keys are not copied.
*
* @template T - The prototype object type.
* @template U - The properties object type.
* @param prototype - The object to inherit from.
* @param properties - The properties to assign to the created object.
* @returns The new object.
*/
function create(prototype, properties) {
const proto = require_isObject.isObject(prototype) ? Object.create(prototype) : {};
if (properties != null) {
const propsKeys = require_keys.keys(properties);
for (let i = 0; i < propsKeys.length; i++) {
const key = propsKeys[i];
const propsValue = properties[key];
require_assignValue.assignValue(proto, key, propsValue);
}
}
return proto;
}
//#endregion
exports.create = create;

View file

@ -0,0 +1,31 @@
import { isObject } from "../predicate/isObject.mjs";
import { assignValue } from "../_internal/assignValue.mjs";
import { keys } from "./keys.mjs";
//#region src/compat/object/create.ts
/**
* Creates an object that inherits from the prototype object.
*
* If `properties` are provided, they will be added to the new object.
* Only string-keyed enumerable properties directly owned by the `properties` object are copied.
* Inherited properties or those with `Symbol` keys are not copied.
*
* @template T - The prototype object type.
* @template U - The properties object type.
* @param prototype - The object to inherit from.
* @param properties - The properties to assign to the created object.
* @returns The new object.
*/
function create(prototype, properties) {
const proto = isObject(prototype) ? Object.create(prototype) : {};
if (properties != null) {
const propsKeys = keys(properties);
for (let i = 0; i < propsKeys.length; i++) {
const key = propsKeys[i];
const propsValue = properties[key];
assignValue(proto, key, propsValue);
}
}
return proto;
}
//#endregion
export { create };

View file

@ -0,0 +1,101 @@
//#region src/compat/object/defaults.d.ts
/**
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* @template T - The type of the object being processed.
* @template S - The type of the object that provides default values.
* @param object - The target object that will receive default values.
* @param source - The object that specifies the default values to apply.
* @returns The `object` that has been updated with default values from `source`.
*
* @example
* defaults({ a: 1 }, { b: 2 }); // { a: 1, b: 2 }
* defaults({ a: undefined }, { a: 1 }); // { a: 1 }
*/
declare function defaults<T, S>(object: T, source: S): NonNullable<S & T>;
/**
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* @template T - The type of the object being processed.
* @template S1 - The type of the first object that provides default values.
* @template S2 - The type of the second object that provides default values.
* @param object - The target object that will receive default values.
* @param source1 - The first object that specifies the default values to apply.
* @param source2 - The second object that specifies the default values to apply.
* @returns The `object` that has been updated with default values from `source1` and `source2`.
*
* @example
* defaults({ a: 1 }, { b: 2 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
* defaults({ a: undefined }, { a: 1 }, { b: 2 }); // { a: 1, b: 2 }
*/
declare function defaults<T, S1, S2>(object: T, source1: S1, source2: S2): NonNullable<S2 & S1 & T>;
/**
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* @template T - The type of the object being processed.
* @template S1 - The type of the first object that provides default values.
* @template S2 - The type of the second object that provides default values.
* @template S3 - The type of the third object that provides default values.
* @param object - The target object that will receive default values.
* @param source1 - The first object that specifies the default values to apply.
* @param source2 - The second object that specifies the default values to apply.
* @param source3 - The third object that specifies the default values to apply.
* @returns The `object` that has been updated with default values from `source1`, `source2`, and `source3`.
*
* @example
* defaults({ a: 1 }, { b: 2 }, { c: 3 }, { d: 4 }); // { a: 1, b: 2, c: 3, d: 4 }
* defaults({ a: undefined }, { a: 1 }, { b: 2 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
*/
declare function defaults<T, S1, S2, S3>(object: T, source1: S1, source2: S2, source3: S3): NonNullable<S3 & S2 & S1 & T>;
/**
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* @template T - The type of the object being processed.
* @template S1 - The type of the first object that provides default values.
* @template S2 - The type of the second object that provides default values.
* @template S3 - The type of the third object that provides default values.
* @template S4 - The type of the fourth object that provides default values.
* @param object - The target object that will receive default values.
* @param source1 - The first object that specifies the default values to apply.
* @param source2 - The second object that specifies the default values to apply.
* @param source3 - The third object that specifies the default values to apply.
* @param source4 - The fourth object that specifies the default values to apply.
* @returns The `object` that has been updated with default values from `source1`, `source2`, `source3`, and `source4`.
*
* @example
* defaults({ a: 1 }, { b: 2 }, { c: 3 }, { d: 4 }, { e: 5 }); // { a: 1, b: 2, c: 3, d: 4, e: 5 }
* defaults({ a: undefined }, { a: 1 }, { b: 2 }, { c: 3 }, { d: 4 }); // { a: 1, b: 2, c: 3, d: 4 }
*/
declare function defaults<T, S1, S2, S3, S4>(object: T, source1: S1, source2: S2, source3: S3, source4: S4): NonNullable<S4 & S3 & S2 & S1 & T>;
/**
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* @template T - The type of the object being processed.
* @param object - The target object that will receive default values.
* @returns The `object` that has been updated with default values.
*
* @example
* defaults({ a: 1 }); // { a: 1 }
* defaults({ a: undefined }); // { a: undefined }
*/
declare function defaults<T>(object: T): NonNullable<T>;
/**
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* @param object - The target object that will receive default values.
* @param sources - The objects that specify the default values to apply.
* @returns The `object` that has been updated with default values from `sources`.
*
* @example
* defaults({}, { a: 1 }, { b: 2 }); // { a: 1, b: 2 }
* defaults({ a: undefined }, { a: 1 }); // { a: 1 }
*/
declare function defaults(object: any, ...sources: any[]): any;
//#endregion
export { defaults };

View file

@ -0,0 +1,101 @@
//#region src/compat/object/defaults.d.ts
/**
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* @template T - The type of the object being processed.
* @template S - The type of the object that provides default values.
* @param object - The target object that will receive default values.
* @param source - The object that specifies the default values to apply.
* @returns The `object` that has been updated with default values from `source`.
*
* @example
* defaults({ a: 1 }, { b: 2 }); // { a: 1, b: 2 }
* defaults({ a: undefined }, { a: 1 }); // { a: 1 }
*/
declare function defaults<T, S>(object: T, source: S): NonNullable<S & T>;
/**
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* @template T - The type of the object being processed.
* @template S1 - The type of the first object that provides default values.
* @template S2 - The type of the second object that provides default values.
* @param object - The target object that will receive default values.
* @param source1 - The first object that specifies the default values to apply.
* @param source2 - The second object that specifies the default values to apply.
* @returns The `object` that has been updated with default values from `source1` and `source2`.
*
* @example
* defaults({ a: 1 }, { b: 2 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
* defaults({ a: undefined }, { a: 1 }, { b: 2 }); // { a: 1, b: 2 }
*/
declare function defaults<T, S1, S2>(object: T, source1: S1, source2: S2): NonNullable<S2 & S1 & T>;
/**
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* @template T - The type of the object being processed.
* @template S1 - The type of the first object that provides default values.
* @template S2 - The type of the second object that provides default values.
* @template S3 - The type of the third object that provides default values.
* @param object - The target object that will receive default values.
* @param source1 - The first object that specifies the default values to apply.
* @param source2 - The second object that specifies the default values to apply.
* @param source3 - The third object that specifies the default values to apply.
* @returns The `object` that has been updated with default values from `source1`, `source2`, and `source3`.
*
* @example
* defaults({ a: 1 }, { b: 2 }, { c: 3 }, { d: 4 }); // { a: 1, b: 2, c: 3, d: 4 }
* defaults({ a: undefined }, { a: 1 }, { b: 2 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
*/
declare function defaults<T, S1, S2, S3>(object: T, source1: S1, source2: S2, source3: S3): NonNullable<S3 & S2 & S1 & T>;
/**
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* @template T - The type of the object being processed.
* @template S1 - The type of the first object that provides default values.
* @template S2 - The type of the second object that provides default values.
* @template S3 - The type of the third object that provides default values.
* @template S4 - The type of the fourth object that provides default values.
* @param object - The target object that will receive default values.
* @param source1 - The first object that specifies the default values to apply.
* @param source2 - The second object that specifies the default values to apply.
* @param source3 - The third object that specifies the default values to apply.
* @param source4 - The fourth object that specifies the default values to apply.
* @returns The `object` that has been updated with default values from `source1`, `source2`, `source3`, and `source4`.
*
* @example
* defaults({ a: 1 }, { b: 2 }, { c: 3 }, { d: 4 }, { e: 5 }); // { a: 1, b: 2, c: 3, d: 4, e: 5 }
* defaults({ a: undefined }, { a: 1 }, { b: 2 }, { c: 3 }, { d: 4 }); // { a: 1, b: 2, c: 3, d: 4 }
*/
declare function defaults<T, S1, S2, S3, S4>(object: T, source1: S1, source2: S2, source3: S3, source4: S4): NonNullable<S4 & S3 & S2 & S1 & T>;
/**
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* @template T - The type of the object being processed.
* @param object - The target object that will receive default values.
* @returns The `object` that has been updated with default values.
*
* @example
* defaults({ a: 1 }); // { a: 1 }
* defaults({ a: undefined }); // { a: undefined }
*/
declare function defaults<T>(object: T): NonNullable<T>;
/**
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* @param object - The target object that will receive default values.
* @param sources - The objects that specify the default values to apply.
* @returns The `object` that has been updated with default values from `sources`.
*
* @example
* defaults({}, { a: 1 }, { b: 2 }); // { a: 1, b: 2 }
* defaults({ a: undefined }, { a: 1 }); // { a: 1 }
*/
declare function defaults(object: any, ...sources: any[]): any;
//#endregion
export { defaults };

View file

@ -0,0 +1,47 @@
const require_isEqualsSameValueZero = require("../../_internal/isEqualsSameValueZero.js");
require("../util/eq.js");
const require_isNil = require("../../predicate/isNil.js");
const require_isIterateeCall = require("../_internal/isIterateeCall.js");
//#region src/compat/object/defaults.ts
/**
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* You can pass in multiple objects to define these default values,
* and they will be applied in order from left to right.
* Once a property has been assigned a value, any subsequent values for that property will be ignored.
*
* Note: This function modifies the first argument, `object`. If you want to keep `object` unchanged, consider using `toDefaulted` instead.
*
* @template T - The type of the object being processed.
* @template S - The type of the objects that provides default values.
* @param object - The target object that will receive default values.
* @param source - The objects that specifies the default values to apply.
* @returns The `object` that has been updated with default values from `sources`, ensuring that all properties are defined and none are left as `undefined`.
*
* @example
* defaults({ a: 1 }, { a: 2, b: 2 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
* defaults({ a: 1, b: 2 }, { b: 3 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
* defaults({ a: null }, { a: 1 }); // { a: null }
* defaults({ a: undefined }, { a: 1 }); // { a: 1 }
*/
function defaults(object, ...sources) {
object = Object(object);
const objectProto = Object.prototype;
let length = sources.length;
const guard = length > 2 ? sources[2] : void 0;
if (guard && require_isIterateeCall.isIterateeCall(sources[0], sources[1], guard)) length = 1;
for (let i = 0; i < length; i++) {
if (require_isNil.isNil(sources[i])) continue;
const source = sources[i];
const keys = Object.keys(source);
for (let j = 0; j < keys.length; j++) {
const key = keys[j];
const value = object[key];
if (value === void 0 || !Object.hasOwn(object, key) && require_isEqualsSameValueZero.isEqualsSameValueZero(value, objectProto[key])) object[key] = source[key];
}
}
return object;
}
//#endregion
exports.defaults = defaults;

View file

@ -0,0 +1,47 @@
import { isEqualsSameValueZero } from "../../_internal/isEqualsSameValueZero.mjs";
import "../util/eq.mjs";
import { isNil } from "../../predicate/isNil.mjs";
import { isIterateeCall } from "../_internal/isIterateeCall.mjs";
//#region src/compat/object/defaults.ts
/**
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* You can pass in multiple objects to define these default values,
* and they will be applied in order from left to right.
* Once a property has been assigned a value, any subsequent values for that property will be ignored.
*
* Note: This function modifies the first argument, `object`. If you want to keep `object` unchanged, consider using `toDefaulted` instead.
*
* @template T - The type of the object being processed.
* @template S - The type of the objects that provides default values.
* @param object - The target object that will receive default values.
* @param source - The objects that specifies the default values to apply.
* @returns The `object` that has been updated with default values from `sources`, ensuring that all properties are defined and none are left as `undefined`.
*
* @example
* defaults({ a: 1 }, { a: 2, b: 2 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
* defaults({ a: 1, b: 2 }, { b: 3 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
* defaults({ a: null }, { a: 1 }); // { a: null }
* defaults({ a: undefined }, { a: 1 }); // { a: 1 }
*/
function defaults(object, ...sources) {
object = Object(object);
const objectProto = Object.prototype;
let length = sources.length;
const guard = length > 2 ? sources[2] : void 0;
if (guard && isIterateeCall(sources[0], sources[1], guard)) length = 1;
for (let i = 0; i < length; i++) {
if (isNil(sources[i])) continue;
const source = sources[i];
const keys = Object.keys(source);
for (let j = 0; j < keys.length; j++) {
const key = keys[j];
const value = object[key];
if (value === void 0 || !Object.hasOwn(object, key) && isEqualsSameValueZero(value, objectProto[key])) object[key] = source[key];
}
}
return object;
}
//#endregion
export { defaults };

View file

@ -0,0 +1,24 @@
//#region src/compat/object/defaultsDeep.d.ts
/**
* Recursively assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* Similar to `defaults` but recursively applies default values to nested objects.
* Source objects are applied in order from left to right, and once a property has been assigned a value,
* any subsequent values for that property will be ignored.
*
* Note: This function modifies the first argument, `object`.
*
* @template T - The type of the object being processed.
* @param target - The target object that will receive default values.
* @param sources - One or more source objects that specify default values to apply.
* @returns The `object` that has been updated with default values from all sources, recursively merging nested objects.
*
* @example
* defaultsDeep({ a: { b: 2 } }, { a: { b: 3, c: 3 }, d: 4 }); // { a: { b: 2, c: 3 }, d: 4 }
* defaultsDeep({ a: { b: undefined } }, { a: { b: 1 } }); // { a: { b: 1 } }
* defaultsDeep({ a: null }, { a: { b: 1 } }); // { a: null }
*/
declare function defaultsDeep(target: any, ...sources: any[]): any;
//#endregion
export { defaultsDeep };

View file

@ -0,0 +1,24 @@
//#region src/compat/object/defaultsDeep.d.ts
/**
* Recursively assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* Similar to `defaults` but recursively applies default values to nested objects.
* Source objects are applied in order from left to right, and once a property has been assigned a value,
* any subsequent values for that property will be ignored.
*
* Note: This function modifies the first argument, `object`.
*
* @template T - The type of the object being processed.
* @param target - The target object that will receive default values.
* @param sources - One or more source objects that specify default values to apply.
* @returns The `object` that has been updated with default values from all sources, recursively merging nested objects.
*
* @example
* defaultsDeep({ a: { b: 2 } }, { a: { b: 3, c: 3 }, d: 4 }); // { a: { b: 2, c: 3 }, d: 4 }
* defaultsDeep({ a: { b: undefined } }, { a: { b: 1 } }); // { a: { b: 1 } }
* defaultsDeep({ a: null }, { a: { b: 1 } }); // { a: null }
*/
declare function defaultsDeep(target: any, ...sources: any[]): any;
//#endregion
export { defaultsDeep };

View file

@ -0,0 +1,70 @@
const require_isPlainObject = require("../predicate/isPlainObject.js");
//#region src/compat/object/defaultsDeep.ts
/**
* Recursively assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* Similar to `defaults` but recursively applies default values to nested objects.
* Source objects are applied in order from left to right, and once a property has been assigned a value,
* any subsequent values for that property will be ignored.
*
* Note: This function modifies the first argument, `object`.
*
* @template T - The type of the object being processed.
* @param target - The target object that will receive default values.
* @param sources - One or more source objects that specify default values to apply.
* @returns The `object` that has been updated with default values from all sources, recursively merging nested objects.
*
* @example
* defaultsDeep({ a: { b: 2 } }, { a: { b: 3, c: 3 }, d: 4 }); // { a: { b: 2, c: 3 }, d: 4 }
* defaultsDeep({ a: { b: undefined } }, { a: { b: 1 } }); // { a: { b: 1 } }
* defaultsDeep({ a: null }, { a: { b: 1 } }); // { a: null }
*/
function defaultsDeep(target, ...sources) {
target = Object(target);
for (let i = 0; i < sources.length; i++) {
const source = sources[i];
if (source != null) defaultsDeepRecursive(target, source, /* @__PURE__ */ new WeakMap());
}
return target;
}
function defaultsDeepRecursive(target, source, stack) {
for (const key in source) {
const sourceValue = source[key];
const targetValue = target[key];
if (targetValue === void 0 || !Object.hasOwn(target, key)) {
target[key] = handleMissingProperty(sourceValue, stack);
continue;
}
if (stack.get(sourceValue) === targetValue) continue;
handleExistingProperty(targetValue, sourceValue, stack);
}
}
function handleMissingProperty(sourceValue, stack) {
if (stack.has(sourceValue)) return stack.get(sourceValue);
if (require_isPlainObject.isPlainObject(sourceValue)) {
const newObj = {};
stack.set(sourceValue, newObj);
defaultsDeepRecursive(newObj, sourceValue, stack);
return newObj;
}
return sourceValue;
}
function handleExistingProperty(targetValue, sourceValue, stack) {
if (require_isPlainObject.isPlainObject(targetValue) && require_isPlainObject.isPlainObject(sourceValue)) {
stack.set(sourceValue, targetValue);
defaultsDeepRecursive(targetValue, sourceValue, stack);
return;
}
if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
stack.set(sourceValue, targetValue);
mergeArrays(targetValue, sourceValue, stack);
}
}
function mergeArrays(targetArray, sourceArray, stack) {
const minLength = Math.min(sourceArray.length, targetArray.length);
for (let i = 0; i < minLength; i++) if (require_isPlainObject.isPlainObject(targetArray[i]) && require_isPlainObject.isPlainObject(sourceArray[i])) defaultsDeepRecursive(targetArray[i], sourceArray[i], stack);
for (let i = minLength; i < sourceArray.length; i++) targetArray.push(sourceArray[i]);
}
//#endregion
exports.defaultsDeep = defaultsDeep;

View file

@ -0,0 +1,70 @@
import { isPlainObject } from "../predicate/isPlainObject.mjs";
//#region src/compat/object/defaultsDeep.ts
/**
* Recursively assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
*
* Similar to `defaults` but recursively applies default values to nested objects.
* Source objects are applied in order from left to right, and once a property has been assigned a value,
* any subsequent values for that property will be ignored.
*
* Note: This function modifies the first argument, `object`.
*
* @template T - The type of the object being processed.
* @param target - The target object that will receive default values.
* @param sources - One or more source objects that specify default values to apply.
* @returns The `object` that has been updated with default values from all sources, recursively merging nested objects.
*
* @example
* defaultsDeep({ a: { b: 2 } }, { a: { b: 3, c: 3 }, d: 4 }); // { a: { b: 2, c: 3 }, d: 4 }
* defaultsDeep({ a: { b: undefined } }, { a: { b: 1 } }); // { a: { b: 1 } }
* defaultsDeep({ a: null }, { a: { b: 1 } }); // { a: null }
*/
function defaultsDeep(target, ...sources) {
target = Object(target);
for (let i = 0; i < sources.length; i++) {
const source = sources[i];
if (source != null) defaultsDeepRecursive(target, source, /* @__PURE__ */ new WeakMap());
}
return target;
}
function defaultsDeepRecursive(target, source, stack) {
for (const key in source) {
const sourceValue = source[key];
const targetValue = target[key];
if (targetValue === void 0 || !Object.hasOwn(target, key)) {
target[key] = handleMissingProperty(sourceValue, stack);
continue;
}
if (stack.get(sourceValue) === targetValue) continue;
handleExistingProperty(targetValue, sourceValue, stack);
}
}
function handleMissingProperty(sourceValue, stack) {
if (stack.has(sourceValue)) return stack.get(sourceValue);
if (isPlainObject(sourceValue)) {
const newObj = {};
stack.set(sourceValue, newObj);
defaultsDeepRecursive(newObj, sourceValue, stack);
return newObj;
}
return sourceValue;
}
function handleExistingProperty(targetValue, sourceValue, stack) {
if (isPlainObject(targetValue) && isPlainObject(sourceValue)) {
stack.set(sourceValue, targetValue);
defaultsDeepRecursive(targetValue, sourceValue, stack);
return;
}
if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
stack.set(sourceValue, targetValue);
mergeArrays(targetValue, sourceValue, stack);
}
}
function mergeArrays(targetArray, sourceArray, stack) {
const minLength = Math.min(sourceArray.length, targetArray.length);
for (let i = 0; i < minLength; i++) if (isPlainObject(targetArray[i]) && isPlainObject(sourceArray[i])) defaultsDeepRecursive(targetArray[i], sourceArray[i], stack);
for (let i = minLength; i < sourceArray.length; i++) targetArray.push(sourceArray[i]);
}
//#endregion
export { defaultsDeep };

View file

@ -0,0 +1 @@
import { assignIn } from "./assignIn.mjs";

View file

@ -0,0 +1 @@
import { assignIn } from "./assignIn.js";

View file

@ -0,0 +1 @@
require("./assignIn.js");

View file

@ -0,0 +1 @@
import "./assignIn.mjs";

View file

@ -0,0 +1 @@
import { assignInWith } from "./assignInWith.mjs";

View file

@ -0,0 +1 @@
import { assignInWith } from "./assignInWith.js";

View file

@ -0,0 +1 @@
require("./assignInWith.js");

View file

@ -0,0 +1 @@
import "./assignInWith.mjs";

View file

@ -0,0 +1,18 @@
import { ObjectIteratee } from "../_internal/ObjectIteratee.mjs";
//#region src/compat/object/findKey.d.ts
/**
* Finds the key of the first element that matches the given predicate.
*
* This function determines the type of the predicate and delegates the search
* to the appropriate helper function. It supports predicates as functions, objects,
* arrays, or strings.
*
* @template T - The type of the object.
* @param obj - The object to inspect.
* @param predicate - The predicate to match.
* @returns Returns the key of the matched element, else `undefined`.
*/
declare function findKey<T>(obj: T | null | undefined, predicate?: ObjectIteratee<T>): string | undefined;
//#endregion
export { findKey };

View file

@ -0,0 +1,18 @@
import { ObjectIteratee } from "../_internal/ObjectIteratee.js";
//#region src/compat/object/findKey.d.ts
/**
* Finds the key of the first element that matches the given predicate.
*
* This function determines the type of the predicate and delegates the search
* to the appropriate helper function. It supports predicates as functions, objects,
* arrays, or strings.
*
* @template T - The type of the object.
* @param obj - The object to inspect.
* @param predicate - The predicate to match.
* @returns Returns the key of the matched element, else `undefined`.
*/
declare function findKey<T>(obj: T | null | undefined, predicate?: ObjectIteratee<T>): string | undefined;
//#endregion
export { findKey };

View file

@ -0,0 +1,24 @@
const require_findKey = require("../../object/findKey.js");
const require_isObject = require("../predicate/isObject.js");
const require_iteratee = require("../util/iteratee.js");
const require_identity = require("../function/identity.js");
//#region src/compat/object/findKey.ts
/**
* Finds the key of the first element that matches the given predicate.
*
* This function determines the type of the predicate and delegates the search
* to the appropriate helper function. It supports predicates as functions, objects,
* arrays, or strings.
*
* @template T - The type of the object.
* @param obj - The object to inspect.
* @param predicate - The predicate to match.
* @returns Returns the key of the matched element, else `undefined`.
*/
function findKey(obj, predicate) {
if (!require_isObject.isObject(obj)) return;
const iteratee$1 = require_iteratee.iteratee(predicate ?? require_identity.identity);
return require_findKey.findKey(obj, iteratee$1);
}
//#endregion
exports.findKey = findKey;

View file

@ -0,0 +1,23 @@
import { findKey as findKey$1 } from "../../object/findKey.mjs";
import { isObject } from "../predicate/isObject.mjs";
import { iteratee } from "../util/iteratee.mjs";
import { identity } from "../function/identity.mjs";
//#region src/compat/object/findKey.ts
/**
* Finds the key of the first element that matches the given predicate.
*
* This function determines the type of the predicate and delegates the search
* to the appropriate helper function. It supports predicates as functions, objects,
* arrays, or strings.
*
* @template T - The type of the object.
* @param obj - The object to inspect.
* @param predicate - The predicate to match.
* @returns Returns the key of the matched element, else `undefined`.
*/
function findKey(obj, predicate) {
if (!isObject(obj)) return;
return findKey$1(obj, iteratee(predicate ?? identity));
}
//#endregion
export { findKey };

View file

@ -0,0 +1,18 @@
import { ObjectIteratee } from "../_internal/ObjectIteratee.mjs";
//#region src/compat/object/findLastKey.d.ts
/**
* Finds the key of the last element that matches the given predicate.
*
* This function determines the type of the predicate and delegates the search
* to the appropriate helper function. It supports predicates as functions, objects,
* arrays, or strings.
*
* @template T - The type of the object.
* @param obj - The object to inspect.
* @param predicate - The predicate to match.
* @returns Returns the key of the matched element, else `undefined`.
*/
declare function findLastKey<T>(obj: T | null | undefined, predicate?: ObjectIteratee<T>): string | undefined;
//#endregion
export { findLastKey };

View file

@ -0,0 +1,18 @@
import { ObjectIteratee } from "../_internal/ObjectIteratee.js";
//#region src/compat/object/findLastKey.d.ts
/**
* Finds the key of the last element that matches the given predicate.
*
* This function determines the type of the predicate and delegates the search
* to the appropriate helper function. It supports predicates as functions, objects,
* arrays, or strings.
*
* @template T - The type of the object.
* @param obj - The object to inspect.
* @param predicate - The predicate to match.
* @returns Returns the key of the matched element, else `undefined`.
*/
declare function findLastKey<T>(obj: T | null | undefined, predicate?: ObjectIteratee<T>): string | undefined;
//#endregion
export { findLastKey };

View file

@ -0,0 +1,23 @@
const require_isObject = require("../predicate/isObject.js");
const require_iteratee = require("../util/iteratee.js");
const require_identity = require("../function/identity.js");
//#region src/compat/object/findLastKey.ts
/**
* Finds the key of the last element that matches the given predicate.
*
* This function determines the type of the predicate and delegates the search
* to the appropriate helper function. It supports predicates as functions, objects,
* arrays, or strings.
*
* @template T - The type of the object.
* @param obj - The object to inspect.
* @param predicate - The predicate to match.
* @returns Returns the key of the matched element, else `undefined`.
*/
function findLastKey(obj, predicate) {
if (!require_isObject.isObject(obj)) return;
const iteratee$1 = require_iteratee.iteratee(predicate ?? require_identity.identity);
return Object.keys(obj).findLast((key) => iteratee$1(obj[key], key, obj));
}
//#endregion
exports.findLastKey = findLastKey;

View file

@ -0,0 +1,23 @@
import { isObject } from "../predicate/isObject.mjs";
import { iteratee } from "../util/iteratee.mjs";
import { identity } from "../function/identity.mjs";
//#region src/compat/object/findLastKey.ts
/**
* Finds the key of the last element that matches the given predicate.
*
* This function determines the type of the predicate and delegates the search
* to the appropriate helper function. It supports predicates as functions, objects,
* arrays, or strings.
*
* @template T - The type of the object.
* @param obj - The object to inspect.
* @param predicate - The predicate to match.
* @returns Returns the key of the matched element, else `undefined`.
*/
function findLastKey(obj, predicate) {
if (!isObject(obj)) return;
const iteratee$1 = iteratee(predicate ?? identity);
return Object.keys(obj).findLast((key) => iteratee$1(obj[key], key, obj));
}
//#endregion
export { findLastKey };

View file

@ -0,0 +1,59 @@
//#region src/compat/object/forIn.d.ts
/**
* Iterates over an object and invokes the `iteratee` function for each property.
*
* Iterates over string keyed properties including inherited properties.
*
* The iteration is terminated early if the `iteratee` function returns `false`.
*
* @template T - The type of the object
* @param object - The object to iterate over
* @param iteratee - The function invoked per iteration
* @returns Returns the object
*
* @example
* // Iterate over all properties including inherited ones
* const obj = { a: 1, b: 2 };
* forIn(obj, (value, key) => {
* console.log(key, value);
* });
* // Output: 'a' 1, 'b' 2
*
* // Early termination
* forIn(obj, (value, key) => {
* console.log(key, value);
* return key !== 'a'; // stop after 'a'
* });
* // Output: 'a' 1
*/
declare function forIn<T>(object: T, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T;
/**
* Iterates over an object and invokes the `iteratee` function for each property.
*
* Iterates over string keyed properties including inherited properties.
*
* The iteration is terminated early if the `iteratee` function returns `false`.
*
* @template T - The type of the object
* @param object - The object to iterate over
* @param iteratee - The function invoked per iteration
* @returns Returns the object
*
* @example
* // Iterate over all properties including inherited ones
* const obj = { a: 1, b: 2 };
* forIn(obj, (value, key) => {
* console.log(key, value);
* });
* // Output: 'a' 1, 'b' 2
*
* // Early termination
* forIn(obj, (value, key) => {
* console.log(key, value);
* return key !== 'a'; // stop after 'a'
* });
* // Output: 'a' 1
*/
declare function forIn<T>(object: T | null | undefined, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T | null | undefined;
//#endregion
export { forIn };

View file

@ -0,0 +1,59 @@
//#region src/compat/object/forIn.d.ts
/**
* Iterates over an object and invokes the `iteratee` function for each property.
*
* Iterates over string keyed properties including inherited properties.
*
* The iteration is terminated early if the `iteratee` function returns `false`.
*
* @template T - The type of the object
* @param object - The object to iterate over
* @param iteratee - The function invoked per iteration
* @returns Returns the object
*
* @example
* // Iterate over all properties including inherited ones
* const obj = { a: 1, b: 2 };
* forIn(obj, (value, key) => {
* console.log(key, value);
* });
* // Output: 'a' 1, 'b' 2
*
* // Early termination
* forIn(obj, (value, key) => {
* console.log(key, value);
* return key !== 'a'; // stop after 'a'
* });
* // Output: 'a' 1
*/
declare function forIn<T>(object: T, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T;
/**
* Iterates over an object and invokes the `iteratee` function for each property.
*
* Iterates over string keyed properties including inherited properties.
*
* The iteration is terminated early if the `iteratee` function returns `false`.
*
* @template T - The type of the object
* @param object - The object to iterate over
* @param iteratee - The function invoked per iteration
* @returns Returns the object
*
* @example
* // Iterate over all properties including inherited ones
* const obj = { a: 1, b: 2 };
* forIn(obj, (value, key) => {
* console.log(key, value);
* });
* // Output: 'a' 1, 'b' 2
*
* // Early termination
* forIn(obj, (value, key) => {
* console.log(key, value);
* return key !== 'a'; // stop after 'a'
* });
* // Output: 'a' 1
*/
declare function forIn<T>(object: T | null | undefined, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T | null | undefined;
//#endregion
export { forIn };

View file

@ -0,0 +1,36 @@
const require_identity = require("../../function/identity.js");
//#region src/compat/object/forIn.ts
/**
* Iterates over an object and invokes the `iteratee` function for each property.
*
* Iterates over string keyed properties including inherited properties.
*
* The iteration is terminated early if the `iteratee` function returns `false`.
*
* @template T - The type of the object
* @param object - The object to iterate over
* @param iteratee - The function invoked per iteration
* @returns Returns the object
*
* @example
* // Iterate over all properties including inherited ones
* const obj = { a: 1, b: 2 };
* forIn(obj, (value, key) => {
* console.log(key, value);
* });
* // Output: 'a' 1, 'b' 2
*
* // Early termination
* forIn(obj, (value, key) => {
* console.log(key, value);
* return key !== 'a'; // stop after 'a'
* });
* // Output: 'a' 1
*/
function forIn(object, iteratee = require_identity.identity) {
if (object == null) return object;
for (const key in object) if (iteratee(object[key], key, object) === false) break;
return object;
}
//#endregion
exports.forIn = forIn;

View file

@ -0,0 +1,36 @@
import { identity } from "../../function/identity.mjs";
//#region src/compat/object/forIn.ts
/**
* Iterates over an object and invokes the `iteratee` function for each property.
*
* Iterates over string keyed properties including inherited properties.
*
* The iteration is terminated early if the `iteratee` function returns `false`.
*
* @template T - The type of the object
* @param object - The object to iterate over
* @param iteratee - The function invoked per iteration
* @returns Returns the object
*
* @example
* // Iterate over all properties including inherited ones
* const obj = { a: 1, b: 2 };
* forIn(obj, (value, key) => {
* console.log(key, value);
* });
* // Output: 'a' 1, 'b' 2
*
* // Early termination
* forIn(obj, (value, key) => {
* console.log(key, value);
* return key !== 'a'; // stop after 'a'
* });
* // Output: 'a' 1
*/
function forIn(object, iteratee = identity) {
if (object == null) return object;
for (const key in object) if (iteratee(object[key], key, object) === false) break;
return object;
}
//#endregion
export { forIn };

View file

@ -0,0 +1,59 @@
//#region src/compat/object/forInRight.d.ts
/**
* Iterates over an object in reverse order and invokes the `iteratee` function for each property.
*
* Iterates over string keyed properties including inherited properties in reverse order.
*
* The iteration is terminated early if the `iteratee` function returns `false`.
*
* @template T - The type of the object
* @param object - The object to iterate over
* @param iteratee - The function invoked per iteration
* @returns Returns the object
*
* @example
* // Iterate over all properties including inherited ones
* const obj = { a: 1, b: 2 };
* forInRight(obj, (value, key) => {
* console.log(key, value);
* });
* // Output: 'b' 2, 'a' 1
*
* // Early termination
* forInRight(obj, (value, key) => {
* console.log(key, value);
* return key !== 'a'; // stop after 'a'
* });
* // Output: 'b' 2
*/
declare function forInRight<T>(object: T, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T;
/**
* Iterates over an object in reverse order and invokes the `iteratee` function for each property.
*
* Iterates over string keyed properties including inherited properties in reverse order.
*
* The iteration is terminated early if the `iteratee` function returns `false`.
*
* @template T - The type of the object
* @param object - The object to iterate over
* @param iteratee - The function invoked per iteration
* @returns Returns the object
*
* @example
* // Iterate over all properties including inherited ones
* const obj = { a: 1, b: 2 };
* forInRight(obj, (value, key) => {
* console.log(key, value);
* });
* // Output: 'b' 2, 'a' 1
*
* // Early termination
* forInRight(obj, (value, key) => {
* console.log(key, value);
* return key !== 'a'; // stop after 'a'
* });
* // Output: 'b' 2
*/
declare function forInRight<T>(object: T | null | undefined, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T | null | undefined;
//#endregion
export { forInRight };

View file

@ -0,0 +1,59 @@
//#region src/compat/object/forInRight.d.ts
/**
* Iterates over an object in reverse order and invokes the `iteratee` function for each property.
*
* Iterates over string keyed properties including inherited properties in reverse order.
*
* The iteration is terminated early if the `iteratee` function returns `false`.
*
* @template T - The type of the object
* @param object - The object to iterate over
* @param iteratee - The function invoked per iteration
* @returns Returns the object
*
* @example
* // Iterate over all properties including inherited ones
* const obj = { a: 1, b: 2 };
* forInRight(obj, (value, key) => {
* console.log(key, value);
* });
* // Output: 'b' 2, 'a' 1
*
* // Early termination
* forInRight(obj, (value, key) => {
* console.log(key, value);
* return key !== 'a'; // stop after 'a'
* });
* // Output: 'b' 2
*/
declare function forInRight<T>(object: T, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T;
/**
* Iterates over an object in reverse order and invokes the `iteratee` function for each property.
*
* Iterates over string keyed properties including inherited properties in reverse order.
*
* The iteration is terminated early if the `iteratee` function returns `false`.
*
* @template T - The type of the object
* @param object - The object to iterate over
* @param iteratee - The function invoked per iteration
* @returns Returns the object
*
* @example
* // Iterate over all properties including inherited ones
* const obj = { a: 1, b: 2 };
* forInRight(obj, (value, key) => {
* console.log(key, value);
* });
* // Output: 'b' 2, 'a' 1
*
* // Early termination
* forInRight(obj, (value, key) => {
* console.log(key, value);
* return key !== 'a'; // stop after 'a'
* });
* // Output: 'b' 2
*/
declare function forInRight<T>(object: T | null | undefined, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T | null | undefined;
//#endregion
export { forInRight };

View file

@ -0,0 +1,41 @@
const require_identity = require("../../function/identity.js");
//#region src/compat/object/forInRight.ts
/**
* Iterates over an object in reverse order and invokes the `iteratee` function for each property.
*
* Iterates over string keyed properties including inherited properties in reverse order.
*
* The iteration is terminated early if the `iteratee` function returns `false`.
*
* @template T - The type of the object
* @param object - The object to iterate over
* @param iteratee - The function invoked per iteration
* @returns Returns the object
*
* @example
* // Iterate over all properties including inherited ones
* const obj = { a: 1, b: 2 };
* forInRight(obj, (value, key) => {
* console.log(key, value);
* });
* // Output: 'b' 2, 'a' 1
*
* // Early termination
* forInRight(obj, (value, key) => {
* console.log(key, value);
* return key !== 'a'; // stop after 'a'
* });
* // Output: 'b' 2
*/
function forInRight(object, iteratee = require_identity.identity) {
if (object == null) return object;
const keys = [];
for (const key in object) keys.push(key);
for (let i = keys.length - 1; i >= 0; i--) {
const key = keys[i];
if (iteratee(object[key], key, object) === false) break;
}
return object;
}
//#endregion
exports.forInRight = forInRight;

View file

@ -0,0 +1,41 @@
import { identity } from "../../function/identity.mjs";
//#region src/compat/object/forInRight.ts
/**
* Iterates over an object in reverse order and invokes the `iteratee` function for each property.
*
* Iterates over string keyed properties including inherited properties in reverse order.
*
* The iteration is terminated early if the `iteratee` function returns `false`.
*
* @template T - The type of the object
* @param object - The object to iterate over
* @param iteratee - The function invoked per iteration
* @returns Returns the object
*
* @example
* // Iterate over all properties including inherited ones
* const obj = { a: 1, b: 2 };
* forInRight(obj, (value, key) => {
* console.log(key, value);
* });
* // Output: 'b' 2, 'a' 1
*
* // Early termination
* forInRight(obj, (value, key) => {
* console.log(key, value);
* return key !== 'a'; // stop after 'a'
* });
* // Output: 'b' 2
*/
function forInRight(object, iteratee = identity) {
if (object == null) return object;
const keys = [];
for (const key in object) keys.push(key);
for (let i = keys.length - 1; i >= 0; i--) {
const key = keys[i];
if (iteratee(object[key], key, object) === false) break;
}
return object;
}
//#endregion
export { forInRight };

View file

@ -0,0 +1,55 @@
//#region src/compat/object/forOwn.d.ts
/**
* Iterates over an object's properties and calls the `iteratee` function for each property.
*
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
*
* The `iteratee` function can terminate the iteration early by returning `false`.
*
* @template T - The type of the object.
* @param object The object to iterate over.
* @param [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
* @return {T} Returns object.
*
* @example
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* forOwn(new Foo(), function(value, key) {
* console.log(key);
* });
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
*/
declare function forOwn<T>(object: T, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T;
/**
* Iterates over an object's properties and calls the `iteratee` function for each property.
*
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
*
* The `iteratee` function can terminate the iteration early by returning `false`.
*
* @template T - The type of the object.
* @param object The object to iterate over.
* @param [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
* @return {T | null | undefined} Returns object.
*
* @example
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* forOwn(new Foo(), function(value, key) {
* console.log(key);
* });
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
*/
declare function forOwn<T>(object: T | null | undefined, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T | null | undefined;
//#endregion
export { forOwn };

View file

@ -0,0 +1,55 @@
//#region src/compat/object/forOwn.d.ts
/**
* Iterates over an object's properties and calls the `iteratee` function for each property.
*
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
*
* The `iteratee` function can terminate the iteration early by returning `false`.
*
* @template T - The type of the object.
* @param object The object to iterate over.
* @param [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
* @return {T} Returns object.
*
* @example
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* forOwn(new Foo(), function(value, key) {
* console.log(key);
* });
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
*/
declare function forOwn<T>(object: T, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T;
/**
* Iterates over an object's properties and calls the `iteratee` function for each property.
*
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
*
* The `iteratee` function can terminate the iteration early by returning `false`.
*
* @template T - The type of the object.
* @param object The object to iterate over.
* @param [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
* @return {T | null | undefined} Returns object.
*
* @example
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* forOwn(new Foo(), function(value, key) {
* console.log(key);
* });
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
*/
declare function forOwn<T>(object: T | null | undefined, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T | null | undefined;
//#endregion
export { forOwn };

View file

@ -0,0 +1,40 @@
const require_identity = require("../../function/identity.js");
const require_keys = require("./keys.js");
//#region src/compat/object/forOwn.ts
/**
* Iterates over an object's properties and calls the `iteratee` function for each property.
*
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
*
* The `iteratee` function can terminate the iteration early by returning `false`.
*
* @template T - The type of the object.
* @param object The object to iterate over.
* @param [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
* @return {T | null | undefined} Returns object.
*
* @example
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* forOwn(new Foo(), function(value, key) {
* console.log(key);
* });
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
*/
function forOwn(object, iteratee = require_identity.identity) {
if (object == null) return object;
const iterable = Object(object);
const keys$1 = require_keys.keys(object);
for (let i = 0; i < keys$1.length; ++i) {
const key = keys$1[i];
if (iteratee(iterable[key], key, iterable) === false) break;
}
return object;
}
//#endregion
exports.forOwn = forOwn;

View file

@ -0,0 +1,40 @@
import { identity } from "../../function/identity.mjs";
import { keys } from "./keys.mjs";
//#region src/compat/object/forOwn.ts
/**
* Iterates over an object's properties and calls the `iteratee` function for each property.
*
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
*
* The `iteratee` function can terminate the iteration early by returning `false`.
*
* @template T - The type of the object.
* @param object The object to iterate over.
* @param [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
* @return {T | null | undefined} Returns object.
*
* @example
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* forOwn(new Foo(), function(value, key) {
* console.log(key);
* });
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
*/
function forOwn(object, iteratee = identity) {
if (object == null) return object;
const iterable = Object(object);
const keys$1 = keys(object);
for (let i = 0; i < keys$1.length; ++i) {
const key = keys$1[i];
if (iteratee(iterable[key], key, iterable) === false) break;
}
return object;
}
//#endregion
export { forOwn };

View file

@ -0,0 +1,55 @@
//#region src/compat/object/forOwnRight.d.ts
/**
* Iterates over an object's properties in reverse order and calls the `iteratee` function for each property.
*
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
*
* The `iteratee` function can terminate the iteration early by returning `false`.
*
* @template T - The type of the object.
* @param object The object to iterate over.
* @param [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
* @return {T} Returns object.
*
* @example
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* forOwnRight(new Foo(), function(value, key) {
* console.log(key);
* });
* // => Logs 'b' then 'a' (iteration order is not guaranteed).
*/
declare function forOwnRight<T>(object: T, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T;
/**
* Iterates over an object's properties in reverse order and calls the `iteratee` function for each property.
*
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
*
* The `iteratee` function can terminate the iteration early by returning `false`.
*
* @template T - The type of the object.
* @param object The object to iterate over.
* @param [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
* @return {T | null | undefined} Returns object.
*
* @example
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* forOwnRight(new Foo(), function(value, key) {
* console.log(key);
* });
* // => Logs 'b' then 'a' (iteration order is not guaranteed).
*/
declare function forOwnRight<T>(object: T | null | undefined, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T | null | undefined;
//#endregion
export { forOwnRight };

View file

@ -0,0 +1,55 @@
//#region src/compat/object/forOwnRight.d.ts
/**
* Iterates over an object's properties in reverse order and calls the `iteratee` function for each property.
*
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
*
* The `iteratee` function can terminate the iteration early by returning `false`.
*
* @template T - The type of the object.
* @param object The object to iterate over.
* @param [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
* @return {T} Returns object.
*
* @example
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* forOwnRight(new Foo(), function(value, key) {
* console.log(key);
* });
* // => Logs 'b' then 'a' (iteration order is not guaranteed).
*/
declare function forOwnRight<T>(object: T, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T;
/**
* Iterates over an object's properties in reverse order and calls the `iteratee` function for each property.
*
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
*
* The `iteratee` function can terminate the iteration early by returning `false`.
*
* @template T - The type of the object.
* @param object The object to iterate over.
* @param [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
* @return {T | null | undefined} Returns object.
*
* @example
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* forOwnRight(new Foo(), function(value, key) {
* console.log(key);
* });
* // => Logs 'b' then 'a' (iteration order is not guaranteed).
*/
declare function forOwnRight<T>(object: T | null | undefined, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T | null | undefined;
//#endregion
export { forOwnRight };

View file

@ -0,0 +1,40 @@
const require_identity = require("../../function/identity.js");
const require_keys = require("./keys.js");
//#region src/compat/object/forOwnRight.ts
/**
* Iterates over an object's properties in reverse order and calls the `iteratee` function for each property.
*
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
*
* The `iteratee` function can terminate the iteration early by returning `false`.
*
* @template T - The type of the object.
* @param object The object to iterate over.
* @param [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
* @return {T | null | undefined} Returns object.
*
* @example
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* forOwnRight(new Foo(), function(value, key) {
* console.log(key);
* });
* // => Logs 'b' then 'a' (iteration order is not guaranteed).
*/
function forOwnRight(object, iteratee = require_identity.identity) {
if (object == null) return object;
const iterable = Object(object);
const keys$1 = require_keys.keys(object);
for (let i = keys$1.length - 1; i >= 0; --i) {
const key = keys$1[i];
if (iteratee(iterable[key], key, iterable) === false) break;
}
return object;
}
//#endregion
exports.forOwnRight = forOwnRight;

View file

@ -0,0 +1,40 @@
import { identity } from "../../function/identity.mjs";
import { keys } from "./keys.mjs";
//#region src/compat/object/forOwnRight.ts
/**
* Iterates over an object's properties in reverse order and calls the `iteratee` function for each property.
*
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
*
* The `iteratee` function can terminate the iteration early by returning `false`.
*
* @template T - The type of the object.
* @param object The object to iterate over.
* @param [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
* @return {T | null | undefined} Returns object.
*
* @example
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* forOwnRight(new Foo(), function(value, key) {
* console.log(key);
* });
* // => Logs 'b' then 'a' (iteration order is not guaranteed).
*/
function forOwnRight(object, iteratee = identity) {
if (object == null) return object;
const iterable = Object(object);
const keys$1 = keys(object);
for (let i = keys$1.length - 1; i >= 0; --i) {
const key = keys$1[i];
if (iteratee(iterable[key], key, iterable) === false) break;
}
return object;
}
//#endregion
export { forOwnRight };

View file

@ -0,0 +1,29 @@
//#region src/compat/object/fromPairs.d.ts
type PropertyName = string | number | symbol;
/**
* Converts an array of key-value pairs into an object.
*
* @template T - The type of the values.
* @param pairs - An array of key-value pairs.
* @returns An object where keys are strings and values are of type T.
*
* @example
* const pairs = [['a', 1], ['b', 2]];
* const result = fromPairs(pairs);
* // => { a: 1, b: 2 }
*/
declare function fromPairs<T>(pairs: ArrayLike<[PropertyName, T]> | null | undefined): Record<string, T>;
/**
* Converts an array of key-value pairs into an object.
*
* @param pairs - An array of key-value pairs.
* @returns An object where keys are strings and values can be any type.
*
* @example
* const pairs = [['a', 1], ['b', 'hello']];
* const result = fromPairs(pairs);
* // => { a: 1, b: 'hello' }
*/
declare function fromPairs(pairs: ArrayLike<any[]> | null | undefined): Record<string, any>;
//#endregion
export { fromPairs };

View file

@ -0,0 +1,29 @@
//#region src/compat/object/fromPairs.d.ts
type PropertyName = string | number | symbol;
/**
* Converts an array of key-value pairs into an object.
*
* @template T - The type of the values.
* @param pairs - An array of key-value pairs.
* @returns An object where keys are strings and values are of type T.
*
* @example
* const pairs = [['a', 1], ['b', 2]];
* const result = fromPairs(pairs);
* // => { a: 1, b: 2 }
*/
declare function fromPairs<T>(pairs: ArrayLike<[PropertyName, T]> | null | undefined): Record<string, T>;
/**
* Converts an array of key-value pairs into an object.
*
* @param pairs - An array of key-value pairs.
* @returns An object where keys are strings and values can be any type.
*
* @example
* const pairs = [['a', 1], ['b', 'hello']];
* const result = fromPairs(pairs);
* // => { a: 1, b: 'hello' }
*/
declare function fromPairs(pairs: ArrayLike<any[]> | null | undefined): Record<string, any>;
//#endregion
export { fromPairs };

View file

@ -0,0 +1,27 @@
const require_isArrayLike = require("../predicate/isArrayLike.js");
//#region src/compat/object/fromPairs.ts
/**
* Converts an array of key-value pairs into an object.
*
* @template T - The type of the keys in the resulting object. It must extend `PropertyKey`.
* @template U - The type of the values in the resulting object.
*
* @param pairs - An array of key-value pairs where each key is a `PropertyKey` and each value is of type `U`.
* @returns An object where the keys are of type `T` and the values are of type `U`.
*
* @example
* const pairs = [['a', 1], ['b', 2]];
* const result = fromPairs(pairs);
* // result will be: { a: 1, b: 2 }
*/
function fromPairs(pairs) {
if (!require_isArrayLike.isArrayLike(pairs)) return {};
const result = {};
for (let i = 0; i < pairs.length; i++) {
const [key, value] = pairs[i];
result[key] = value;
}
return result;
}
//#endregion
exports.fromPairs = fromPairs;

View file

@ -0,0 +1,27 @@
import { isArrayLike } from "../predicate/isArrayLike.mjs";
//#region src/compat/object/fromPairs.ts
/**
* Converts an array of key-value pairs into an object.
*
* @template T - The type of the keys in the resulting object. It must extend `PropertyKey`.
* @template U - The type of the values in the resulting object.
*
* @param pairs - An array of key-value pairs where each key is a `PropertyKey` and each value is of type `U`.
* @returns An object where the keys are of type `T` and the values are of type `U`.
*
* @example
* const pairs = [['a', 1], ['b', 2]];
* const result = fromPairs(pairs);
* // result will be: { a: 1, b: 2 }
*/
function fromPairs(pairs) {
if (!isArrayLike(pairs)) return {};
const result = {};
for (let i = 0; i < pairs.length; i++) {
const [key, value] = pairs[i];
result[key] = value;
}
return result;
}
//#endregion
export { fromPairs };

View file

@ -0,0 +1,21 @@
//#region src/compat/object/functions.d.ts
/**
* Creates an array of property names from an object where the property values are functions.
*
* @param object - The object to inspect.
* @returns An array of function property names.
*
* @example
* function Foo() {
* this.a = () => 'a';
* this.b = () => 'b';
* }
*
* Foo.prototype.c = () => 'c';
*
* functions(new Foo);
* // => ['a', 'b']
*/
declare function functions(object: any): string[];
//#endregion
export { functions };

View file

@ -0,0 +1,21 @@
//#region src/compat/object/functions.d.ts
/**
* Creates an array of property names from an object where the property values are functions.
*
* @param object - The object to inspect.
* @returns An array of function property names.
*
* @example
* function Foo() {
* this.a = () => 'a';
* this.b = () => 'b';
* }
*
* Foo.prototype.c = () => 'c';
*
* functions(new Foo);
* // => ['a', 'b']
*/
declare function functions(object: any): string[];
//#endregion
export { functions };

View file

@ -0,0 +1,29 @@
const require_keys = require("./keys.js");
//#region src/compat/object/functions.ts
/**
* Creates an array of property names from an object where the property values are functions.
*
* Only checks for own properties with string keys. Inherited properties or
* properties with Symbol keys are not included.
*
* @param object The object to inspect.
* @returns An array of function property names.
*
* @example
*
* function Foo() {
* this.a = () => 'a'
* this.b = () => 'b'
* }
*
* Foo.prototype.c = () => 'c'
*
* functions(new Foo)
* // => ['a', 'b']
*/
function functions(object) {
if (object == null) return [];
return require_keys.keys(object).filter((key) => typeof object[key] === "function");
}
//#endregion
exports.functions = functions;

View file

@ -0,0 +1,29 @@
import { keys } from "./keys.mjs";
//#region src/compat/object/functions.ts
/**
* Creates an array of property names from an object where the property values are functions.
*
* Only checks for own properties with string keys. Inherited properties or
* properties with Symbol keys are not included.
*
* @param object The object to inspect.
* @returns An array of function property names.
*
* @example
*
* function Foo() {
* this.a = () => 'a'
* this.b = () => 'b'
* }
*
* Foo.prototype.c = () => 'c'
*
* functions(new Foo)
* // => ['a', 'b']
*/
function functions(object) {
if (object == null) return [];
return keys(object).filter((key) => typeof object[key] === "function");
}
//#endregion
export { functions };

View file

@ -0,0 +1,21 @@
//#region src/compat/object/functionsIn.d.ts
/**
* Returns an array of property names whose values are functions, including inherited properties.
*
* @param object The object to inspect.
* @returns Returns the function names.
* @example
*
* function Foo() {
* this.a = function() { return 'a'; };
* this.b = function() { return 'b'; };
* }
*
* Foo.prototype.c = function() { return 'c'; };
*
* functionsIn(new Foo);
* // => ['a', 'b', 'c']
*/
declare function functionsIn<T extends {}>(object: any): string[];
//#endregion
export { functionsIn };

View file

@ -0,0 +1,21 @@
//#region src/compat/object/functionsIn.d.ts
/**
* Returns an array of property names whose values are functions, including inherited properties.
*
* @param object The object to inspect.
* @returns Returns the function names.
* @example
*
* function Foo() {
* this.a = function() { return 'a'; };
* this.b = function() { return 'b'; };
* }
*
* Foo.prototype.c = function() { return 'c'; };
*
* functionsIn(new Foo);
* // => ['a', 'b', 'c']
*/
declare function functionsIn<T extends {}>(object: any): string[];
//#endregion
export { functionsIn };

View file

@ -0,0 +1,27 @@
const require_isFunction = require("../../predicate/isFunction.js");
//#region src/compat/object/functionsIn.ts
/**
* Returns an array of property names whose values are functions, including inherited properties.
*
* @param object The object to inspect.
* @returns Returns the function names.
* @example
*
* function Foo() {
* this.a = function() { return 'a'; };
* this.b = function() { return 'b'; };
* }
*
* Foo.prototype.c = function() { return 'c'; };
*
* functionsIn(new Foo);
* // => ['a', 'b', 'c']
*/
function functionsIn(object) {
if (object == null) return [];
const result = [];
for (const key in object) if (require_isFunction.isFunction(object[key])) result.push(key);
return result;
}
//#endregion
exports.functionsIn = functionsIn;

View file

@ -0,0 +1,27 @@
import { isFunction } from "../../predicate/isFunction.mjs";
//#region src/compat/object/functionsIn.ts
/**
* Returns an array of property names whose values are functions, including inherited properties.
*
* @param object The object to inspect.
* @returns Returns the function names.
* @example
*
* function Foo() {
* this.a = function() { return 'a'; };
* this.b = function() { return 'b'; };
* }
*
* Foo.prototype.c = function() { return 'c'; };
*
* functionsIn(new Foo);
* // => ['a', 'b', 'c']
*/
function functionsIn(object) {
if (object == null) return [];
const result = [];
for (const key in object) if (isFunction(object[key])) result.push(key);
return result;
}
//#endregion
export { functionsIn };

View file

@ -0,0 +1,328 @@
import { PropertyPath } from "../_internal/PropertyPath.mjs";
import { GetFieldType } from "../_internal/GetFieldType.mjs";
//#region src/compat/object/get.d.ts
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': [{ 'b': { 'c': 3 } }] };
* get(object, 'a[0].b.c');
* // => 3
*/
declare function get<TObject extends object, TKey extends keyof TObject>(object: TObject, path: TKey | [TKey]): TObject[TKey];
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': [{ 'b': { 'c': 3 } }] };
* get(object, 'a[0].b.c');
* // => 3
*/
declare function get<TObject extends object, TKey extends keyof TObject>(object: TObject | null | undefined, path: TKey | [TKey]): TObject[TKey] | undefined;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey
* @template TDefault
* @param object - The object to query.
* @param path - The path of the property to get.
* @param defaultValue - The value returned if the resolved value is undefined.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': [{ 'b': { 'c': 3 } }] };
* get(object, 'a[0].b.c', 'default');
* // => 3
*/
declare function get<TObject extends object, TKey extends keyof TObject, TDefault>(object: TObject | null | undefined, path: TKey | [TKey], defaultValue: TDefault): Exclude<TObject[TKey], undefined> | TDefault;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey1
* @template TKey2
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': 2 } };
* get(object, ['a', 'b']);
* // => 2
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1]>(object: TObject, path: [TKey1, TKey2]): TObject[TKey1][TKey2];
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey1
* @template TKey2
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': 2 } };
* get(object, ['a', 'b']);
* // => 2
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>>(object: TObject | null | undefined, path: [TKey1, TKey2]): NonNullable<TObject[TKey1]>[TKey2] | undefined;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey1
* @template TKey2
* @template TDefault
* @param object - The object to query.
* @param path - The path of the property to get.
* @param defaultValue - The value returned if the resolved value is undefined.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': 2 } };
* get(object, ['a', 'b'], 'default');
* // => 2
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2], defaultValue: TDefault): Exclude<NonNullable<TObject[TKey1]>[TKey2], undefined> | TDefault;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey1
* @template TKey2
* @template TKey3
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': { 'c': 3 } } };
* get(object, ['a', 'b', 'c']);
* // => 3
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1], TKey3 extends keyof TObject[TKey1][TKey2]>(object: TObject, path: [TKey1, TKey2, TKey3]): TObject[TKey1][TKey2][TKey3];
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey1
* @template TKey2
* @template TKey3
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': { 'c': 3 } } };
* get(object, ['a', 'b', 'c']);
* // => 3
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3]): NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3] | undefined;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey1
* @template TKey2
* @template TKey3
* @template TDefault
* @param object - The object to query.
* @param path - The path of the property to get.
* @param defaultValue - The value returned if the resolved value is undefined.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': { 'c': 3 } } };
* get(object, ['a', 'b', 'c'], 'default');
* // => 3
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3], defaultValue: TDefault): Exclude<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3], undefined> | TDefault;
/**
* Gets the value at path of object.
*
* @template TObject
* @template TKey1
* @template TKey2
* @template TKey3
* @template TKey4
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': { 'c': { 'd': 4 } } } };
* get(object, ['a', 'b', 'c', 'd']);
* // => 4
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1], TKey3 extends keyof TObject[TKey1][TKey2], TKey4 extends keyof TObject[TKey1][TKey2][TKey3]>(object: TObject, path: [TKey1, TKey2, TKey3, TKey4]): TObject[TKey1][TKey2][TKey3][TKey4];
/**
* Gets the value at path of object. If the resolved value is undefined, undefined is returned.
*
* @template TObject
* @template TKey1
* @template TKey2
* @template TKey3
* @template TKey4
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': { 'c': { 'd': 4 } } } };
* get(object, ['a', 'b', 'c', 'd']);
* // => 4
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TKey4 extends keyof NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3, TKey4]): NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>[TKey4] | undefined;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey1
* @template TKey2
* @template TKey3
* @template TKey4
* @template TDefault
* @param object - The object to query.
* @param path - The path of the property to get.
* @param defaultValue - The value returned if the resolved value is undefined.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': { 'c': { 'd': 4 } } } };
* get(object, ['a', 'b', 'c', 'd'], 'default');
* // => 4
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TKey4 extends keyof NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3, TKey4], defaultValue: TDefault): Exclude<NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>[TKey4], undefined> | TDefault;
/**
* Gets the value at path of object.
*
* @template T
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 0: 'a', 1: 'b', 2: 'c' };
* get(object, 1);
* // => 'b'
*/
declare function get<T>(object: Record<number, T>, path: number): T;
/**
* Gets the value at path of object. If the resolved value is undefined, undefined is returned.
*
* @template T
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 0: 'a', 1: 'b', 2: 'c' };
* get(object, 1);
* // => 'b'
*/
declare function get<T>(object: Record<number, T> | null | undefined, path: number): T | undefined;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template T
* @template TDefault
* @param object - The object to query.
* @param path - The path of the property to get.
* @param defaultValue - The value returned if the resolved value is undefined.
* @returns Returns the resolved value.
*
* @example
* const object = { 0: 'a', 1: 'b', 2: 'c' };
* get(object, 1, 'default');
* // => 'b'
*/
declare function get<T, TDefault>(object: Record<number, T> | null | undefined, path: number, defaultValue: TDefault): T | TDefault;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TDefault
* @param object - The object to query.
* @param path - The path of the property to get.
* @param defaultValue - The value returned if the resolved value is undefined.
* @returns Returns the default value.
*
* @example
* get(null, 'a.b.c', 'default');
* // => 'default'
*/
declare function get<TDefault>(object: null | undefined, path: PropertyPath, defaultValue: TDefault): TDefault;
/**
* Gets the value at path of object. If the resolved value is undefined, undefined is returned.
*
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns undefined.
*
* @example
* get(null, 'a.b.c');
* // => undefined
*/
declare function get(object: null | undefined, path: PropertyPath): undefined;
/**
* Gets the value at path of object using type-safe path.
*
* @template TObject
* @template TPath
* @param data - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { a: { b: { c: 1 } } };
* get(object, 'a.b.c');
* // => 1
*/
declare function get<TObject, TPath extends string>(data: TObject, path: TPath): string extends TPath ? any : GetFieldType<TObject, TPath>;
/**
* Gets the value at path of object using type-safe path. If the resolved value is undefined, the defaultValue is returned.
*
* @template TObject
* @template TPath
* @template TDefault
* @param data - The object to query.
* @param path - The path of the property to get.
* @param defaultValue - The value returned if the resolved value is undefined.
* @returns Returns the resolved value.
*
* @example
* const object = { a: { b: { c: 1 } } };
* get(object, 'a.b.d', 'default');
* // => 'default'
*/
declare function get<TObject, TPath extends string, TDefault = GetFieldType<TObject, TPath>>(data: TObject, path: TPath, defaultValue: TDefault): Exclude<GetFieldType<TObject, TPath>, null | undefined> | TDefault;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned.
*
* @param object - The object to query.
* @param path - The path of the property to get.
* @param [defaultValue] - The value returned if the resolved value is undefined.
* @returns Returns the resolved value.
*
* @example
* const object = { a: { b: { c: 1 } } };
* get(object, 'a.b.c', 'default');
* // => 1
*/
declare function get(object: any, path: PropertyPath, defaultValue?: any): any;
//#endregion
export { get };

View file

@ -0,0 +1,328 @@
import { PropertyPath } from "../_internal/PropertyPath.js";
import { GetFieldType } from "../_internal/GetFieldType.js";
//#region src/compat/object/get.d.ts
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': [{ 'b': { 'c': 3 } }] };
* get(object, 'a[0].b.c');
* // => 3
*/
declare function get<TObject extends object, TKey extends keyof TObject>(object: TObject, path: TKey | [TKey]): TObject[TKey];
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': [{ 'b': { 'c': 3 } }] };
* get(object, 'a[0].b.c');
* // => 3
*/
declare function get<TObject extends object, TKey extends keyof TObject>(object: TObject | null | undefined, path: TKey | [TKey]): TObject[TKey] | undefined;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey
* @template TDefault
* @param object - The object to query.
* @param path - The path of the property to get.
* @param defaultValue - The value returned if the resolved value is undefined.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': [{ 'b': { 'c': 3 } }] };
* get(object, 'a[0].b.c', 'default');
* // => 3
*/
declare function get<TObject extends object, TKey extends keyof TObject, TDefault>(object: TObject | null | undefined, path: TKey | [TKey], defaultValue: TDefault): Exclude<TObject[TKey], undefined> | TDefault;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey1
* @template TKey2
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': 2 } };
* get(object, ['a', 'b']);
* // => 2
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1]>(object: TObject, path: [TKey1, TKey2]): TObject[TKey1][TKey2];
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey1
* @template TKey2
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': 2 } };
* get(object, ['a', 'b']);
* // => 2
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>>(object: TObject | null | undefined, path: [TKey1, TKey2]): NonNullable<TObject[TKey1]>[TKey2] | undefined;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey1
* @template TKey2
* @template TDefault
* @param object - The object to query.
* @param path - The path of the property to get.
* @param defaultValue - The value returned if the resolved value is undefined.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': 2 } };
* get(object, ['a', 'b'], 'default');
* // => 2
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2], defaultValue: TDefault): Exclude<NonNullable<TObject[TKey1]>[TKey2], undefined> | TDefault;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey1
* @template TKey2
* @template TKey3
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': { 'c': 3 } } };
* get(object, ['a', 'b', 'c']);
* // => 3
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1], TKey3 extends keyof TObject[TKey1][TKey2]>(object: TObject, path: [TKey1, TKey2, TKey3]): TObject[TKey1][TKey2][TKey3];
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey1
* @template TKey2
* @template TKey3
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': { 'c': 3 } } };
* get(object, ['a', 'b', 'c']);
* // => 3
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3]): NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3] | undefined;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey1
* @template TKey2
* @template TKey3
* @template TDefault
* @param object - The object to query.
* @param path - The path of the property to get.
* @param defaultValue - The value returned if the resolved value is undefined.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': { 'c': 3 } } };
* get(object, ['a', 'b', 'c'], 'default');
* // => 3
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3], defaultValue: TDefault): Exclude<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3], undefined> | TDefault;
/**
* Gets the value at path of object.
*
* @template TObject
* @template TKey1
* @template TKey2
* @template TKey3
* @template TKey4
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': { 'c': { 'd': 4 } } } };
* get(object, ['a', 'b', 'c', 'd']);
* // => 4
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1], TKey3 extends keyof TObject[TKey1][TKey2], TKey4 extends keyof TObject[TKey1][TKey2][TKey3]>(object: TObject, path: [TKey1, TKey2, TKey3, TKey4]): TObject[TKey1][TKey2][TKey3][TKey4];
/**
* Gets the value at path of object. If the resolved value is undefined, undefined is returned.
*
* @template TObject
* @template TKey1
* @template TKey2
* @template TKey3
* @template TKey4
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': { 'c': { 'd': 4 } } } };
* get(object, ['a', 'b', 'c', 'd']);
* // => 4
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TKey4 extends keyof NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3, TKey4]): NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>[TKey4] | undefined;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TObject
* @template TKey1
* @template TKey2
* @template TKey3
* @template TKey4
* @template TDefault
* @param object - The object to query.
* @param path - The path of the property to get.
* @param defaultValue - The value returned if the resolved value is undefined.
* @returns Returns the resolved value.
*
* @example
* const object = { 'a': { 'b': { 'c': { 'd': 4 } } } };
* get(object, ['a', 'b', 'c', 'd'], 'default');
* // => 4
*/
declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TKey4 extends keyof NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3, TKey4], defaultValue: TDefault): Exclude<NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>[TKey4], undefined> | TDefault;
/**
* Gets the value at path of object.
*
* @template T
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 0: 'a', 1: 'b', 2: 'c' };
* get(object, 1);
* // => 'b'
*/
declare function get<T>(object: Record<number, T>, path: number): T;
/**
* Gets the value at path of object. If the resolved value is undefined, undefined is returned.
*
* @template T
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { 0: 'a', 1: 'b', 2: 'c' };
* get(object, 1);
* // => 'b'
*/
declare function get<T>(object: Record<number, T> | null | undefined, path: number): T | undefined;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template T
* @template TDefault
* @param object - The object to query.
* @param path - The path of the property to get.
* @param defaultValue - The value returned if the resolved value is undefined.
* @returns Returns the resolved value.
*
* @example
* const object = { 0: 'a', 1: 'b', 2: 'c' };
* get(object, 1, 'default');
* // => 'b'
*/
declare function get<T, TDefault>(object: Record<number, T> | null | undefined, path: number, defaultValue: TDefault): T | TDefault;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @template TDefault
* @param object - The object to query.
* @param path - The path of the property to get.
* @param defaultValue - The value returned if the resolved value is undefined.
* @returns Returns the default value.
*
* @example
* get(null, 'a.b.c', 'default');
* // => 'default'
*/
declare function get<TDefault>(object: null | undefined, path: PropertyPath, defaultValue: TDefault): TDefault;
/**
* Gets the value at path of object. If the resolved value is undefined, undefined is returned.
*
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns Returns undefined.
*
* @example
* get(null, 'a.b.c');
* // => undefined
*/
declare function get(object: null | undefined, path: PropertyPath): undefined;
/**
* Gets the value at path of object using type-safe path.
*
* @template TObject
* @template TPath
* @param data - The object to query.
* @param path - The path of the property to get.
* @returns Returns the resolved value.
*
* @example
* const object = { a: { b: { c: 1 } } };
* get(object, 'a.b.c');
* // => 1
*/
declare function get<TObject, TPath extends string>(data: TObject, path: TPath): string extends TPath ? any : GetFieldType<TObject, TPath>;
/**
* Gets the value at path of object using type-safe path. If the resolved value is undefined, the defaultValue is returned.
*
* @template TObject
* @template TPath
* @template TDefault
* @param data - The object to query.
* @param path - The path of the property to get.
* @param defaultValue - The value returned if the resolved value is undefined.
* @returns Returns the resolved value.
*
* @example
* const object = { a: { b: { c: 1 } } };
* get(object, 'a.b.d', 'default');
* // => 'default'
*/
declare function get<TObject, TPath extends string, TDefault = GetFieldType<TObject, TPath>>(data: TObject, path: TPath, defaultValue: TDefault): Exclude<GetFieldType<TObject, TPath>, null | undefined> | TDefault;
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned.
*
* @param object - The object to query.
* @param path - The path of the property to get.
* @param [defaultValue] - The value returned if the resolved value is undefined.
* @returns Returns the resolved value.
*
* @example
* const object = { a: { b: { c: 1 } } };
* get(object, 'a.b.c', 'default');
* // => 1
*/
declare function get(object: any, path: PropertyPath, defaultValue?: any): any;
//#endregion
export { get };

View file

@ -0,0 +1,65 @@
const require_isUnsafeProperty = require("../../_internal/isUnsafeProperty.js");
const require_isDeepKey = require("../_internal/isDeepKey.js");
const require_toKey = require("../_internal/toKey.js");
const require_toPath = require("../util/toPath.js");
//#region src/compat/object/get.ts
/**
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
*
* @param object - The object to query.
* @param path - The path of the property to get.
* @param [defaultValue] - The value returned if the resolved value is undefined.
* @returns 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 (require_isUnsafeProperty.isUnsafeProperty(path)) return defaultValue;
const result = object[path];
if (result === void 0) if (require_isDeepKey.isDeepKey(path) && !Object.hasOwn(object, path)) return get(object, require_toPath.toPath(path), defaultValue);
else return defaultValue;
return result;
}
case "number":
case "symbol": {
if (typeof path === "number") path = require_toKey.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 (require_isUnsafeProperty.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 (require_isUnsafeProperty.isUnsafeProperty(path[index])) return defaultValue;
current = current[path[index]];
}
if (current === void 0) return defaultValue;
return current;
}
//#endregion
exports.get = get;

View file

@ -0,0 +1,65 @@
import { isUnsafeProperty } from "../../_internal/isUnsafeProperty.mjs";
import { isDeepKey } from "../_internal/isDeepKey.mjs";
import { toKey } from "../_internal/toKey.mjs";
import { toPath } from "../util/toPath.mjs";
//#region src/compat/object/get.ts
/**
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
*
* @param object - The object to query.
* @param path - The path of the property to get.
* @param [defaultValue] - The value returned if the resolved value is undefined.
* @returns 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) && !Object.hasOwn(object, 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
export { get };

View file

@ -0,0 +1,51 @@
import { PropertyPath } from "../_internal/PropertyPath.mjs";
//#region src/compat/object/has.d.ts
/**
* Checks if a given path exists within an object.
*
* @template T
* @template K
* @param object - The object to query.
* @param path - The path to check.
* @returns & { [key: symbol]: unknown }} Returns a type guard indicating if the path exists in the object.
*
* @example
* const obj = { a: 1, b: { c: 2 } };
*
* if (has(obj, 'a')) {
* console.log(obj.a); // TypeScript knows obj.a exists
* }
*
* if (has(obj, 'b')) {
* console.log(obj.b.c); // TypeScript knows obj.b exists
* }
*/
declare function has<T, K extends PropertyKey>(object: T, path: K): object is T & { [P in K]: P extends keyof T ? T[P] : Record<string, unknown> extends T ? T[keyof T] : unknown } & {
[key: symbol]: unknown;
};
/**
* Checks if a given path exists within an object.
*
* @template T
* @param object - The object to query.
* @param path - The path to check. This can be a single property key,
* an array of property keys, or a string representing a deep path.
* @returns Returns `true` if the path exists in the object, `false` otherwise.
*
* @example
* const obj = { a: { b: { c: 3 } } };
*
* has(obj, 'a'); // true
* has(obj, ['a', 'b']); // true
* has(obj, ['a', 'b', 'c']); // true
* has(obj, 'a.b.c'); // true
* has(obj, 'a.b.d'); // false
* has(obj, ['a', 'b', 'c', 'd']); // false
* has([], 0); // false
* has([1, 2, 3], 2); // true
* has([1, 2, 3], 5); // false
*/
declare function has<T>(object: T, path: PropertyPath): boolean;
//#endregion
export { has };

View file

@ -0,0 +1,51 @@
import { PropertyPath } from "../_internal/PropertyPath.js";
//#region src/compat/object/has.d.ts
/**
* Checks if a given path exists within an object.
*
* @template T
* @template K
* @param object - The object to query.
* @param path - The path to check.
* @returns & { [key: symbol]: unknown }} Returns a type guard indicating if the path exists in the object.
*
* @example
* const obj = { a: 1, b: { c: 2 } };
*
* if (has(obj, 'a')) {
* console.log(obj.a); // TypeScript knows obj.a exists
* }
*
* if (has(obj, 'b')) {
* console.log(obj.b.c); // TypeScript knows obj.b exists
* }
*/
declare function has<T, K extends PropertyKey>(object: T, path: K): object is T & { [P in K]: P extends keyof T ? T[P] : Record<string, unknown> extends T ? T[keyof T] : unknown } & {
[key: symbol]: unknown;
};
/**
* Checks if a given path exists within an object.
*
* @template T
* @param object - The object to query.
* @param path - The path to check. This can be a single property key,
* an array of property keys, or a string representing a deep path.
* @returns Returns `true` if the path exists in the object, `false` otherwise.
*
* @example
* const obj = { a: { b: { c: 3 } } };
*
* has(obj, 'a'); // true
* has(obj, ['a', 'b']); // true
* has(obj, ['a', 'b', 'c']); // true
* has(obj, 'a.b.c'); // true
* has(obj, 'a.b.d'); // false
* has(obj, ['a', 'b', 'c', 'd']); // false
* has([], 0); // false
* has([1, 2, 3], 2); // true
* has([1, 2, 3], 5); // false
*/
declare function has<T>(object: T, path: PropertyPath): boolean;
//#endregion
export { has };

View file

@ -0,0 +1,52 @@
const require_isDeepKey = require("../_internal/isDeepKey.js");
const require_toPath = require("../util/toPath.js");
const require_isIndex = require("../_internal/isIndex.js");
const require_isArguments = require("../predicate/isArguments.js");
//#region src/compat/object/has.ts
/**
* Checks if a given path exists within an object.
*
* You can provide the path as a single property key, an array of property keys,
* or a string representing a deep path.
*
* If the path is an index and the object is an array or an arguments object, the function will verify
* if the index is valid and within the bounds of the array or arguments object, even if the array or
* arguments object is sparse (i.e., not all indexes are defined).
*
* @param object - The object to query.
* @param path - The path to check. This can be a single property key,
* an array of property keys, or a string representing a deep path.
* @returns Returns `true` if the path exists in the object, `false` otherwise.
*
* @example
*
* const obj = { a: { b: { c: 3 } } };
*
* has(obj, 'a'); // true
* has(obj, ['a', 'b']); // true
* has(obj, ['a', 'b', 'c']); // true
* has(obj, 'a.b.c'); // true
* has(obj, 'a.b.d'); // false
* has(obj, ['a', 'b', 'c', 'd']); // false
* has([], 0); // false
* has([1, 2, 3], 2); // true
* has([1, 2, 3], 5); // false
*/
function has(object, path) {
let resolvedPath;
if (Array.isArray(path)) resolvedPath = path;
else if (typeof path === "string" && require_isDeepKey.isDeepKey(path) && object?.[path] == null) resolvedPath = require_toPath.toPath(path);
else resolvedPath = [path];
if (resolvedPath.length === 0) return false;
let current = object;
for (let i = 0; i < resolvedPath.length; i++) {
const key = resolvedPath[i];
if (current == null || !Object.hasOwn(current, key)) {
if (!((Array.isArray(current) || require_isArguments.isArguments(current)) && require_isIndex.isIndex(key) && key < current.length)) return false;
}
current = current[key];
}
return true;
}
//#endregion
exports.has = has;

View file

@ -0,0 +1,52 @@
import { isDeepKey } from "../_internal/isDeepKey.mjs";
import { toPath } from "../util/toPath.mjs";
import { isIndex } from "../_internal/isIndex.mjs";
import { isArguments } from "../predicate/isArguments.mjs";
//#region src/compat/object/has.ts
/**
* Checks if a given path exists within an object.
*
* You can provide the path as a single property key, an array of property keys,
* or a string representing a deep path.
*
* If the path is an index and the object is an array or an arguments object, the function will verify
* if the index is valid and within the bounds of the array or arguments object, even if the array or
* arguments object is sparse (i.e., not all indexes are defined).
*
* @param object - The object to query.
* @param path - The path to check. This can be a single property key,
* an array of property keys, or a string representing a deep path.
* @returns Returns `true` if the path exists in the object, `false` otherwise.
*
* @example
*
* const obj = { a: { b: { c: 3 } } };
*
* has(obj, 'a'); // true
* has(obj, ['a', 'b']); // true
* has(obj, ['a', 'b', 'c']); // true
* has(obj, 'a.b.c'); // true
* has(obj, 'a.b.d'); // false
* has(obj, ['a', 'b', 'c', 'd']); // false
* has([], 0); // false
* has([1, 2, 3], 2); // true
* has([1, 2, 3], 5); // false
*/
function has(object, path) {
let resolvedPath;
if (Array.isArray(path)) resolvedPath = path;
else if (typeof path === "string" && isDeepKey(path) && object?.[path] == null) resolvedPath = toPath(path);
else resolvedPath = [path];
if (resolvedPath.length === 0) return false;
let current = object;
for (let i = 0; i < resolvedPath.length; i++) {
const key = resolvedPath[i];
if (current == null || !Object.hasOwn(current, key)) {
if (!((Array.isArray(current) || isArguments(current)) && isIndex(key) && key < current.length)) return false;
}
current = current[key];
}
return true;
}
//#endregion
export { has };

Some files were not shown because too many files have changed in this diff Show more