toFixedString(num: number, count: number)

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

Description

Convert a number to a string of the specified length; pad with leading zeros if shorter, truncate from the right if longer

Parameters

ParameterTypeRequiredDescription
numnumberYesNumber to convert
countnumberYesThe fixed length of the target string

Return Value

Type: string
A fixed-length string; negative numbers keep the minus sign prefix

Examples

Basic usage

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

const { toFixedString } = utils;

toFixedString(111, 5);  // '00111'
toFixedString(-42, 4);  // '-0042'
toFixedString(123456, 3); // '456'

toFilledString(num: number, count: number)

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

Description

Convert a number to a string with a specified minimum length; pad with leading zeros if shorter, keep as is if longer

Parameters

ParameterTypeRequiredDescription
numnumberYesNumber to convert
countnumberYesThe minimum length of the target string

Return Value

Type: string
A string with at least count digits; negative numbers keep the minus sign prefix

Examples

Basic usage

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

const { toFilledString } = utils;

toFilledString(111, 5);      // '00111'
toFilledString(-1111111, 5); // '-1111111'
toFilledString(42, 4);       // '0042'

bytesToHexString(bytes: number[])

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

Description

Convert a byte array to a hex string

Parameters

ParameterTypeRequiredDescription
bytesnumber[]YesByte array; each element is an integer from 0 to 255

Return Value

Type: string
The corresponding hex string, two characters per byte

Examples

Basic usage

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

const { bytesToHexString } = utils;

bytesToHexString([1, 2]);   // '0102'
bytesToHexString([23, 2]);  // '1702'
bytesToHexString([255, 0]); // 'ff00'

numToByteNumbers(num: number, bytes?: number)

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

Description

Convert a decimal integer to a big-endian byte array

Parameters

ParameterTypeRequiredDescription
numnumberYesThe decimal integer to convert
bytesnumberNoMinimum byte count (default 2); if the result is shorter than this length, pad zeros on the high-order side

Return Value

Type: number[]
The corresponding byte array, high-order first; if the value exceeds the width specified by bytes, it will not be truncated

Examples

Basic usage

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

const { numToByteNumbers } = utils;

numToByteNumbers(111);      // [0, 111]
numToByteNumbers(1040001);  // [15, 222, 129]
numToByteNumbers(256, 2);   // [1, 0]

intToHighLow(num: number)

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

Description

Split an integer into an array of high and low bytes

Parameters

ParameterTypeRequiredDescription
numnumberYesInteger to split

Return Value

Type: [number, number]
A tuple containing [high 8 bits, low 8 bits]

Examples

Basic usage

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

const { intToHighLow } = utils;

intToHighLow(2838); // [11, 22]
intToHighLow(5643); // [22, 11]
intToHighLow(256);  // [1, 0]

inMaxMin(min: number, max: number, value: number)

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

Description

Clamp a value between a minimum and a maximum

Parameters

ParameterTypeRequiredDescription
minnumberYesMinimum allowed value
maxnumberYesMaximum allowed value
valuenumberYesValue to clamp

Return Value

Type: number
The clamped value, ensuring min <= return value <= max

Examples

Basic usage

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

const { inMaxMin } = utils;

inMaxMin(1, 233, 2838); // 233 (exceeds max, returns max)
inMaxMin(2, 0, 1);      // 1 (out of range, but note parameter order min < max)
inMaxMin(0, 100, 50);   // 50 (within range, return as is)

scaleNumber(scale: number, value: number)

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

Description

Scale a number by the specified precision and return a string

Parameters

ParameterTypeRequiredDescription
scalenumberYesScale precision: divide by 10^scale and keep scale decimal places
valuenumberYesValue to scale

Return Value

Type: string
Scaled number string

Examples

Basic usage

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

const { scaleNumber } = utils;

scaleNumber(2, 10245); // '102.45'
scaleNumber(1, 1024);  // '102.4'
scaleNumber(0, 42);    // '42'

range(start: number, end: number, step?: number)

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

Description

Generate an array of numbers within a specified range

Parameters

ParameterTypeRequiredDescription
startnumberYesStart value
endnumberYesEnd value
stepnumberNoStep value, defaults to 1

Return Value

Type: number[]
Array from start to end, with step as the increment

Examples

Basic usage

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

const { range } = utils;

range(0, 3);      // [0, 1, 2]
range(1, 10, 3);  // [1, 4, 7]
range(0, -3, -1); // [0, -1, -2]

calcPosition(value: number, min: number, max: number, newMin: number, newMax: number)

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

Description

Linearly map a value from one range to another

Parameters

ParameterTypeRequiredDescription
valuenumberYesOriginal value
minnumberYesMinimum of the original range
maxnumberYesMaximum of the original range
newMinnumberYesMinimum of the target range
newMaxnumberYesMaximum of the target range

Return Value

Type: number
Value mapped to the target range

Examples

Basic usage

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

const { calcPosition } = utils;

calcPosition(50, 0, 100, -100, 0);   // -50
calcPosition(255, 0, 255, 0, 100);   // 100
calcPosition(127.5, 0, 255, 0, 100); // 50

