@blake.regalia/belt
Advanced tools
Comparing version 0.38.0 to 0.38.1
@@ -311,2 +311,20 @@ import type { NoInfer } from 'ts-toolbelt/out/Function/NoInfer'; | ||
/** | ||
* Commonly used reducer function to compute sum of a list numbers | ||
* @param a_values - list of values to sum | ||
* @returns the sum | ||
*/ | ||
export declare const sum: (a_values: number[]) => number; | ||
/** | ||
* Reducer function to compute product of a list numbers | ||
* @param a_values - list of values to multiply | ||
* @returns the sum | ||
*/ | ||
export declare const product: (a_values: number[]) => number; | ||
/** | ||
* Normalizes a list numbers | ||
* @param a_values - list of values to normalize | ||
* @returns a new array representing the normalized values | ||
*/ | ||
export declare const normalize: (a_values: number[], x_sum?: never) => number[]; | ||
/** | ||
* Throws an error, accepting an optional piece of data to attach to the object | ||
@@ -313,0 +331,0 @@ * @param s_msg |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fodemtv = exports.transform_values = exports.oderom = exports.transform_object = exports.oderaf = exports.flatten_entries = exports.oderac = exports.concat_entries = exports.oder = exports.reduce_object = exports.filter_object = exports.odem = exports.map_entries = exports.ofe = exports.from_entries = exports.ode = exports.entries = exports.odv = exports.values = exports.odk = exports.keys = exports.oda = exports.assign = exports.odc = exports.create = exports.each = exports.array = exports.is_error = exports.is_iterable = exports.is_dict_es = exports.is_dict = exports.is_array = exports.is_bytes = exports.is_function = exports.is_object = exports.is_symbol = exports.is_string = exports.is_bigint = exports.is_number = exports.is_boolean = exports.is_undefined = exports.narrow = exports.cast = exports.F_IDENTITY = exports.F_NOOP = exports.XG_32 = exports.XG_16 = exports.XG_8 = exports.__UNDEFINED = exports.ATU8_NIL = void 0; | ||
exports.try_async = exports.try_sync = exports.die = exports.remove = exports.shuffle = exports.random_int = exports.deduplicate = exports.interjoin = exports.collapse = exports.fold = void 0; | ||
exports.try_async = exports.try_sync = exports.die = exports.normalize = exports.product = exports.sum = exports.remove = exports.shuffle = exports.random_int = exports.deduplicate = exports.interjoin = exports.collapse = exports.fold = void 0; | ||
/** | ||
@@ -424,2 +424,23 @@ * Utility nil buffer constant | ||
/** | ||
* Commonly used reducer function to compute sum of a list numbers | ||
* @param a_values - list of values to sum | ||
* @returns the sum | ||
*/ | ||
const sum = (a_values) => a_values.reduce((x_a, x_b) => x_a + x_b, 0); | ||
exports.sum = sum; | ||
/** | ||
* Reducer function to compute product of a list numbers | ||
* @param a_values - list of values to multiply | ||
* @returns the sum | ||
*/ | ||
const product = (a_values) => a_values.reduce((x_a, x_b) => x_a * x_b, 0); | ||
exports.product = product; | ||
/** | ||
* Normalizes a list numbers | ||
* @param a_values - list of values to normalize | ||
* @returns a new array representing the normalized values | ||
*/ | ||
const normalize = (a_values, x_sum = (0, exports.sum)(a_values)) => a_values.map(x => x / x_sum); | ||
exports.normalize = normalize; | ||
/** | ||
* Throws an error, accepting an optional piece of data to attach to the object | ||
@@ -426,0 +447,0 @@ * @param s_msg |
@@ -6,2 +6,27 @@ import type { NaiveBase58, NaiveBase64, NaiveBase93, NaiveHexLower } from './strings'; | ||
export declare const SI_HASH_ALGORITHM_SHA512 = "SHA-512"; | ||
/** | ||
* Returns the lesser of the two `bigint` values | ||
*/ | ||
export declare const bigint_lesser: (xg_a: bigint, xg_b: bigint) => bigint; | ||
/** | ||
* Returns the greater of the two `bigint` values | ||
*/ | ||
export declare const bigint_greater: (xg_a: bigint, xg_b: bigint) => bigint; | ||
/** | ||
* Returns the absolute value of the given `bigint` value, or the absolute value of the delta between | ||
* the two given values if the 2nd argument is provided | ||
*/ | ||
export declare const bigint_abs: (xg_a: bigint, xg_b?: bigint, xg_delta?: never) => bigint; | ||
/** | ||
* Computes the maximum value among a list of `bigint` values | ||
* @param a_values - list of values | ||
* @returns the max value | ||
*/ | ||
export declare const bigint_max: (a_values: bigint[]) => bigint; | ||
/** | ||
* Computes the minimunm value among a list of `bigint` values | ||
* @param a_values - list of values | ||
* @returns the min value | ||
*/ | ||
export declare const bigint_min: (a_values: bigint[]) => bigint; | ||
export declare const uuid_v4: () => string; | ||
@@ -8,0 +33,0 @@ type Uint8ArrayConstructorParams = [] | [length: number] | [array: ArrayLike<number> | ArrayBufferLike] | [buffer: ArrayBufferLike, byteOffset?: number, length?: number]; |
"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.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; | ||
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.bigint_min = exports.bigint_max = exports.bigint_abs = exports.bigint_greater = exports.bigint_lesser = 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 = void 0; | ||
const belt_js_1 = require("./belt.js"); | ||
@@ -8,2 +9,44 @@ exports.SI_HASH_ALGORITHM_SHA256 = 'SHA-256'; | ||
exports.SI_HASH_ALGORITHM_SHA512 = 'SHA-512'; | ||
// /** | ||
// * Alias of `Math.max` | ||
// */ | ||
// export const max = Math.max; | ||
// /** | ||
// * Alias of `Math.min` | ||
// */ | ||
// export const min = Math.min; | ||
// /** | ||
// * Alias of `Math.abs` | ||
// */ | ||
// export const abs = Math.abs; | ||
/** | ||
* Returns the lesser of the two `bigint` values | ||
*/ | ||
const bigint_lesser = (xg_a, xg_b) => xg_a < xg_b ? xg_a : xg_b; | ||
exports.bigint_lesser = bigint_lesser; | ||
/** | ||
* Returns the greater of the two `bigint` values | ||
*/ | ||
const bigint_greater = (xg_a, xg_b) => xg_a > xg_b ? xg_a : xg_b; | ||
exports.bigint_greater = bigint_greater; | ||
/** | ||
* Returns the absolute value of the given `bigint` value, or the absolute value of the delta between | ||
* the two given values if the 2nd argument is provided | ||
*/ | ||
const bigint_abs = (xg_a, xg_b = 0n, xg_delta = xg_a - xg_b) => xg_delta < 0n ? -xg_delta : xg_delta; | ||
exports.bigint_abs = bigint_abs; | ||
/** | ||
* Computes the maximum value among a list of `bigint` values | ||
* @param a_values - list of values | ||
* @returns the max value | ||
*/ | ||
const bigint_max = (a_values) => a_values.reduce(exports.bigint_greater, 0n); | ||
exports.bigint_max = bigint_max; | ||
/** | ||
* Computes the minimunm value among a list of `bigint` values | ||
* @param a_values - list of values | ||
* @returns the min value | ||
*/ | ||
const bigint_min = (a_values) => a_values.reduce(exports.bigint_lesser, 0n); | ||
exports.bigint_min = bigint_min; | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
@@ -403,7 +446,7 @@ const S_UUID_V4 = 'xxxxxxxx_xxxx_4xxx_yxxx_xxxxxxxxxxxx'; | ||
const base64_to_bytes = (sb64_data) => { | ||
// 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(/=+$/, ''); | ||
// a buffer to store decoded sextets | ||
let xb_work = 0; | ||
// number of bits in the buffer | ||
let nb_buffer = 0; | ||
@@ -421,6 +464,4 @@ // prep output values | ||
xb_work = (xb_work << 6) | xb_char; | ||
// increase size of buffer | ||
nb_buffer += 6; | ||
// a whole byte exists in the buffer | ||
if (nb_buffer >= 8) { | ||
// increase size of buffer which checking if a whole byte exists in the buffer | ||
if ((nb_buffer += 6) >= 8) { | ||
// move byte out of buffer | ||
@@ -427,0 +468,0 @@ a_out.push(xb_work >>> (nb_buffer -= 8)); |
@@ -311,2 +311,20 @@ import type { NoInfer } from 'ts-toolbelt/out/Function/NoInfer'; | ||
/** | ||
* Commonly used reducer function to compute sum of a list numbers | ||
* @param a_values - list of values to sum | ||
* @returns the sum | ||
*/ | ||
export declare const sum: (a_values: number[]) => number; | ||
/** | ||
* Reducer function to compute product of a list numbers | ||
* @param a_values - list of values to multiply | ||
* @returns the sum | ||
*/ | ||
export declare const product: (a_values: number[]) => number; | ||
/** | ||
* Normalizes a list numbers | ||
* @param a_values - list of values to normalize | ||
* @returns a new array representing the normalized values | ||
*/ | ||
export declare const normalize: (a_values: number[], x_sum?: never) => number[]; | ||
/** | ||
* Throws an error, accepting an optional piece of data to attach to the object | ||
@@ -313,0 +331,0 @@ * @param s_msg |
@@ -388,2 +388,20 @@ /** | ||
/** | ||
* Commonly used reducer function to compute sum of a list numbers | ||
* @param a_values - list of values to sum | ||
* @returns the sum | ||
*/ | ||
export const sum = (a_values) => a_values.reduce((x_a, x_b) => x_a + x_b, 0); | ||
/** | ||
* Reducer function to compute product of a list numbers | ||
* @param a_values - list of values to multiply | ||
* @returns the sum | ||
*/ | ||
export const product = (a_values) => a_values.reduce((x_a, x_b) => x_a * x_b, 0); | ||
/** | ||
* Normalizes a list numbers | ||
* @param a_values - list of values to normalize | ||
* @returns a new array representing the normalized values | ||
*/ | ||
export const normalize = (a_values, x_sum = sum(a_values)) => a_values.map(x => x / x_sum); | ||
/** | ||
* Throws an error, accepting an optional piece of data to attach to the object | ||
@@ -390,0 +408,0 @@ * @param s_msg |
@@ -6,2 +6,27 @@ import type { NaiveBase58, NaiveBase64, NaiveBase93, NaiveHexLower } from './strings'; | ||
export declare const SI_HASH_ALGORITHM_SHA512 = "SHA-512"; | ||
/** | ||
* Returns the lesser of the two `bigint` values | ||
*/ | ||
export declare const bigint_lesser: (xg_a: bigint, xg_b: bigint) => bigint; | ||
/** | ||
* Returns the greater of the two `bigint` values | ||
*/ | ||
export declare const bigint_greater: (xg_a: bigint, xg_b: bigint) => bigint; | ||
/** | ||
* Returns the absolute value of the given `bigint` value, or the absolute value of the delta between | ||
* the two given values if the 2nd argument is provided | ||
*/ | ||
export declare const bigint_abs: (xg_a: bigint, xg_b?: bigint, xg_delta?: never) => bigint; | ||
/** | ||
* Computes the maximum value among a list of `bigint` values | ||
* @param a_values - list of values | ||
* @returns the max value | ||
*/ | ||
export declare const bigint_max: (a_values: bigint[]) => bigint; | ||
/** | ||
* Computes the minimunm value among a list of `bigint` values | ||
* @param a_values - list of values | ||
* @returns the min value | ||
*/ | ||
export declare const bigint_min: (a_values: bigint[]) => bigint; | ||
export declare const uuid_v4: () => string; | ||
@@ -8,0 +33,0 @@ type Uint8ArrayConstructorParams = [] | [length: number] | [array: ArrayLike<number> | ArrayBufferLike] | [buffer: ArrayBufferLike, byteOffset?: number, length?: number]; |
@@ -1,5 +0,42 @@ | ||
import { XG_8, is_array, is_dict_es, is_string, entries, from_entries, transform_values, die, try_sync } from './belt.js'; | ||
import { XG_8, is_array, is_dict_es, is_string, entries, from_entries, die, try_sync } from './belt.js'; | ||
export const SI_HASH_ALGORITHM_SHA256 = 'SHA-256'; | ||
export const SI_HASH_ALGORITHM_SHA384 = 'SHA-384'; | ||
export const SI_HASH_ALGORITHM_SHA512 = 'SHA-512'; | ||
// /** | ||
// * Alias of `Math.max` | ||
// */ | ||
// export const max = Math.max; | ||
// /** | ||
// * Alias of `Math.min` | ||
// */ | ||
// export const min = Math.min; | ||
// /** | ||
// * Alias of `Math.abs` | ||
// */ | ||
// export const abs = Math.abs; | ||
/** | ||
* Returns the lesser of the two `bigint` values | ||
*/ | ||
export const bigint_lesser = (xg_a, xg_b) => xg_a < xg_b ? xg_a : xg_b; | ||
/** | ||
* Returns the greater of the two `bigint` values | ||
*/ | ||
export const bigint_greater = (xg_a, xg_b) => xg_a > xg_b ? xg_a : xg_b; | ||
/** | ||
* Returns the absolute value of the given `bigint` value, or the absolute value of the delta between | ||
* the two given values if the 2nd argument is provided | ||
*/ | ||
export const bigint_abs = (xg_a, xg_b = 0n, xg_delta = xg_a - xg_b) => xg_delta < 0n ? -xg_delta : xg_delta; | ||
/** | ||
* Computes the maximum value among a list of `bigint` values | ||
* @param a_values - list of values | ||
* @returns the max value | ||
*/ | ||
export const bigint_max = (a_values) => a_values.reduce(bigint_greater, 0n); | ||
/** | ||
* Computes the minimunm value among a list of `bigint` values | ||
* @param a_values - list of values | ||
* @returns the min value | ||
*/ | ||
export const bigint_min = (a_values) => a_values.reduce(bigint_lesser, 0n); | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
@@ -368,7 +405,7 @@ const S_UUID_V4 = 'xxxxxxxx_xxxx_4xxx_yxxx_xxxxxxxxxxxx'; | ||
export const base64_to_bytes = (sb64_data) => { | ||
// 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(/=+$/, ''); | ||
// a buffer to store decoded sextets | ||
let xb_work = 0; | ||
// number of bits in the buffer | ||
let nb_buffer = 0; | ||
@@ -386,6 +423,4 @@ // prep output values | ||
xb_work = (xb_work << 6) | xb_char; | ||
// increase size of buffer | ||
nb_buffer += 6; | ||
// a whole byte exists in the buffer | ||
if (nb_buffer >= 8) { | ||
// increase size of buffer which checking if a whole byte exists in the buffer | ||
if ((nb_buffer += 6) >= 8) { | ||
// move byte out of buffer | ||
@@ -392,0 +427,0 @@ a_out.push(xb_work >>> (nb_buffer -= 8)); |
{ | ||
"name": "@blake.regalia/belt", | ||
"version": "0.38.0", | ||
"version": "0.38.1", | ||
"repository": "github:blake-regalia/belt", | ||
@@ -47,3 +47,4 @@ "license": "ISC", | ||
"access": "public" | ||
} | ||
}, | ||
"packageManager": "pnpm@9.0.6+sha1.648f6014eb363abb36618f2ba59282a9eeb3e879" | ||
} |
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
324364
60
6186