toFixed(str: string | number, count: number)

Requires:
@ray-js/panel-sdk≥1.0.0

Description

Get a string of the specified length; pad with leading zeros if shorter, or truncate from the right if longer.

Parameters

ParameterTypeRequiredDescription
strstring | numberYesThe string or number to pad
countnumberYesThe fixed length of the returned string

Return Value

Type: string
The fixed-length string after padding or truncation

Examples

Basic usage

import { utils } from '@ray-js/panel-sdk';

const { toFixed } = utils;

toFixed('111', 5);    // '00111'
toFixed('3456111', 5); // '56111'
toFixed(42, 4);        // '0042'

toFilled(str: string, count: number)

Requires:
@ray-js/panel-sdk≥1.0.0

Description

Pad a string with leading zeros to the specified minimum length

Parameters

ParameterTypeRequiredDescription
strstringYesThe string to pad
countnumberYesThe minimum length of the returned string

Return Value

Type: string
The padded string; if the original length is already >= count, it is returned as is

Examples

Basic usage

import { utils } from '@ray-js/panel-sdk';

const { toFilled } = utils;

toFilled('111', 5);     // '00111'
toFilled('3456111', 5); // '3456111'

partition(str: string, chunk: number)

Requires:
@ray-js/panel-sdk≥1.0.0

Description

Split a string into an array of substrings of the specified length

Parameters

ParameterTypeRequiredDescription
strstringYesThe original string to split
chunknumberYesThe length of each substring

Return Value

Type: string[]
The resulting array of substrings; the last element may be shorter than chunk

Examples

Basic usage

import { utils } from '@ray-js/panel-sdk';

const { partition } = utils;

partition('1234567', 3); // ['123', '456', '7']
partition('AABB', 2);    // ['AA', 'BB']

get(object: Record<string, any>, pathString: string, defaultValue?: string | number | false | true | Record<string, any>)

Requires:
@ray-js/panel-sdk≥1.0.0

Description

Safely get a nested property value by a path string (a lightweight alternative to lodash.get)

Parameters

ParameterTypeRequiredDescription
YesThe source object to query
pathStringstringYesProperty path, dot-separated, e.g., 'a.b.c'
NoThe default value to return when the resolved path is undefined

Return Value

Type: string | number | false | true | Record<string, any>
The value at the given path, or defaultValue if not found

Examples

Basic usage

import { utils } from '@ray-js/panel-sdk';

const { get } = utils;

const obj = { a: { b: { c: 42 } } };
get(obj, 'a.b.c');          // 42
get(obj, 'a.b.x', 'N/A');  // 'N/A'
get(obj, 'a.b.c.d');       // undefined

pick(object: Record<string, unknown>, keys: string[])

Requires:
@ray-js/panel-sdk≥1.0.0

Description

Pick specified keys from an object and return a new object (a lightweight alternative to lodash.pick)

Parameters

ParameterTypeRequiredDescription
YesSource object
keysstring[]YesAn array of property keys to pick

Return Value

Type: Record<string, unknown>
A new object containing only the specified keys

Examples

Basic usage

import { utils } from '@ray-js/panel-sdk';

const { pick } = utils;

const obj = { a: 1, b: 2, c: 3 };
pick(obj, ['a', 'c']); // { a: 1, c: 3 }
pick(obj, ['d']);       // {}

omit(object: Record<string, unknown>, keys: string[])

Requires:
@ray-js/panel-sdk≥1.0.0

Description

Omit specified keys from an object and return a new object (a lightweight alternative to lodash.omit)

Parameters

ParameterTypeRequiredDescription
YesSource object
keysstring[]YesAn array of property keys to omit

Return Value

Type: Record<string, unknown>
A new object with the specified keys omitted (shallow copy)

Examples

Basic usage

import { utils } from '@ray-js/panel-sdk';

const { omit } = utils;

const obj = { a: 1, b: 2, c: 3 };
omit(obj, ['b']);      // { a: 1, c: 3 }
omit(obj, ['a', 'c']); // { b: 2 }

chunk(arr: any[], chunkSize?: number, cache?: any[])

Requires:
@ray-js/panel-sdk≥1.0.0

Description

Split an array into multiple subarrays of the specified size (a lightweight alternative to lodash.chunk)

Parameters

ParameterTypeRequiredDescription
arrany[]YesThe original array to split
chunkSizenumberNoThe size of each subarray, default is 1
cacheany[]NoCache array for internal recursion; typically not needed to pass

Return Value

Type: any[]
The resulting two-dimensional array

Examples

Basic usage

import { utils } from '@ray-js/panel-sdk';

const { chunk } = utils;

chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
chunk(['a', 'b', 'c'], 1); // [['a'], ['b'], ['c']]

compareVersion(v1: string, v2: string)

Requires:
@ray-js/panel-sdk≥1.0.0

Description

Compare the order of two semantic version strings

Parameters

ParameterTypeRequiredDescription
v1stringYesThe first version string, e.g., '1.2.3'
v2stringYesThe second version string, e.g., '1.2.4'

Return Value

Type: false | 0 | 1 | -1
1 means v1 is greater than v2, -1 means v1 is less than v2, 0 means equal, false means invalid arguments

Valid Values

return
ValueDescriptionSince
false--
0--
1--
-1--

Examples

Basic usage

import { utils } from '@ray-js/panel-sdk';

const { compareVersion } = utils;

compareVersion('1.2.3', '1.2.4'); // -1
compareVersion('2.0.0', '1.9.9'); // 1
compareVersion('1.0.0', '1.0.0'); // 0
compareVersion(null, '1.0.0');    // false