Comparing version 1.2.10 to 1.3.0
@@ -6,8 +6,9 @@ type BitsToBytes = { | ||
'64': 8; | ||
'128': 16; | ||
}; | ||
export type Size<T extends string> = T extends `${'int' | 'uint' | 'float'}${infer bits}` ? (bits extends keyof BitsToBytes ? BitsToBytes[bits] : never) : never; | ||
export type Type = `${'int' | 'uint'}${8 | 16 | 32 | 64}` | `float${32 | 64}`; | ||
export declare const types: readonly ["int8", "uint8", "int16", "uint16", "int32", "uint32", "int64", "uint64", "int128", "uint128", "float32", "float64", "float128"]; | ||
export type Type = (typeof types)[number]; | ||
export type Valid = Type | Capitalize<Type> | 'char'; | ||
export declare const types: ("int8" | "int16" | "int32" | "int64" | "uint8" | "uint16" | "uint32" | "uint64" | "float32" | "float64")[]; | ||
export declare const valids: ("int8" | "int16" | "int32" | "int64" | "uint8" | "uint16" | "uint32" | "uint64" | "float32" | "float64" | "Int8" | "Int16" | "Int32" | "Int64" | "Uint8" | "Uint16" | "Uint32" | "Uint64" | "Float32" | "Float64" | "char")[]; | ||
export declare const valids: ("int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "int64" | "uint64" | "int128" | "uint128" | "float32" | "float64" | "float128" | "Int8" | "Uint8" | "Int16" | "Uint16" | "Int32" | "Uint32" | "Int64" | "Uint64" | "Int128" | "Uint128" | "Float32" | "Float64" | "Float128" | "char")[]; | ||
export declare const regex: RegExp; | ||
@@ -25,2 +26,3 @@ export type Normalize<T extends Valid> = T extends 'char' ? 'uint8' : Uncapitalize<T>; | ||
}): asserts type is Valid; | ||
export declare const mask64: bigint; | ||
export {}; |
import { capitalize } from '../string.js'; | ||
export const types = ['int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'int64', 'uint64', 'float32', 'float64']; | ||
export const types = ['int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'int64', 'uint64', 'int128', 'uint128', 'float32', 'float64', 'float128']; | ||
export const valids = [...types, ...types.map(t => capitalize(t)), 'char']; | ||
export const regex = /^(u?int|float)(8|16|32|64)$/i; | ||
export const regex = /^(u?int|float)(8|16|32|64|128)$/i; | ||
export function normalize(type) { | ||
@@ -19,1 +19,2 @@ return (type == 'char' ? 'uint8' : type.toLowerCase()); | ||
} | ||
export const mask64 = BigInt('0xffffffffffffffff'); |
@@ -91,4 +91,3 @@ import * as primitive from './internal/primitives.js'; | ||
} | ||
const Type = capitalize(type); | ||
const fn = ('set' + Type); | ||
const fn = `set${capitalize(type)}`; | ||
if (fn == 'setInt64') { | ||
@@ -102,2 +101,17 @@ view.setBigInt64(iOff, BigInt(value), !options.bigEndian); | ||
} | ||
if (fn == 'setInt128') { | ||
view.setBigUint64(iOff + (!options.bigEndian ? 0 : 8), value & primitive.mask64, !options.bigEndian); | ||
view.setBigInt64(iOff + (!options.bigEndian ? 8 : 0), value >> BigInt(64), !options.bigEndian); | ||
continue; | ||
} | ||
if (fn == 'setUint128') { | ||
view.setBigUint64(iOff + (!options.bigEndian ? 0 : 8), value & primitive.mask64, !options.bigEndian); | ||
view.setBigUint64(iOff + (!options.bigEndian ? 8 : 0), value >> BigInt(64), !options.bigEndian); | ||
continue; | ||
} | ||
if (fn == 'setFloat128') { | ||
view.setFloat64(iOff + (!options.bigEndian ? 0 : 8), Number(value), !options.bigEndian); | ||
view.setBigUint64(iOff + (!options.bigEndian ? 8 : 0), BigInt(0), !options.bigEndian); | ||
continue; | ||
} | ||
view[fn](iOff, Number(value), !options.bigEndian); | ||
@@ -137,4 +151,3 @@ } | ||
} | ||
const Type = capitalize(type); | ||
const fn = ('get' + Type); | ||
const fn = `get${capitalize(type)}`; | ||
if (fn == 'getInt64') { | ||
@@ -148,2 +161,18 @@ object[key] = view.getBigInt64(iOff, !options.bigEndian); | ||
} | ||
if (fn == 'getInt128') { | ||
object[key] = | ||
(view.getBigInt64(iOff + (!options.bigEndian ? 8 : 0), !options.bigEndian) << BigInt(64)) | | ||
view.getBigUint64(iOff + (!options.bigEndian ? 0 : 8), !options.bigEndian); | ||
continue; | ||
} | ||
if (fn == 'getUint128') { | ||
object[key] = | ||
(view.getBigUint64(iOff + (!options.bigEndian ? 8 : 0), !options.bigEndian) << BigInt(64)) | | ||
view.getBigUint64(iOff + (!options.bigEndian ? 0 : 8), !options.bigEndian); | ||
continue; | ||
} | ||
if (fn == 'getFloat128') { | ||
object[key] = view.getFloat64(iOff + (!options.bigEndian ? 0 : 8), !options.bigEndian); | ||
continue; | ||
} | ||
object[key] = view[fn](iOff, !options.bigEndian); | ||
@@ -150,0 +179,0 @@ } |
{ | ||
"name": "utilium", | ||
"version": "1.2.10", | ||
"version": "1.3.0", | ||
"description": "Typescript utilities", | ||
@@ -5,0 +5,0 @@ "funding": { |
@@ -8,13 +8,16 @@ import { capitalize } from '../string.js'; | ||
'64': 8; | ||
'128': 16; | ||
}; | ||
export type Size<T extends string> = T extends `${'int' | 'uint' | 'float'}${infer bits}` ? (bits extends keyof BitsToBytes ? BitsToBytes[bits] : never) : never; | ||
export type Type = `${'int' | 'uint'}${8 | 16 | 32 | 64}` | `float${32 | 64}`; | ||
export const types = ['int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'int64', 'uint64', 'int128', 'uint128', 'float32', 'float64', 'float128'] as const; | ||
export type Type = (typeof types)[number]; | ||
export type Valid = Type | Capitalize<Type> | 'char'; | ||
export const types = ['int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'int64', 'uint64', 'float32', 'float64'] satisfies Type[]; | ||
export const valids = [...types, ...types.map(t => capitalize(t)), 'char'] satisfies Valid[]; | ||
export const regex = /^(u?int|float)(8|16|32|64)$/i; | ||
export const regex = /^(u?int|float)(8|16|32|64|128)$/i; | ||
@@ -40,1 +43,3 @@ export type Normalize<T extends Valid> = T extends 'char' ? 'uint8' : Uncapitalize<T>; | ||
} | ||
export const mask64 = BigInt('0xffffffffffffffff'); |
@@ -110,4 +110,4 @@ import * as primitive from './internal/primitives.js'; | ||
const Type = capitalize(type); | ||
const fn = ('set' + Type) as `set${typeof Type}`; | ||
const fn = `set${capitalize(type)}` as const; | ||
if (fn == 'setInt64') { | ||
@@ -123,2 +123,20 @@ view.setBigInt64(iOff, BigInt(value), !options.bigEndian); | ||
if (fn == 'setInt128') { | ||
view.setBigUint64(iOff + (!options.bigEndian ? 0 : 8), value & primitive.mask64, !options.bigEndian); | ||
view.setBigInt64(iOff + (!options.bigEndian ? 8 : 0), value >> BigInt(64), !options.bigEndian); | ||
continue; | ||
} | ||
if (fn == 'setUint128') { | ||
view.setBigUint64(iOff + (!options.bigEndian ? 0 : 8), value & primitive.mask64, !options.bigEndian); | ||
view.setBigUint64(iOff + (!options.bigEndian ? 8 : 0), value >> BigInt(64), !options.bigEndian); | ||
continue; | ||
} | ||
if (fn == 'setFloat128') { | ||
view.setFloat64(iOff + (!options.bigEndian ? 0 : 8), Number(value), !options.bigEndian); | ||
view.setBigUint64(iOff + (!options.bigEndian ? 8 : 0), BigInt(0), !options.bigEndian); | ||
continue; | ||
} | ||
view[fn](iOff, Number(value), !options.bigEndian); | ||
@@ -168,4 +186,3 @@ } | ||
const Type = capitalize(type); | ||
const fn = ('get' + Type) as `get${typeof Type}`; | ||
const fn = `get${capitalize(type)}` as const; | ||
if (fn == 'getInt64') { | ||
@@ -181,2 +198,21 @@ object[key] = view.getBigInt64(iOff, !options.bigEndian); | ||
if (fn == 'getInt128') { | ||
object[key] = | ||
(view.getBigInt64(iOff + (!options.bigEndian ? 8 : 0), !options.bigEndian) << BigInt(64)) | | ||
view.getBigUint64(iOff + (!options.bigEndian ? 0 : 8), !options.bigEndian); | ||
continue; | ||
} | ||
if (fn == 'getUint128') { | ||
object[key] = | ||
(view.getBigUint64(iOff + (!options.bigEndian ? 8 : 0), !options.bigEndian) << BigInt(64)) | | ||
view.getBigUint64(iOff + (!options.bigEndian ? 0 : 8), !options.bigEndian); | ||
continue; | ||
} | ||
if (fn == 'getFloat128') { | ||
object[key] = view.getFloat64(iOff + (!options.bigEndian ? 0 : 8), !options.bigEndian); | ||
continue; | ||
} | ||
object[key] = view[fn](iOff, !options.bigEndian); | ||
@@ -183,0 +219,0 @@ } |
133523
3775