Files
pezkuwi-common/packages/util/src/hex/stripPrefix.ts
T
pezkuwichain a5542fdd87 Rebrand: polkadot → pezkuwi internal references fixed
- Fixed internal @polkadot references to @pezkuwi
- Updated hw-ledger and hw-ledger-transports packages
- Updated keyring and networks packages
- Version 14.0.7
2026-01-07 02:34:39 +03:00

31 lines
890 B
TypeScript

// Copyright 2017-2025 @pezkuwi/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { REGEX_HEX_NOPREFIX, REGEX_HEX_PREFIXED } from '../is/hex.js';
/**
* @name hexStripPrefix
* @summary Strips any leading `0x` prefix.
* @description
* Tests for the existence of a `0x` prefix, and returns the value without the prefix. Un-prefixed values are returned as-is.
* @example
* <BR>
*
* ```javascript
* import { hexStripPrefix } from '@pezkuwi/util';
*
* console.log('stripped', hexStripPrefix('0x1234')); // => 1234
* ```
*/
export function hexStripPrefix (value?: string | null): string {
if (!value || value === '0x') {
return '';
} else if (REGEX_HEX_PREFIXED.test(value)) {
return value.substring(2);
} else if (REGEX_HEX_NOPREFIX.test(value)) {
return value;
}
throw new Error(`Expected hex value to convert, found '${value}'`);
}