MCPcopy Create free account
hub / github.com/dfinity/orbit / parseToBigIntOrUndefined

Function parseToBigIntOrUndefined

apps/wallet/src/utils/helper.utils.ts:390–410  ·  view source on GitHub ↗
(
  value: string | number | bigint | null | undefined,
)

Source from the content-addressed store, hash-verified

388 * @returns The parsed BigInt value or undefined if the value is not a valid BigInt.
389 */
390export const parseToBigIntOrUndefined = (
391 value: string | number | bigint | null | undefined,
392): bigint | undefined => {
393 try {
394 if (value === undefined || value === null) {
395 return undefined;
396 }
397
398 if (typeof value === 'bigint') {
399 return value;
400 }
401
402 if (typeof value === 'string') {
403 return value.trim() !== '' ? BigInt(value) : undefined;
404 }
405
406 return BigInt(value);
407 } catch (_error) {
408 return undefined;
409 }
410};
411
412export const parseToNumberOrUndefined = (
413 value: string | number | bigint | null | undefined,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected