New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@blake.regalia/belt

Package Overview
Dependencies
Maintainers
0
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blake.regalia/belt - npm Package Compare versions

Comparing version 0.36.2 to 0.36.3

18

dist/cjs/async.d.ts

@@ -15,10 +15,7 @@ import type { Nilable } from './types';

*/
export declare const timeout_exec: <w_return extends unknown = any>(xt_wait: number, f_attempt?: () => Promise<w_return>) => Promise<[
w_return,
0
] | [undefined, 1]>;
export declare const timeout_exec: <w_return extends unknown = any>(xt_wait: number, f_attempt?: () => Promise<w_return>) => Promise<[w_return, 0] | [undefined, 1]>;
/**
* A Promise that never fulfills nor rejects
*/
export declare const forever: <w_type = void>(w_type?: w_type | undefined) => Promise<w_type>;
export declare const forever: <w_type = void>(w_type?: w_type) => Promise<w_type>;
/**

@@ -51,8 +48,5 @@ * Promse-based version of `queueMicrotask()`

*/
export declare const defer: <w_return extends unknown = any>() => [
Promise<w_return>,
{
(w_return: w_return): void;
(w_return: Nilable<void>, e_reject: Error): void;
}
];
export declare const defer: <w_return extends unknown = any>() => [Promise<w_return>, {
(w_return: w_return): void;
(w_return: Nilable<void>, e_reject: Error): void;
}];

@@ -79,3 +79,3 @@ import type { NoInfer } from 'ts-toolbelt/out/Function/NoInfer';

*/
export declare const is_array: <w_type = unknown>(z: unknown) => z is w_type[];
export declare const is_array: <w_type = unknown>(z: unknown) => z is Array<w_type>;
/**

@@ -193,7 +193,7 @@ * Simple test for whether a deserialized JSON value is a plain object (dict) or not

*/
export declare const concat_entries: <w_out extends unknown, w_src extends KeyValuable = KeyValuable, z_keys extends StringKeysOf<w_src> = StringKeysOf<w_src>, z_values extends ValuesOf<w_src> = ValuesOf<w_src>, b_keep_undefs extends AnyBoolish = AnyBoolish>(w_src: w_src, f_concat: (si_key: z_keys, w_value: z_values, i_entry: number) => w_out, b_keep_undefs?: AnyBoolish, a_out?: w_out[]) => IfBoolishTrue<b_keep_undefs, w_out, NonNullable<w_out>>[];
export declare const concat_entries: <w_out extends unknown, w_src extends KeyValuable = KeyValuable, z_keys extends StringKeysOf<w_src> = StringKeysOf<w_src>, z_values extends ValuesOf<w_src> = ValuesOf<w_src>, b_keep_undefs extends AnyBoolish = AnyBoolish>(w_src: w_src, f_concat: (si_key: z_keys, w_value: z_values, i_entry: number) => w_out, b_keep_undefs?: b_keep_undefs, a_out?: w_out[]) => NoInfer<IfBoolishTrue<b_keep_undefs, w_out, NonNullable<w_out>>[]>;
/**
* @deprecated Use {@link concat_entries} instead
*/
export declare const oderac: <w_out extends unknown, w_src extends KeyValuable = KeyValuable, z_keys extends StringKeysOf<w_src> = StringKeysOf<w_src>, z_values extends ValuesOf<w_src> = ValuesOf<w_src>, b_keep_undefs extends AnyBoolish = AnyBoolish>(w_src: w_src, f_concat: (si_key: z_keys, w_value: z_values, i_entry: number) => w_out, b_keep_undefs?: AnyBoolish, a_out?: w_out[]) => IfBoolishTrue<b_keep_undefs, w_out, NonNullable<w_out>>[];
export declare const oderac: <w_out extends unknown, w_src extends KeyValuable = KeyValuable, z_keys extends StringKeysOf<w_src> = StringKeysOf<w_src>, z_values extends ValuesOf<w_src> = ValuesOf<w_src>, b_keep_undefs extends AnyBoolish = AnyBoolish>(w_src: w_src, f_concat: (si_key: z_keys, w_value: z_values, i_entry: number) => w_out, b_keep_undefs?: b_keep_undefs, a_out?: w_out[]) => NoInfer<IfBoolishTrue<b_keep_undefs, w_out, NonNullable<w_out>>[]>;
/**

@@ -285,6 +285,6 @@ * Reduce object entries to an array via flattening (i.e., callback return value will be spread into array)

*/
export declare const interjoin: <w_item extends unknown, w_insert extends unknown>(a_input: w_item[], w_insert: w_insert) => (w_item | w_insert)[];
export declare const interjoin: <w_item extends unknown, w_insert extends unknown>(a_input: readonly w_item[], w_insert: w_insert) => Array<w_item | w_insert>;
/**
* Removes duplicates from an array, keeping only the first occurrence of each value. Optionally accepts
* an identity argument for deduplicating lists of objects using a key or callback function.
* Creates a copy of the original array with duplicates removed, keeping only the first occurrence of each value.
* Optionally accepts an identity argument for deduplicating lists of objects using a key or callback function.
* @param a_items - the items to deduplicate

@@ -295,4 +295,5 @@ * @param z_identify - defines how to identify items in the list

* - if omitted, compares items using strict equality
* @returns the new array
*/
export declare const deduplicate: <z_item extends unknown, s_key extends keyof z_item = keyof z_item>(a_items: z_item[], z_identify?: s_key | ((z_item: z_item) => any)) => z_item[];
export declare const deduplicate: <z_item extends unknown, s_key extends keyof z_item = keyof z_item>(a_items: readonly z_item[], z_identify?: s_key | ((z_item: z_item) => any)) => typeof a_items;
/**

@@ -303,7 +304,7 @@ * Generate a random int within a given range

/**
* Shuffles an array
* Shuffles an array in-place and returns it
*/
export declare const shuffle: <w_list extends any[] | TypedArray>(a_items: w_list, f_random?: (x_a: number, x_b?: number) => number) => w_list;
export declare const shuffle: <w_list extends Array<any> | TypedArray>(a_items: w_list, f_random?: (x_a: number, x_b?: number) => number) => w_list;
/**
* Removes the first occurrence of the given item from the array
* Removes the first occurrence of the given item from the array in-place and returns the array
* @param a_items

@@ -310,0 +311,0 @@ * @param w_item

@@ -342,4 +342,4 @@ "use strict";

/**
* Removes duplicates from an array, keeping only the first occurrence of each value. Optionally accepts
* an identity argument for deduplicating lists of objects using a key or callback function.
* Creates a copy of the original array with duplicates removed, keeping only the first occurrence of each value.
* Optionally accepts an identity argument for deduplicating lists of objects using a key or callback function.
* @param a_items - the items to deduplicate

@@ -350,2 +350,3 @@ * @param z_identify - defines how to identify items in the list

* - if omitted, compares items using strict equality
* @returns the new array
*/

@@ -398,3 +399,3 @@ const deduplicate = (a_items, z_identify) => {

/**
* Shuffles an array
* Shuffles an array in-place and returns it
*/

@@ -413,3 +414,3 @@ const shuffle = (a_items, f_random = exports.random_int) => {

/**
* Removes the first occurrence of the given item from the array
* Removes the first occurrence of the given item from the array in-place and returns the array
* @param a_items

@@ -416,0 +417,0 @@ * @param w_item

@@ -23,6 +23,3 @@ /**

*/
export declare const cbor_decode_trivial: <w_expected extends CborValue>(atu8_data: Uint8Array, ib_read?: number) => [
w_item: w_expected,
ib_read: number
];
export declare const cbor_decode_trivial: <w_expected extends CborValue>(atu8_data: Uint8Array, ib_read?: number) => [w_item: w_expected, ib_read: number];
export {};

@@ -1,3 +0,1 @@

/// <reference types="web" />
/// <reference types="web" />
import type { NaiveBase58, NaiveBase64, NaiveBase93, NaiveHexLower } from './strings';

@@ -79,3 +77,3 @@ import type { JsonValue, NaiveJsonString } from './types';

*/
export declare const import_key: (atu8_sk: Uint8Array, z_algo: Parameters<SubtleCrypto['importKey']>[2], da_usages: Parameters<SubtleCrypto['importKey']>[4], b_extractable?: boolean) => Promise<CryptoKey>;
export declare const import_key: (atu8_sk: Uint8Array, z_algo: Parameters<SubtleCrypto["importKey"]>[2], da_usages: Parameters<SubtleCrypto["importKey"]>[4], b_extractable?: boolean) => Promise<CryptoKey>;
/**

@@ -87,3 +85,3 @@ * Performs HMAC signing of the given message, **not the digest**.

*/
export declare const hmac: (atu8_sk: Uint8Array, atu8_message: Uint8Array, si_algo?: 'SHA-256' | 'SHA-384' | 'SHA-512') => Promise<Uint8Array>;
export declare const hmac: (atu8_sk: Uint8Array, atu8_message: Uint8Array, si_algo?: "SHA-256" | "SHA-384" | "SHA-512") => Promise<Uint8Array>;
/**

@@ -97,3 +95,3 @@ * Performs HKDF on the given IKM

*/
export declare const hkdf: (atu8_ikm: Uint8Array, ni_bits: number, atu8_salt: Uint8Array, atu8_info?: Uint8Array, si_algo?: 'SHA-256' | 'SHA-384' | 'SHA-512') => Promise<Uint8Array>;
export declare const hkdf: (atu8_ikm: Uint8Array, ni_bits: number, atu8_salt: Uint8Array, atu8_info?: Uint8Array, si_algo?: "SHA-256" | "SHA-384" | "SHA-512") => Promise<Uint8Array>;
/**

@@ -179,3 +177,3 @@ * Wipe the contents of a buffer so that sensitive data does not outlive garbage collection.

*/
export declare const concat: (a_buffers: Uint8Array[]) => Uint8Array;
export declare const concat: (a_buffers: readonly Uint8Array[]) => Uint8Array;
/**

@@ -225,3 +223,3 @@ * Concatenate two Uint8Arrays together.

/**
* Converts the given UTF-8 friendly compact string to a buffer.
* Converts the given raw string (no encoding) to bytes.
* @param sx_buffer input string

@@ -232,2 +230,8 @@ * @returns output buffer

/**
* Converts the given bytes to a raw string (no encoding).
* @param at8u_bytes input bytes
* @returns output string
*/
export declare const bytes_to_string8: (atu8_bytes: Uint8Array) => string;
/**
* Converts the given buffer to a base93-encoded string.

@@ -234,0 +238,0 @@ * @param atu8_buffer input buffer

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.crypto_random_int = exports.crypto_random = exports.base58_to_bytes = exports.bytes_to_base58 = exports.base93_to_bytes = exports.bytes_to_base93 = exports.string8_to_bytes = exports.base64_to_bytes = exports.bytes_to_base64 = exports.base64_to_bytes_slim = exports.bytes_to_base64_slim = exports.hex_to_bytes = exports.bytes_to_hex = exports.concat2 = exports.concat = exports.bytes_to_bigint_be = exports.bytes_to_biguint_be = exports.bigint_to_bytes_be = exports.biguint_to_bytes_be = exports.bytes_to_uint32_be = exports.uint32_to_bytes_be = exports.bytes_to_json = exports.json_to_bytes = exports.text_to_base64 = exports.base64_to_text = exports.bytes_to_text = exports.text_to_bytes = exports.decode_length_prefix_u16 = exports.encode_length_prefix_u16 = exports.zero_out = exports.hkdf = exports.hmac = exports.import_key = exports.sha512 = exports.sha384 = exports.sha256d = exports.sha256 = exports.dataview = exports.bytes = exports.canonicalize_json = exports.safe_json = exports.parse_json_safe = exports.parse_json = exports.stringify_json = exports.uuid_v4 = exports.SI_HASH_ALGORITHM_SHA512 = exports.SI_HASH_ALGORITHM_SHA384 = exports.SI_HASH_ALGORITHM_SHA256 = void 0;
exports.crypto_random_int = exports.crypto_random = exports.base58_to_bytes = exports.bytes_to_base58 = exports.base93_to_bytes = exports.bytes_to_base93 = exports.bytes_to_string8 = exports.string8_to_bytes = exports.base64_to_bytes = exports.bytes_to_base64 = exports.base64_to_bytes_slim = exports.bytes_to_base64_slim = exports.hex_to_bytes = exports.bytes_to_hex = exports.concat2 = exports.concat = exports.bytes_to_bigint_be = exports.bytes_to_biguint_be = exports.bigint_to_bytes_be = exports.biguint_to_bytes_be = exports.bytes_to_uint32_be = exports.uint32_to_bytes_be = exports.bytes_to_json = exports.json_to_bytes = exports.text_to_base64 = exports.base64_to_text = exports.bytes_to_text = exports.text_to_bytes = exports.decode_length_prefix_u16 = exports.encode_length_prefix_u16 = exports.zero_out = exports.hkdf = exports.hmac = exports.import_key = exports.sha512 = exports.sha384 = exports.sha256d = exports.sha256 = exports.dataview = exports.bytes = exports.canonicalize_json = exports.safe_json = exports.parse_json_safe = exports.parse_json = exports.stringify_json = exports.uuid_v4 = exports.SI_HASH_ALGORITHM_SHA512 = exports.SI_HASH_ALGORITHM_SHA384 = exports.SI_HASH_ALGORITHM_SHA256 = void 0;
const belt_js_1 = require("./belt.js");

@@ -344,3 +344,3 @@ exports.SI_HASH_ALGORITHM_SHA256 = 'SHA-256';

*/
const base64_to_bytes_slim = (sx_buffer) => (0, exports.bytes)(atob(sx_buffer).split('').map(s => s.charCodeAt(0)));
const base64_to_bytes_slim = (sx_buffer) => (0, exports.bytes)(atob(sx_buffer.replace(/=+$/, '')).split('').map(s => s.charCodeAt(0)));
exports.base64_to_bytes_slim = base64_to_bytes_slim;

@@ -403,9 +403,15 @@ const SX_CHARS_BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';

const base64_to_bytes = (sb64_data) => {
const nl_padding = sb64_data.match(/=$/g)?.length || 0;
sb64_data = sb64_data.replace(/=/g, '');
// count how many padding characters there are
const nl_padding = sb64_data.match(/=+$/)?.[0].length || 0;
// remove padding from string
sb64_data = sb64_data.replace(/=+$/, '');
let xb_work = 0;
let nb_buffer = 0;
// prep output values
const a_out = [];
// each character
for (const s_char of sb64_data) {
// decode character value
const xb_char = SX_CHARS_BASE64.indexOf(s_char);
// invalid base64-encoding
if (-1 === xb_char)

@@ -415,17 +421,12 @@ (0, belt_js_1.die)('Invalid base64 string');

xb_work = (xb_work << 6) | xb_char;
// increase size of buffer
nb_buffer += 6;
do {
if (nb_buffer >= 8) {
a_out.push(xb_work >>> (nb_buffer - 8));
nb_buffer -= 8;
}
} while (nb_buffer >= 8);
// a whole byte exists in the buffer
if (nb_buffer >= 8) {
// move byte out of buffer
a_out.push(xb_work >>> (nb_buffer -= 8));
// trim the buffer
xb_work &= (1 << nb_buffer) - 1;
}
}
// Adjust for padding by removing bits added
nb_buffer -= nl_padding * 2;
// Convert remaining bits in the buffer to bytes (if any)
while (nb_buffer >= 8) {
a_out.push(xb_work >>> (nb_buffer - 8));
nb_buffer -= 8;
}
return (0, exports.bytes)(a_out);

@@ -435,3 +436,3 @@ };

/**
* Converts the given UTF-8 friendly compact string to a buffer.
* Converts the given raw string (no encoding) to bytes.
* @param sx_buffer input string

@@ -441,5 +442,5 @@ * @returns output buffer

const string8_to_bytes = (sx_buffer) => {
const nl_pairs = sx_buffer.length;
const atu8_buffer = (0, exports.bytes)(nl_pairs);
for (let i_read = 0; i_read < nl_pairs; i_read++) {
const nl_chars = sx_buffer.length;
const atu8_buffer = (0, exports.bytes)(nl_chars);
for (let i_read = 0; i_read < nl_chars; i_read++) {
atu8_buffer[i_read] = sx_buffer.charCodeAt(i_read);

@@ -450,2 +451,15 @@ }

exports.string8_to_bytes = string8_to_bytes;
/**
* Converts the given bytes to a raw string (no encoding).
* @param at8u_bytes input bytes
* @returns output string
*/
const bytes_to_string8 = (atu8_bytes) => {
let sx_buffer = '';
for (let i_read = 0; i_read < atu8_bytes.length; i_read++) {
sx_buffer += String.fromCharCode(atu8_bytes[i_read]);
}
return sx_buffer;
};
exports.bytes_to_string8 = bytes_to_string8;
// inspired by <https://github.com/ticlo/jsonesc/blob/master/dist/base93.js>

@@ -452,0 +466,0 @@ // eslint-disable-next-line @typescript-eslint/naming-convention

@@ -28,7 +28,7 @@ import type { NoInfer } from 'ts-toolbelt/out/Function/_api';

interface HexLowerMethods extends HexMethods {
concat(...a_lowers: NaiveHexLower[]): NaiveHexLower;
concat(...a_lowers: readonly NaiveHexLower[]): NaiveHexLower;
concat(...a_uppers: (NaiveHexUpper | NaiveHexMixed)[]): NaiveHexMixed;
}
interface HexUpperMethods extends HexMethods {
concat(...a_uppers: NaiveHexUpper[]): NaiveHexUpper;
concat(...a_uppers: readonly NaiveHexUpper[]): NaiveHexUpper;
concat(...a_lowers: (NaiveHexLower | NaiveHexMixed)[]): NaiveHexMixed;

@@ -35,0 +35,0 @@ }

@@ -15,10 +15,7 @@ import type { Nilable } from './types';

*/
export declare const timeout_exec: <w_return extends unknown = any>(xt_wait: number, f_attempt?: () => Promise<w_return>) => Promise<[
w_return,
0
] | [undefined, 1]>;
export declare const timeout_exec: <w_return extends unknown = any>(xt_wait: number, f_attempt?: () => Promise<w_return>) => Promise<[w_return, 0] | [undefined, 1]>;
/**
* A Promise that never fulfills nor rejects
*/
export declare const forever: <w_type = void>(w_type?: w_type | undefined) => Promise<w_type>;
export declare const forever: <w_type = void>(w_type?: w_type) => Promise<w_type>;
/**

@@ -51,8 +48,5 @@ * Promse-based version of `queueMicrotask()`

*/
export declare const defer: <w_return extends unknown = any>() => [
Promise<w_return>,
{
(w_return: w_return): void;
(w_return: Nilable<void>, e_reject: Error): void;
}
];
export declare const defer: <w_return extends unknown = any>() => [Promise<w_return>, {
(w_return: w_return): void;
(w_return: Nilable<void>, e_reject: Error): void;
}];

@@ -79,3 +79,3 @@ import type { NoInfer } from 'ts-toolbelt/out/Function/NoInfer';

*/
export declare const is_array: <w_type = unknown>(z: unknown) => z is w_type[];
export declare const is_array: <w_type = unknown>(z: unknown) => z is Array<w_type>;
/**

@@ -193,7 +193,7 @@ * Simple test for whether a deserialized JSON value is a plain object (dict) or not

*/
export declare const concat_entries: <w_out extends unknown, w_src extends KeyValuable = KeyValuable, z_keys extends StringKeysOf<w_src> = StringKeysOf<w_src>, z_values extends ValuesOf<w_src> = ValuesOf<w_src>, b_keep_undefs extends AnyBoolish = AnyBoolish>(w_src: w_src, f_concat: (si_key: z_keys, w_value: z_values, i_entry: number) => w_out, b_keep_undefs?: AnyBoolish, a_out?: w_out[]) => IfBoolishTrue<b_keep_undefs, w_out, NonNullable<w_out>>[];
export declare const concat_entries: <w_out extends unknown, w_src extends KeyValuable = KeyValuable, z_keys extends StringKeysOf<w_src> = StringKeysOf<w_src>, z_values extends ValuesOf<w_src> = ValuesOf<w_src>, b_keep_undefs extends AnyBoolish = AnyBoolish>(w_src: w_src, f_concat: (si_key: z_keys, w_value: z_values, i_entry: number) => w_out, b_keep_undefs?: b_keep_undefs, a_out?: w_out[]) => NoInfer<IfBoolishTrue<b_keep_undefs, w_out, NonNullable<w_out>>[]>;
/**
* @deprecated Use {@link concat_entries} instead
*/
export declare const oderac: <w_out extends unknown, w_src extends KeyValuable = KeyValuable, z_keys extends StringKeysOf<w_src> = StringKeysOf<w_src>, z_values extends ValuesOf<w_src> = ValuesOf<w_src>, b_keep_undefs extends AnyBoolish = AnyBoolish>(w_src: w_src, f_concat: (si_key: z_keys, w_value: z_values, i_entry: number) => w_out, b_keep_undefs?: AnyBoolish, a_out?: w_out[]) => IfBoolishTrue<b_keep_undefs, w_out, NonNullable<w_out>>[];
export declare const oderac: <w_out extends unknown, w_src extends KeyValuable = KeyValuable, z_keys extends StringKeysOf<w_src> = StringKeysOf<w_src>, z_values extends ValuesOf<w_src> = ValuesOf<w_src>, b_keep_undefs extends AnyBoolish = AnyBoolish>(w_src: w_src, f_concat: (si_key: z_keys, w_value: z_values, i_entry: number) => w_out, b_keep_undefs?: b_keep_undefs, a_out?: w_out[]) => NoInfer<IfBoolishTrue<b_keep_undefs, w_out, NonNullable<w_out>>[]>;
/**

@@ -285,6 +285,6 @@ * Reduce object entries to an array via flattening (i.e., callback return value will be spread into array)

*/
export declare const interjoin: <w_item extends unknown, w_insert extends unknown>(a_input: w_item[], w_insert: w_insert) => (w_item | w_insert)[];
export declare const interjoin: <w_item extends unknown, w_insert extends unknown>(a_input: readonly w_item[], w_insert: w_insert) => Array<w_item | w_insert>;
/**
* Removes duplicates from an array, keeping only the first occurrence of each value. Optionally accepts
* an identity argument for deduplicating lists of objects using a key or callback function.
* Creates a copy of the original array with duplicates removed, keeping only the first occurrence of each value.
* Optionally accepts an identity argument for deduplicating lists of objects using a key or callback function.
* @param a_items - the items to deduplicate

@@ -295,4 +295,5 @@ * @param z_identify - defines how to identify items in the list

* - if omitted, compares items using strict equality
* @returns the new array
*/
export declare const deduplicate: <z_item extends unknown, s_key extends keyof z_item = keyof z_item>(a_items: z_item[], z_identify?: s_key | ((z_item: z_item) => any)) => z_item[];
export declare const deduplicate: <z_item extends unknown, s_key extends keyof z_item = keyof z_item>(a_items: readonly z_item[], z_identify?: s_key | ((z_item: z_item) => any)) => typeof a_items;
/**

@@ -303,7 +304,7 @@ * Generate a random int within a given range

/**
* Shuffles an array
* Shuffles an array in-place and returns it
*/
export declare const shuffle: <w_list extends any[] | TypedArray>(a_items: w_list, f_random?: (x_a: number, x_b?: number) => number) => w_list;
export declare const shuffle: <w_list extends Array<any> | TypedArray>(a_items: w_list, f_random?: (x_a: number, x_b?: number) => number) => w_list;
/**
* Removes the first occurrence of the given item from the array
* Removes the first occurrence of the given item from the array in-place and returns the array
* @param a_items

@@ -310,0 +311,0 @@ * @param w_item

@@ -310,4 +310,4 @@ /**

/**
* Removes duplicates from an array, keeping only the first occurrence of each value. Optionally accepts
* an identity argument for deduplicating lists of objects using a key or callback function.
* Creates a copy of the original array with duplicates removed, keeping only the first occurrence of each value.
* Optionally accepts an identity argument for deduplicating lists of objects using a key or callback function.
* @param a_items - the items to deduplicate

@@ -318,2 +318,3 @@ * @param z_identify - defines how to identify items in the list

* - if omitted, compares items using strict equality
* @returns the new array
*/

@@ -364,3 +365,3 @@ export const deduplicate = (a_items, z_identify) => {

/**
* Shuffles an array
* Shuffles an array in-place and returns it
*/

@@ -378,3 +379,3 @@ export const shuffle = (a_items, f_random = random_int) => {

/**
* Removes the first occurrence of the given item from the array
* Removes the first occurrence of the given item from the array in-place and returns the array
* @param a_items

@@ -381,0 +382,0 @@ * @param w_item

@@ -23,6 +23,3 @@ /**

*/
export declare const cbor_decode_trivial: <w_expected extends CborValue>(atu8_data: Uint8Array, ib_read?: number) => [
w_item: w_expected,
ib_read: number
];
export declare const cbor_decode_trivial: <w_expected extends CborValue>(atu8_data: Uint8Array, ib_read?: number) => [w_item: w_expected, ib_read: number];
export {};

@@ -1,3 +0,1 @@

/// <reference types="web" />
/// <reference types="web" />
import type { NaiveBase58, NaiveBase64, NaiveBase93, NaiveHexLower } from './strings';

@@ -79,3 +77,3 @@ import type { JsonValue, NaiveJsonString } from './types';

*/
export declare const import_key: (atu8_sk: Uint8Array, z_algo: Parameters<SubtleCrypto['importKey']>[2], da_usages: Parameters<SubtleCrypto['importKey']>[4], b_extractable?: boolean) => Promise<CryptoKey>;
export declare const import_key: (atu8_sk: Uint8Array, z_algo: Parameters<SubtleCrypto["importKey"]>[2], da_usages: Parameters<SubtleCrypto["importKey"]>[4], b_extractable?: boolean) => Promise<CryptoKey>;
/**

@@ -87,3 +85,3 @@ * Performs HMAC signing of the given message, **not the digest**.

*/
export declare const hmac: (atu8_sk: Uint8Array, atu8_message: Uint8Array, si_algo?: 'SHA-256' | 'SHA-384' | 'SHA-512') => Promise<Uint8Array>;
export declare const hmac: (atu8_sk: Uint8Array, atu8_message: Uint8Array, si_algo?: "SHA-256" | "SHA-384" | "SHA-512") => Promise<Uint8Array>;
/**

@@ -97,3 +95,3 @@ * Performs HKDF on the given IKM

*/
export declare const hkdf: (atu8_ikm: Uint8Array, ni_bits: number, atu8_salt: Uint8Array, atu8_info?: Uint8Array, si_algo?: 'SHA-256' | 'SHA-384' | 'SHA-512') => Promise<Uint8Array>;
export declare const hkdf: (atu8_ikm: Uint8Array, ni_bits: number, atu8_salt: Uint8Array, atu8_info?: Uint8Array, si_algo?: "SHA-256" | "SHA-384" | "SHA-512") => Promise<Uint8Array>;
/**

@@ -179,3 +177,3 @@ * Wipe the contents of a buffer so that sensitive data does not outlive garbage collection.

*/
export declare const concat: (a_buffers: Uint8Array[]) => Uint8Array;
export declare const concat: (a_buffers: readonly Uint8Array[]) => Uint8Array;
/**

@@ -225,3 +223,3 @@ * Concatenate two Uint8Arrays together.

/**
* Converts the given UTF-8 friendly compact string to a buffer.
* Converts the given raw string (no encoding) to bytes.
* @param sx_buffer input string

@@ -232,2 +230,8 @@ * @returns output buffer

/**
* Converts the given bytes to a raw string (no encoding).
* @param at8u_bytes input bytes
* @returns output string
*/
export declare const bytes_to_string8: (atu8_bytes: Uint8Array) => string;
/**
* Converts the given buffer to a base93-encoded string.

@@ -234,0 +238,0 @@ * @param atu8_buffer input buffer

@@ -312,3 +312,3 @@ import { XG_8, is_array, is_dict_es, is_string, entries, from_entries, transform_values, die, try_sync } from './belt.js';

*/
export const base64_to_bytes_slim = (sx_buffer) => bytes(atob(sx_buffer).split('').map(s => s.charCodeAt(0)));
export const base64_to_bytes_slim = (sx_buffer) => bytes(atob(sx_buffer.replace(/=+$/, '')).split('').map(s => s.charCodeAt(0)));
const SX_CHARS_BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';

@@ -369,9 +369,15 @@ // adapted from <https://gist.github.com/jonleighton/958841>

export const base64_to_bytes = (sb64_data) => {
const nl_padding = sb64_data.match(/=$/g)?.length || 0;
sb64_data = sb64_data.replace(/=/g, '');
// count how many padding characters there are
const nl_padding = sb64_data.match(/=+$/)?.[0].length || 0;
// remove padding from string
sb64_data = sb64_data.replace(/=+$/, '');
let xb_work = 0;
let nb_buffer = 0;
// prep output values
const a_out = [];
// each character
for (const s_char of sb64_data) {
// decode character value
const xb_char = SX_CHARS_BASE64.indexOf(s_char);
// invalid base64-encoding
if (-1 === xb_char)

@@ -381,21 +387,16 @@ die('Invalid base64 string');

xb_work = (xb_work << 6) | xb_char;
// increase size of buffer
nb_buffer += 6;
do {
if (nb_buffer >= 8) {
a_out.push(xb_work >>> (nb_buffer - 8));
nb_buffer -= 8;
}
} while (nb_buffer >= 8);
// a whole byte exists in the buffer
if (nb_buffer >= 8) {
// move byte out of buffer
a_out.push(xb_work >>> (nb_buffer -= 8));
// trim the buffer
xb_work &= (1 << nb_buffer) - 1;
}
}
// Adjust for padding by removing bits added
nb_buffer -= nl_padding * 2;
// Convert remaining bits in the buffer to bytes (if any)
while (nb_buffer >= 8) {
a_out.push(xb_work >>> (nb_buffer - 8));
nb_buffer -= 8;
}
return bytes(a_out);
};
/**
* Converts the given UTF-8 friendly compact string to a buffer.
* Converts the given raw string (no encoding) to bytes.
* @param sx_buffer input string

@@ -405,5 +406,5 @@ * @returns output buffer

export const string8_to_bytes = (sx_buffer) => {
const nl_pairs = sx_buffer.length;
const atu8_buffer = bytes(nl_pairs);
for (let i_read = 0; i_read < nl_pairs; i_read++) {
const nl_chars = sx_buffer.length;
const atu8_buffer = bytes(nl_chars);
for (let i_read = 0; i_read < nl_chars; i_read++) {
atu8_buffer[i_read] = sx_buffer.charCodeAt(i_read);

@@ -413,2 +414,14 @@ }

};
/**
* Converts the given bytes to a raw string (no encoding).
* @param at8u_bytes input bytes
* @returns output string
*/
export const bytes_to_string8 = (atu8_bytes) => {
let sx_buffer = '';
for (let i_read = 0; i_read < atu8_bytes.length; i_read++) {
sx_buffer += String.fromCharCode(atu8_bytes[i_read]);
}
return sx_buffer;
};
// inspired by <https://github.com/ticlo/jsonesc/blob/master/dist/base93.js>

@@ -415,0 +428,0 @@ // eslint-disable-next-line @typescript-eslint/naming-convention

@@ -28,7 +28,7 @@ import type { NoInfer } from 'ts-toolbelt/out/Function/_api';

interface HexLowerMethods extends HexMethods {
concat(...a_lowers: NaiveHexLower[]): NaiveHexLower;
concat(...a_lowers: readonly NaiveHexLower[]): NaiveHexLower;
concat(...a_uppers: (NaiveHexUpper | NaiveHexMixed)[]): NaiveHexMixed;
}
interface HexUpperMethods extends HexMethods {
concat(...a_uppers: NaiveHexUpper[]): NaiveHexUpper;
concat(...a_uppers: readonly NaiveHexUpper[]): NaiveHexUpper;
concat(...a_lowers: (NaiveHexLower | NaiveHexMixed)[]): NaiveHexMixed;

@@ -35,0 +35,0 @@ }

{
"name": "@blake.regalia/belt",
"version": "0.36.2",
"version": "0.36.3",
"repository": "github:blake-regalia/belt",

@@ -33,13 +33,13 @@ "license": "ISC",

"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^20.12.7",
"@types/web": "^0.0.142",
"@typescript-eslint/parser": "^7.6.0",
"bun": "^1.1.3",
"bun-types": "^1.1.3",
"@types/node": "^20.14.7",
"@types/web": "^0.0.149",
"@typescript-eslint/parser": "^7.13.1",
"bun": "^1.1.15",
"bun-types": "^1.1.15",
"eslint": "^8.57.0",
"jest": "^29.7.0",
"rollup": "^4.14.2",
"rollup": "^4.18.0",
"ts-node": "^10.9.2",
"ts-toolbelt": "^9.6.0",
"typescript": "^5.4.5"
"typescript": "^5.5.2"
},

@@ -46,0 +46,0 @@ "publishConfig": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc