Object API
isPlainObject Plain
Checks whether a value is a plain object.
Signature
export function isPlainObject(value: unknown): value is Record<PropertyKey, unknown>;Example
import { isPlainObject } from "@fast-china/utils";
const result = isPlainObject({});Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | unknown | Required | Any value to check. |
Returns
| Value | Type | Description |
|---|---|---|
result | value is Record<PropertyKey, unknown> | true when the prototype is Object.prototype or null. |
hasOwn Ownership
Safely checks for an object's own property.
Signature
export function hasOwn<ObjectType extends object, Key extends PropertyKey>(value: ObjectType, key: Key): key is Key & keyof ObjectType;Example
import { hasOwn } from "@fast-china/utils";
const result = hasOwn({}, "profile");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | ObjectType | Required | Object to check. |
key | Key | Required | String, number, or Symbol property key. |
Returns
| Value | Type | Description |
|---|---|---|
result | key is Key & keyof ObjectType | true for an own property, narrowing the key type. |
cloneDeep Clone
Recursively creates a deep copy.
Signature
export function cloneDeep<Value>(value: Value): Value;Example
import { cloneDeep } from "@fast-china/utils";
const result = cloneDeep({});Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | Value | Required | Any value to clone deeply. |
Returns
| Value | Type | Description |
|---|---|---|
result | Value | New value of the same type, sharing no clonable nested values; primitives are returned unchanged. |
isEqual Compare
Deeply compares two values for equivalence.
Signature
export function isEqual(left: unknown, right: unknown): boolean;Example
import { isEqual } from "@fast-china/utils";
const result = isEqual([1, 2, 3], [2, 4]);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
left | unknown | Required | First value to compare. |
right | unknown | Required | Second value to compare. |
Returns
| Value | Type | Description |
|---|---|---|
result | boolean | true when the values are deeply equivalent. |
pick Pick
Performs the corresponding public utility operation.
Signature
export function pick<Source extends object, const Keys extends readonly (keyof Source)[]>(
source: Source,
keys: Keys
): number extends Keys["length"] ? Partial<Pick<Source, Keys[number]>> : Pick<Source, Keys[number]>;
export function pick<Source extends object>(source: Source, keys: readonly PropertyKey[]): Partial<Source>;Example
import { pick } from "@fast-china/utils";
const result = pick({ id: 1, name: "Fast" }, ["id"] as const);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
source | Source | Required | See the signature and method description. |
keys | readonly PropertyKey[] | Required | See the signature and method description. |
Returns
| Value | Type | Description |
|---|---|---|
result | Partial<Source> | Result calculated or created by the method. |
omit Omit
Performs the corresponding public utility operation.
Signature
export function omit<Source extends object, const Keys extends readonly (keyof Source)[]>(
source: Source,
keys: Keys
): number extends Keys["length"] ? Omit<Source, Keys[number]> & Partial<Pick<Source, Keys[number]>> : Omit<Source, Keys[number]>;
export function omit<Source extends object>(source: Source, keys: readonly PropertyKey[]): Partial<Source>;Example
import { omit } from "@fast-china/utils";
const result = omit({ id: 1, name: "Fast" }, ["id"] as const);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
source | Source | Required | See the signature and method description. |
keys | readonly PropertyKey[] | Required | See the signature and method description. |
Returns
| Value | Type | Description |
|---|---|---|
result | Partial<Source> | Result calculated or created by the method. |
omitBy Omit
Conditionally omits own enumerable properties.
Signature
export function omitBy<Source extends object>(
source: Source,
predicate: (value: Source[keyof Source], key: keyof Source, source: Source) => unknown
): Partial<Source>;Example
import { omitBy } from "@fast-china/utils";
const result = omitBy({ id: 1, name: "Fast" }, (_value, key) => key === "id");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
source | Source | Required | Source object; not mutated. |
predicate | (value: Source[keyof Source], key: keyof Source, source: Source) => unknown | Required | Receives value, key, and source object; a truthy result omits the property. |
Returns
| Value | Type | Description |
|---|---|---|
result | Partial<Source> | New object containing nonmatching properties. |
pickBy Pick
Conditionally selects own enumerable properties.
Signature
export function pickBy<Source extends object>(
source: Source,
predicate: (value: Source[keyof Source], key: keyof Source, source: Source) => unknown
): Partial<Source>;Example
import { pickBy } from "@fast-china/utils";
const result = pickBy({ id: 1, name: "Fast" }, (_value, key) => key === "name");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
source | Source | Required | Source object; not mutated. |
predicate | (value: Source[keyof Source], key: keyof Source, source: Source) => unknown | Required | Receives value, key, and source object; a truthy result retains the property. |
Returns
| Value | Type | Description |
|---|---|---|
result | Partial<Source> | New object containing matching properties. |
mapValues Map
Maps own enumerable property values.
Signature
export function mapValues<Source extends object, Result>(
source: Source,
mapper: (value: Source[keyof Source], key: keyof Source, source: Source) => Result
): { [Key in keyof Source]: Result };Example
import { mapValues } from "@fast-china/utils";
const result = mapValues({ first: 1, second: 2 }, (value) => value * 2);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
source | Source | Required | Source object; not mutated. |
mapper | (value: Source[keyof Source], key: keyof Source, source: Source) => Result | Required | Mapper receiving value, key, and source object. |
Returns
| Value | Type | Description |
|---|---|---|
result | { [Key in keyof Source]: Result } | New object preserving the original keys. |
shallowEqual Compare
Shallowly compares own enumerable properties using SameValue.
Signature
export function shallowEqual(left: object, right: object): boolean;Example
import { shallowEqual } from "@fast-china/utils";
const result = shallowEqual([1, 2, 3], [2, 4]);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
left | object | Required | First object. |
right | object | Required | Second object. |
Returns
| Value | Type | Description |
|---|---|---|
result | boolean | true when own enumerable key sets and corresponding values match under SameValue. |
toQueryString Query
Serializes an object into a standard URL query string.
Signature
export function toQueryString(value: Readonly<Record<string, QueryValue>>, options: QueryStringOptions = {}): string;Example
import { toQueryString } from "@fast-china/utils";
const result = toQueryString({ page: 1, tag: ["vue", "tsx"] });Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | Readonly<Record<string, QueryValue>> | Required | Query parameter object. |
options | QueryStringOptions | Optional; defaults to {} | Sorting, whitespace encoding, and question-mark prefix options. |
Returns
| Value | Type | Description |
|---|---|---|
result | string | URL-encoded query string; always empty when there are no parameters. |
Clone and dynamic-key boundaries
Deep cloning preserves sparse slots, own enumerable string/symbol properties and cycles. Views sharing an ArrayBuffer also share its cloned buffer, with offsets and lengths preserved. Existing unsupported-type behavior remains. pick/omit are shallow operations and dynamic candidate keys are not incorrectly required.