calcPercent(min: number, max: number, value: number, offset?: number)

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

Description

Compute the percentage of a value within a specified range

Parameters

ParameterTypeRequiredDescription
minnumberYesRange minimum
maxnumberYesRange maximum
valuenumberYesThe value to compute, which will be clamped to [min, max]
offsetnumberNoPercentage start offset (0–1), defaults to 0

Return Value

Type: number
A percentage between 0 and 1

Examples

Basic usage

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

const { calcPercent } = utils;

calcPercent(0, 100, 50);       // 0.5
calcPercent(25, 255, 25);      // 0
calcPercent(25, 255, 25, 0.1); // 0.1 (with offset)

getBitValue(num: number, idx: number)

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

Description

Get the bit value at the specified position in a number's binary representation

Parameters

ParameterTypeRequiredDescription
numnumberYesInput number
idxnumberYesBit index (starting from the least significant bit; 0 is the LSB)

Return Value

Type: number
The bit value at that position, 0 or 1

Examples

Basic usage

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

const { getBitValue } = utils;

// 17 = 10001(2)
getBitValue(17, 0); // 1
getBitValue(17, 1); // 0
getBitValue(17, 4); // 1

changeBitValue(num: number, idx: number)

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

Description

Flip the bit at the specified position in a number's binary representation (0 becomes 1, 1 becomes 0)

Parameters

ParameterTypeRequiredDescription
numnumberYesInput number
idxnumberYesBit index (starting from the least significant bit; 0 is the LSB)

Return Value

Type: number
The new number after flipping the specified bit

Examples

Basic usage

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

const { changeBitValue } = utils;

// 17 = 10001(2)
changeBitValue(17, 0); // 16 (10000)
changeBitValue(17, 1); // 19 (10011)
changeBitValue(17, 4); // 1  (00001)

setBitValueWithOne(num: number, idx: number)

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

Description

Set the bit at the specified position to 1 in a number's binary representation

Parameters

ParameterTypeRequiredDescription
numnumberYesInput number
idxnumberYesBit index (starting from the least significant bit; 0 is the LSB)

Return Value

Type: number
The new number after setting the specified bit to 1

Examples

Basic usage

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

const { setBitValueWithOne } = utils;

// 17 = 10001(2)
setBitValueWithOne(17, 0); // 17 (10001), already 1
setBitValueWithOne(17, 1); // 19 (10011)
setBitValueWithOne(17, 5); // 49 (110001)

setBitValueWithZero(num: number, idx: number)

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

Description

Set the bit at the specified position to 0 in a number's binary representation

Parameters

ParameterTypeRequiredDescription
numnumberYesInput number
idxnumberYesBit index (starting from the least significant bit; 0 is the LSB)

Return Value

Type: number
The new number after setting the specified bit to 0

Examples

Basic usage

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

const { setBitValueWithZero } = utils;

// 17 = 10001(2)
setBitValueWithZero(17, 0); // 16 (10000)
setBitValueWithZero(17, 1); // 17 (10001), already 0
setBitValueWithZero(17, 4); // 1  (00001)

numToHexString(num: number, padding?: number)

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

Description

Convert a decimal number to a hex string with the specified minimum length

Parameters

ParameterTypeRequiredDescription
numnumberYesDecimal number to convert
paddingnumberNoMinimum hex string length; defaults to 2, pad with leading zeros if shorter

Return Value

Type: string
Hex string

Examples

Basic usage

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

const { numToHexString } = utils;

numToHexString(111);    // '6f'
numToHexString(15);     // '0f'
numToHexString(255, 4); // '00ff'

highLowToInt(high: number, low: number)

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

Description

Combine high and low bytes into an integer

Parameters

ParameterTypeRequiredDescription
highnumberYesHigh 8-bit byte value
lownumberYesLow 8-bit byte value

Return Value

Type: number
The combined integer value

Examples

Basic usage

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

const { highLowToInt } = utils;

highLowToInt(11, 22); // 2838
highLowToInt(22, 11); // 5643
highLowToInt(1, 0);   // 256

add(number1: number, number2: number)

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

Description

Accurately add two numbers to avoid floating-point precision issues

Parameters

ParameterTypeRequiredDescription
number1numberYesFirst addend
number2numberYesSecond addend

Return Value

Type: number
Accurate sum

Examples

Basic usage

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

const { add } = utils;

add(0.1, 0.2);   // 0.3 (instead of 0.30000000000000004)
add(1.005, 0.01); // 1.015

subtract(number1: number, number2: number)

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

Description

Accurately subtract two numbers to avoid floating-point precision issues

Parameters

ParameterTypeRequiredDescription
number1numberYesMinuend
number2numberYesSubtrahend

Return Value

Type: number
Accurate difference

Examples

Basic usage

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

const { subtract } = utils;

subtract(0.3, 0.1);   // 0.2 (instead of 0.19999999999999998)
subtract(1.005, 0.01); // 0.995