Overview
A handful of small, dependency-free helpers used across the SDK for reshaping objects and narrowing types. All four are plain functions exported from @bitrix24/b24jssdk:
pick— a new object containing only the listed keys.omit— a shallow copy with the listed keys removed.getEnumValue— resolve a raw string/number to the matching enum member (orundefined).isArrayOfArray— a type guard distinguishing an array of arrays from a flat array.
import { pick, omit } from '@bitrix24/b24jssdk'
const user = { ID: '1', NAME: 'Ann', EMAIL: 'ann@example.com' }
pick(user, ['ID', 'NAME']) // { ID: '1', NAME: 'Ann' }
omit(user, ['EMAIL']) // { ID: '1', NAME: 'Ann' }
Method Signature
pick<Data extends object, Keys extends keyof Data>(
data: Data,
keys: Keys[]
): Pick<Data, Keys>
omit<Data extends object, Keys extends keyof Data>(
data: Data,
keys: Keys[]
): Omit<Data, Keys>
getEnumValue<T extends Record<string, string | number>>(
enumObj: T,
value: string | number
): T[keyof T] | undefined
isArrayOfArray<A>(item: A[] | A[][]): item is A[][]
Key Concepts
pick/omitare shallow.pickcopies the chosen property references into a fresh object;omitspreadsdatainto a shallow clone anddeletes the listed keys. Nested objects are shared by reference, and the originaldatais never mutated. Both return a precisely-typed result (Pick<Data, Keys>/Omit<Data, Keys>).getEnumValueis a runtime lookup. It checks whethervalueis present inObject.values(enumObj)and, if so, returns it narrowed to the enum's member type; otherwise it returnsundefined. It works with both string and numeric enums and is the safe way to turn an untrusted REST string into a typed enum member.isArrayOfArrayonly inspects the first element. It returnsArray.isArray(item[0])— it does not scan the whole array. On an empty arrayitem[0]isundefined, so it returnsfalse. The SDK uses it to tell a single list of batch calls apart from a list-of-lists.
Error Handling
None of these helpers throw. pick / omit operate on a copy and leave the input untouched, getEnumValue returns undefined for a value that is not a member of the enum, and isArrayOfArray returns false for an empty array rather than failing.
Examples
Reshape a REST record before sending it on:
import { pick, omit } from '@bitrix24/b24jssdk'
const contact = { ID: '42', NAME: 'Ann', PHONE: '+100', SECRET: 'x' }
// Keep only what the next call needs
pick(contact, ['ID', 'NAME']) // { ID: '42', NAME: 'Ann' }
// Drop an internal field before logging
omit(contact, ['SECRET']) // { ID: '42', NAME: 'Ann', PHONE: '+100' }
Resolve a raw field type to a DataType member:
import { getEnumValue, DataType } from '@bitrix24/b24jssdk'
getEnumValue(DataType, 'string') // DataType.string
getEnumValue(DataType, 'nope') // undefined
Branch on array shape with a type guard:
import { isArrayOfArray } from '@bitrix24/b24jssdk'
isArrayOfArray([[1, 2], [3, 4]]) // true — array of arrays
isArrayOfArray([1, 2, 3]) // false — flat array
isArrayOfArray([]) // false — empty array
Alternatives and Recommendations
- Use
getEnumValuewith the enums intypes/common. It pairs naturally withDataTypeand any other SDK enum when you need to validate a raw REST string before treating it as a typed value. - Prefer
pick/omitfor small, explicit reshaping. They are shallow by design; for deep cloning or complex transforms reach for a dedicated utility rather than layering these. isArrayOfArrayis a heuristic, not a validator. It trusts the first element to represent the whole array — do not use it to validate mixed or untrusted input where later elements may differ in shape.- Runtime type guards for scalar values live in
Type.isArrayOfArrayanswers one narrow question about array nesting; useType's guards (isArrayFilled,isStringFilled, …) for general shape checks.
Environment
Runtime environment detection — `getEnvironment()` and the `Environment` enum for branching between browser and Node.js code paths.
Text
Text and date utilities — UUID v4 / v7, encode / decode HTML entities, type conversions, case helpers, Luxon-backed `toDateTime` / `toB24Format`, number formatting, and query-string builder.