@ac-kit/core 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +130 -0
- package/dist/big-int/from-bytes-be.d.ts +14 -0
- package/dist/big-int/from-bytes-be.d.ts.map +1 -0
- package/dist/big-int/from-bytes-be.js +20 -0
- package/dist/big-int/from-bytes-be.js.map +1 -0
- package/dist/big-int/from-bytes-le.d.ts +15 -0
- package/dist/big-int/from-bytes-le.d.ts.map +1 -0
- package/dist/big-int/from-bytes-le.js +21 -0
- package/dist/big-int/from-bytes-le.js.map +1 -0
- package/dist/big-int/is-safe-number.d.ts +20 -0
- package/dist/big-int/is-safe-number.d.ts.map +1 -0
- package/dist/big-int/is-safe-number.js +24 -0
- package/dist/big-int/is-safe-number.js.map +1 -0
- package/dist/big-int/to-bytes-be.d.ts +19 -0
- package/dist/big-int/to-bytes-be.d.ts.map +1 -0
- package/dist/big-int/to-bytes-be.js +60 -0
- package/dist/big-int/to-bytes-be.js.map +1 -0
- package/dist/big-int/to-bytes-le.d.ts +19 -0
- package/dist/big-int/to-bytes-le.d.ts.map +1 -0
- package/dist/big-int/to-bytes-le.js +22 -0
- package/dist/big-int/to-bytes-le.js.map +1 -0
- package/dist/buffer/bytes-combine.d.ts +18 -0
- package/dist/buffer/bytes-combine.d.ts.map +1 -0
- package/dist/buffer/bytes-combine.js +25 -0
- package/dist/buffer/bytes-combine.js.map +1 -0
- package/dist/buffer/bytes-map.d.ts +14 -0
- package/dist/buffer/bytes-map.d.ts.map +1 -0
- package/dist/buffer/bytes-map.js +21 -0
- package/dist/buffer/bytes-map.js.map +1 -0
- package/dist/buffer/text/next-utf8-boundary.d.ts +17 -0
- package/dist/buffer/text/next-utf8-boundary.d.ts.map +1 -0
- package/dist/buffer/text/next-utf8-boundary.js +27 -0
- package/dist/buffer/text/next-utf8-boundary.js.map +1 -0
- package/dist/guards/has-object-prototype.d.ts +27 -0
- package/dist/guards/has-object-prototype.d.ts.map +1 -0
- package/dist/guards/has-object-prototype.js +30 -0
- package/dist/guards/has-object-prototype.js.map +1 -0
- package/dist/guards/is-object.d.ts +28 -2
- package/dist/guards/is-object.d.ts.map +1 -1
- package/dist/guards/is-object.js +28 -2
- package/dist/guards/is-object.js.map +1 -1
- package/dist/guards/is-pojo.d.ts +27 -2
- package/dist/guards/is-pojo.d.ts.map +1 -1
- package/dist/guards/is-pojo.js +27 -2
- package/dist/guards/is-pojo.js.map +1 -1
- package/dist/index.d.ts +22 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -13
- package/dist/index.js.map +1 -1
- package/dist/json/replacers/big-int.d.ts.map +1 -1
- package/dist/json/replacers/big-int.js +2 -5
- package/dist/json/replacers/big-int.js.map +1 -1
- package/dist/number/parse-number-or-big-int.d.ts +30 -0
- package/dist/number/parse-number-or-big-int.d.ts.map +1 -0
- package/dist/number/parse-number-or-big-int.js +44 -0
- package/dist/number/parse-number-or-big-int.js.map +1 -0
- package/dist/object/defaults.d.ts.map +1 -1
- package/dist/object/defaults.js +11 -4
- package/dist/object/defaults.js.map +1 -1
- package/dist/object/flatten-record.d.ts +67 -0
- package/dist/object/flatten-record.d.ts.map +1 -0
- package/dist/object/flatten-record.js +81 -0
- package/dist/object/flatten-record.js.map +1 -0
- package/dist/object/get-at-path.d.ts +5 -0
- package/dist/object/get-at-path.d.ts.map +1 -1
- package/dist/object/get-at-path.js +5 -0
- package/dist/object/get-at-path.js.map +1 -1
- package/dist/object/is-unsafe-record-key.d.ts +26 -0
- package/dist/object/is-unsafe-record-key.d.ts.map +1 -0
- package/dist/object/is-unsafe-record-key.js +28 -0
- package/dist/object/is-unsafe-record-key.js.map +1 -0
- package/dist/object/merge-inplace.d.ts.map +1 -1
- package/dist/object/merge-inplace.js +4 -2
- package/dist/object/merge-inplace.js.map +1 -1
- package/dist/object/merge.d.ts.map +1 -1
- package/dist/object/merge.js +4 -2
- package/dist/object/merge.js.map +1 -1
- package/dist/object/null-if-empty.d.ts +12 -0
- package/dist/object/null-if-empty.d.ts.map +1 -0
- package/dist/object/null-if-empty.js +17 -0
- package/dist/object/null-if-empty.js.map +1 -0
- package/dist/object/set-at-path.d.ts +5 -0
- package/dist/object/set-at-path.d.ts.map +1 -1
- package/dist/object/set-at-path.js +10 -3
- package/dist/object/set-at-path.js.map +1 -1
- package/dist/object/set-record-entry.d.ts +32 -0
- package/dist/object/set-record-entry.d.ts.map +1 -0
- package/dist/object/set-record-entry.js +43 -0
- package/dist/object/set-record-entry.js.map +1 -0
- package/dist/object/traverse.js +3 -3
- package/dist/object/traverse.js.map +1 -1
- package/dist/object/unflatten-record.d.ts +63 -0
- package/dist/object/unflatten-record.d.ts.map +1 -0
- package/dist/object/unflatten-record.js +71 -0
- package/dist/object/unflatten-record.js.map +1 -0
- package/dist/string/ascii/is-ascii-blank.d.ts +8 -0
- package/dist/string/ascii/is-ascii-blank.d.ts.map +1 -0
- package/dist/string/ascii/is-ascii-blank.js +11 -0
- package/dist/string/ascii/is-ascii-blank.js.map +1 -0
- package/dist/string/ascii/is-ascii-control.d.ts +6 -0
- package/dist/string/ascii/is-ascii-control.d.ts.map +1 -0
- package/dist/string/ascii/is-ascii-control.js +9 -0
- package/dist/string/ascii/is-ascii-control.js.map +1 -0
- package/dist/string/ascii/is-ascii-graphic.d.ts +7 -0
- package/dist/string/ascii/is-ascii-graphic.d.ts.map +1 -0
- package/dist/string/ascii/is-ascii-graphic.js +10 -0
- package/dist/string/ascii/is-ascii-graphic.js.map +1 -0
- package/dist/string/ascii/is-ascii-printable.d.ts +7 -0
- package/dist/string/ascii/is-ascii-printable.d.ts.map +1 -0
- package/dist/string/ascii/is-ascii-printable.js +10 -0
- package/dist/string/ascii/is-ascii-printable.js.map +1 -0
- package/dist/string/ascii/is-ascii-punctuation.d.ts +6 -0
- package/dist/string/ascii/is-ascii-punctuation.d.ts.map +1 -0
- package/dist/string/ascii/is-ascii-punctuation.js +10 -0
- package/dist/string/ascii/is-ascii-punctuation.js.map +1 -0
- package/dist/system/fs/escape-posix-path.d.ts.map +1 -0
- package/dist/system/fs/escape-posix-path.js.map +1 -0
- package/dist/system/fs/escape-win32-path.d.ts.map +1 -0
- package/dist/system/fs/escape-win32-path.js.map +1 -0
- package/package.json +2 -2
- package/dist/guards/is-plain-object.d.ts +0 -8
- package/dist/guards/is-plain-object.d.ts.map +0 -1
- package/dist/guards/is-plain-object.js +0 -11
- package/dist/guards/is-plain-object.js.map +0 -1
- package/dist/net/ephemeral-port.d.ts +0 -13
- package/dist/net/ephemeral-port.d.ts.map +0 -1
- package/dist/net/ephemeral-port.js +0 -19
- package/dist/net/ephemeral-port.js.map +0 -1
- package/dist/net/inet-address.d.ts +0 -20
- package/dist/net/inet-address.d.ts.map +0 -1
- package/dist/net/inet-address.js +0 -42
- package/dist/net/inet-address.js.map +0 -1
- package/dist/net/inet-endpoint.d.ts +0 -7
- package/dist/net/inet-endpoint.d.ts.map +0 -1
- package/dist/net/inet-endpoint.js +0 -2
- package/dist/net/inet-endpoint.js.map +0 -1
- package/dist/shell/fs/escape-posix-path.d.ts.map +0 -1
- package/dist/shell/fs/escape-posix-path.js.map +0 -1
- package/dist/shell/fs/escape-win32-path.d.ts.map +0 -1
- package/dist/shell/fs/escape-win32-path.js.map +0 -1
- package/dist/shell/process/parse-env-variable.d.ts +0 -43
- package/dist/shell/process/parse-env-variable.d.ts.map +0 -1
- package/dist/shell/process/parse-env-variable.js +0 -109
- package/dist/shell/process/parse-env-variable.js.map +0 -1
- package/dist/shell/process/stringify-env-variable.d.ts +0 -50
- package/dist/shell/process/stringify-env-variable.d.ts.map +0 -1
- package/dist/shell/process/stringify-env-variable.js +0 -86
- package/dist/shell/process/stringify-env-variable.js.map +0 -1
- package/dist/shell/process/types.d.ts +0 -7
- package/dist/shell/process/types.d.ts.map +0 -1
- package/dist/shell/process/types.js +0 -2
- package/dist/shell/process/types.js.map +0 -1
- package/dist/shell/shell/escape-posix-sh-command-arg.d.ts +0 -20
- package/dist/shell/shell/escape-posix-sh-command-arg.d.ts.map +0 -1
- package/dist/shell/shell/escape-posix-sh-command-arg.js +0 -26
- package/dist/shell/shell/escape-posix-sh-command-arg.js.map +0 -1
- package/dist/shell/shell/escape-posix-sh-command.d.ts +0 -19
- package/dist/shell/shell/escape-posix-sh-command.d.ts.map +0 -1
- package/dist/shell/shell/escape-posix-sh-command.js +0 -55
- package/dist/shell/shell/escape-posix-sh-command.js.map +0 -1
- package/dist/shell/shell/escape-posix-sh-sqe.d.ts +0 -13
- package/dist/shell/shell/escape-posix-sh-sqe.d.ts.map +0 -1
- package/dist/shell/shell/escape-posix-sh-sqe.js +0 -15
- package/dist/shell/shell/escape-posix-sh-sqe.js.map +0 -1
- package/dist/shell/shell/escape-win32-cmd-command-arg.d.ts +0 -20
- package/dist/shell/shell/escape-win32-cmd-command-arg.d.ts.map +0 -1
- package/dist/shell/shell/escape-win32-cmd-command-arg.js +0 -29
- package/dist/shell/shell/escape-win32-cmd-command-arg.js.map +0 -1
- package/dist/shell/shell/escape-win32-cmd-command.d.ts +0 -18
- package/dist/shell/shell/escape-win32-cmd-command.d.ts.map +0 -1
- package/dist/shell/shell/escape-win32-cmd-command.js +0 -20
- package/dist/shell/shell/escape-win32-cmd-command.js.map +0 -1
- /package/dist/{shell → system}/fs/escape-posix-path.d.ts +0 -0
- /package/dist/{shell → system}/fs/escape-posix-path.js +0 -0
- /package/dist/{shell → system}/fs/escape-win32-path.d.ts +0 -0
- /package/dist/{shell → system}/fs/escape-win32-path.js +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# @ac-kit/core
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a5c4d66: **Breaking:** `bigIntToBytesBe` and `bigIntFromBytesBe` move from
|
|
8
|
+
`@ac-kit/math-integer` to `@ac-kit/core`. Update the import specifier; the
|
|
9
|
+
behaviour is unchanged.
|
|
10
|
+
|
|
11
|
+
They are a wire encoding rather than arithmetic — X.690 §8.3 for an ASN.1
|
|
12
|
+
INTEGER, and what `BigInteger.toByteArray` and `int.to_bytes` produce — and
|
|
13
|
+
their callers need no integer theory at all, while `math-integer` sits too high
|
|
14
|
+
in the dependency graph for some of them to reach it.
|
|
15
|
+
|
|
16
|
+
New in `@ac-kit/core`: `bigIntToBytesLe` and `bigIntFromBytesLe`, the same
|
|
17
|
+
two's-complement, minimal-or-fixed-width encoding with the least significant
|
|
18
|
+
byte first.
|
|
19
|
+
|
|
20
|
+
`@ac-kit/format-asn1` no longer depends on `@ac-kit/math-integer`.
|
|
21
|
+
- a5c4d66: - **Breaking:** `InetAddress`, `InetEndpoint` and `composeInetAddress` are gone,
|
|
22
|
+
and so are `EPHEMERAL_PORT_MIN_VALUE`, `EPHEMERAL_PORT_MAX_VALUE` and
|
|
23
|
+
`getRandomEphemeralPort`. `core` holds language extensions and wrappers over
|
|
24
|
+
simple Web APIs, and `ARCHITECTURE.md` §3 names IP addressing as the example
|
|
25
|
+
of something pure that is nonetheless domain knowledge. The first three are
|
|
26
|
+
now `@ac-kit/node`'s, where `composeInetAddress` is spelled `toInetAddress`;
|
|
27
|
+
the ephemeral port range is `@ac-kit/net-address`'s, beside the rest of the
|
|
28
|
+
RFC 6335 port semantics. No compatibility re-export is left behind.
|
|
29
|
+
- New `flattenRecord(source, options)` and `unflattenRecord(source, options)`,
|
|
30
|
+
collapsing a nested record to delimiter-joined keys and back. A multi-segment
|
|
31
|
+
path can never reach `__proto__`, `constructor` or `prototype`; a
|
|
32
|
+
single-segment key is a leaf and is kept as one, because a record of
|
|
33
|
+
environment variables should still be able to hold one called `constructor`.
|
|
34
|
+
An array is a leaf value by default rather than being numbered, since an index
|
|
35
|
+
is the one segment a flattened key cannot tell apart from an ordinary key
|
|
36
|
+
spelled `"0"`. A key that itself contains the delimiter is not escaped and the
|
|
37
|
+
delimiter wins on the way back, so the round trip holds exactly for keys that
|
|
38
|
+
do not contain one.
|
|
39
|
+
- New `bytesMap(bytes, map)` and `bytesCombine(a, b, combine)`, applying a
|
|
40
|
+
function to every octet of one array or to every octet pair of two. Both mask
|
|
41
|
+
the callback's result to a single octet, so `~byte` and `left & right` read as
|
|
42
|
+
the bitwise operations they are rather than trailing an `& 0xff` that is easy
|
|
43
|
+
to forget and silent when it is. `bytesCombine` throws on mismatched lengths
|
|
44
|
+
instead of pairing up to the shorter array: a bitwise operation over two
|
|
45
|
+
different widths has no meaning, and truncating to the shorter one turns that
|
|
46
|
+
into a wrong answer rather than an error.
|
|
47
|
+
- New `nextUtf8Boundary(bytes, index)`, the first UTF-8 character boundary at or
|
|
48
|
+
after `index`. Slicing a UTF-8 buffer at an arbitrary offset — a tail, a
|
|
49
|
+
window, a chunk handed to `decodeText` — can land inside a multi-byte
|
|
50
|
+
sequence, whose orphaned tail decodes to a leading U+FFFD; aligning the offset
|
|
51
|
+
forward drops the partial character instead.
|
|
52
|
+
- Five more ASCII predicates: `isAsciiControl`, `isAsciiGraphic`,
|
|
53
|
+
`isAsciiPrintable`, `isAsciiPunctuation` and `isAsciiBlank` — C's `iscntrl`,
|
|
54
|
+
`isgraph`, `isprint`, `ispunct` and `isblank`, joining the `isalpha`/`isdigit`
|
|
55
|
+
family already here. Where `punct` stops and `graph` starts is exactly the kind
|
|
56
|
+
of boundary a hand-written range table gets subtly wrong, and every copy of it
|
|
57
|
+
gets it wrong differently.
|
|
58
|
+
|
|
59
|
+
## 0.2.0
|
|
60
|
+
|
|
61
|
+
### Minor Changes
|
|
62
|
+
|
|
63
|
+
- a493b4a: Clarify the object type guards, which were three near-synonyms with one honest
|
|
64
|
+
doc comment between them.
|
|
65
|
+
|
|
66
|
+
`isObject` and `isPojo` keep their names and behaviour and now say which
|
|
67
|
+
question each answers, and which sibling answers the other two. In short:
|
|
68
|
+
`isObject` asks whether there is a non-array object here at all; `isPojo` asks
|
|
69
|
+
whether it is a data bag, following the prototype chain; `hasObjectPrototype`
|
|
70
|
+
asks the same of the *own* prototype only, so `Object.create({})` fails it.
|
|
71
|
+
|
|
72
|
+
**Breaking:** `isPlainObject` is now `hasObjectPrototype`. The old name was a
|
|
73
|
+
trap — everywhere else in the ecosystem `isPlainObject` means what this package
|
|
74
|
+
calls `isPojo`, so a caller reaching for the familiar name got the strictest
|
|
75
|
+
check in the family. It was never exported from the barrel, so this only affects
|
|
76
|
+
a deep import.
|
|
77
|
+
- a493b4a: **Breaking:** the shell quoting and environment variable helpers have moved to
|
|
78
|
+
the new `@ac-kit/format-shell`.
|
|
79
|
+
|
|
80
|
+
Moved as-is: `escapePosixShSqe`, `escapePosixShCommandArg`,
|
|
81
|
+
`escapePosixShCommand`, `escapeWin32CmdCommandArg`, `escapeWin32CmdCommand`.
|
|
82
|
+
|
|
83
|
+
Moved and reshaped — see the `@ac-kit/format-shell` entry for why:
|
|
84
|
+
`stringifyEnvVariable` is `printEnvAssignment`, `stringifyEnvVariableValue` is
|
|
85
|
+
`printEnvValue`, `stringifyEnvVariableBoolValue` is `printEnvBoolValue`,
|
|
86
|
+
`parseEnvVariable` is `parseEnvAssignment`, and `parseEnvVariableValueAsBool`
|
|
87
|
+
and `parseEnvVariableValueAsNumber` drop `Variable` from their names.
|
|
88
|
+
`parseEnvVariableValue` and `parseEnvVariableValueAsString` are gone: parsing no
|
|
89
|
+
longer guesses a type, so `FOO=42` reads as `"42"` rather than `42`.
|
|
90
|
+
- a493b4a: Harden every object helper that writes a key it did not choose, and export the
|
|
91
|
+
two primitives the rest of the tree now uses.
|
|
92
|
+
|
|
93
|
+
- `setRecordEntry(record, key, value)` — assigns through `Object.defineProperty`
|
|
94
|
+
for `__proto__` and by plain assignment for everything else, so a record built
|
|
95
|
+
from parsed text can hold any key without reaching the prototype setter. The
|
|
96
|
+
record stays an ordinary object: same prototype, same spread, same
|
|
97
|
+
`deepEqual`.
|
|
98
|
+
- `isUnsafeRecordKey(key)` — true for `__proto__`, `constructor` and
|
|
99
|
+
`prototype`. A path walk needs this rather than `setRecordEntry`, because
|
|
100
|
+
stepping through `constructor` and then `prototype` pollutes on the *reads*,
|
|
101
|
+
before any assignment happens.
|
|
102
|
+
|
|
103
|
+
**Breaking:**
|
|
104
|
+
|
|
105
|
+
- `merge`, `mergeAll`, `mergeInplace`, `mergeAllInplace` and `defaults` now read
|
|
106
|
+
a source's **own** enumerable keys only. `for...in` previously walked the
|
|
107
|
+
source's prototype chain, which both leaked inherited properties into the
|
|
108
|
+
result and let `{"__proto__": …}` from `JSON.parse` replace `Object.prototype`.
|
|
109
|
+
- `setAtPath` refuses a path containing `__proto__`, `constructor` or
|
|
110
|
+
`prototype` and writes nothing, silently — the same way it already refused a
|
|
111
|
+
non-numeric index into an array. `getAtPath` is deliberately unchanged:
|
|
112
|
+
reading one of those hands back a prototype the caller could already reach
|
|
113
|
+
through any object it holds.
|
|
114
|
+
- 2ab5593: Add `nullIfEmpty`, normalizing an object with no own enumerable property to
|
|
115
|
+
`null`. Useful against APIs that report "no value" as an empty object, so that
|
|
116
|
+
callers only have one absent form to test.
|
|
117
|
+
- a493b4a: Add `parseNumberOrBigInt`, which reads a numeric literal out of text and widens
|
|
118
|
+
to `bigint` rather than rounding, and `bigIntIsSafeNumber`, the range test it
|
|
119
|
+
and `jsonMakeBigIntReplacerFunction` share.
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
parseNumberOrBigInt("42"); // 42
|
|
123
|
+
parseNumberOrBigInt("9007199254740993"); // 9007199254740993n
|
|
124
|
+
parseNumberOrBigInt("abc"); // null
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Reach for it where a human wrote the value — an environment variable, a config
|
|
128
|
+
field, a CLI argument. `bigIntParse` remains the right call when the value must
|
|
129
|
+
be an integer or the radix is known and not spelled in the text; it reports a
|
|
130
|
+
malformed input by throwing rather than by returning `null`.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes two's complement, big-endian bytes back into a `bigint` — the inverse
|
|
3
|
+
* of {@link bigIntToBytesBe}.
|
|
4
|
+
*
|
|
5
|
+
* The high bit of the first byte is the sign, so any width round-trips: `0xff`
|
|
6
|
+
* and `0xff_ff` both decode to `-1`. Reach for {@link bigIntFromBytesLe} when
|
|
7
|
+
* the least significant byte comes first.
|
|
8
|
+
*
|
|
9
|
+
* Time complexity: O(n) in the byte count.
|
|
10
|
+
*
|
|
11
|
+
* @param bytes - The encoding. An empty input decodes to zero.
|
|
12
|
+
*/
|
|
13
|
+
export declare function bigIntFromBytesBe(bytes: Uint8Array): bigint;
|
|
14
|
+
//# sourceMappingURL=from-bytes-be.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"from-bytes-be.d.ts","sourceRoot":"","sources":["../../src/big-int/from-bytes-be.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAQ3D"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes two's complement, big-endian bytes back into a `bigint` — the inverse
|
|
3
|
+
* of {@link bigIntToBytesBe}.
|
|
4
|
+
*
|
|
5
|
+
* The high bit of the first byte is the sign, so any width round-trips: `0xff`
|
|
6
|
+
* and `0xff_ff` both decode to `-1`. Reach for {@link bigIntFromBytesLe} when
|
|
7
|
+
* the least significant byte comes first.
|
|
8
|
+
*
|
|
9
|
+
* Time complexity: O(n) in the byte count.
|
|
10
|
+
*
|
|
11
|
+
* @param bytes - The encoding. An empty input decodes to zero.
|
|
12
|
+
*/
|
|
13
|
+
export function bigIntFromBytesBe(bytes) {
|
|
14
|
+
let value = 0n;
|
|
15
|
+
for (let index = 0; index < bytes.length; index++) {
|
|
16
|
+
value = (value << 8n) | BigInt(bytes[index]);
|
|
17
|
+
}
|
|
18
|
+
return BigInt.asIntN(bytes.length * 8, value);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=from-bytes-be.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"from-bytes-be.js","sourceRoot":"","sources":["../../src/big-int/from-bytes-be.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAiB;IAClD,IAAI,KAAK,GAAG,EAAE,CAAC;IAEf,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACnD,KAAK,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAE,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes two's complement, little-endian bytes back into a `bigint` — the
|
|
3
|
+
* inverse of {@link bigIntToBytesLe}.
|
|
4
|
+
*
|
|
5
|
+
* The high bit of the _last_ byte is the sign, so any width round-trips: `0xff`
|
|
6
|
+
* and `0xff_ff` both decode to `-1`. Reach for {@link bigIntFromBytesBe} when
|
|
7
|
+
* the most significant byte comes first, which is what wire formats usually
|
|
8
|
+
* specify.
|
|
9
|
+
*
|
|
10
|
+
* Time complexity: O(n) in the byte count.
|
|
11
|
+
*
|
|
12
|
+
* @param bytes - The encoding. An empty input decodes to zero.
|
|
13
|
+
*/
|
|
14
|
+
export declare function bigIntFromBytesLe(bytes: Uint8Array): bigint;
|
|
15
|
+
//# sourceMappingURL=from-bytes-le.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"from-bytes-le.d.ts","sourceRoot":"","sources":["../../src/big-int/from-bytes-le.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAQ3D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes two's complement, little-endian bytes back into a `bigint` — the
|
|
3
|
+
* inverse of {@link bigIntToBytesLe}.
|
|
4
|
+
*
|
|
5
|
+
* The high bit of the _last_ byte is the sign, so any width round-trips: `0xff`
|
|
6
|
+
* and `0xff_ff` both decode to `-1`. Reach for {@link bigIntFromBytesBe} when
|
|
7
|
+
* the most significant byte comes first, which is what wire formats usually
|
|
8
|
+
* specify.
|
|
9
|
+
*
|
|
10
|
+
* Time complexity: O(n) in the byte count.
|
|
11
|
+
*
|
|
12
|
+
* @param bytes - The encoding. An empty input decodes to zero.
|
|
13
|
+
*/
|
|
14
|
+
export function bigIntFromBytesLe(bytes) {
|
|
15
|
+
let value = 0n;
|
|
16
|
+
for (let index = bytes.length - 1; index >= 0; index--) {
|
|
17
|
+
value = (value << 8n) | BigInt(bytes[index]);
|
|
18
|
+
}
|
|
19
|
+
return BigInt.asIntN(bytes.length * 8, value);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=from-bytes-le.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"from-bytes-le.js","sourceRoot":"","sources":["../../src/big-int/from-bytes-le.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAiB;IAClD,IAAI,KAAK,GAAG,EAAE,CAAC;IAEf,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACxD,KAAK,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAE,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check whether converting a `bigint` to a `number` is exact.
|
|
3
|
+
*
|
|
4
|
+
* True when the value lies within `Number.MIN_SAFE_INTEGER` and
|
|
5
|
+
* `Number.MAX_SAFE_INTEGER` inclusive, which is exactly the range where
|
|
6
|
+
* `Number(value)` round-trips. Outside it, `Number(value)` still succeeds and
|
|
7
|
+
* still returns a finite result — it just returns the wrong one — so a caller
|
|
8
|
+
* narrowing a `bigint` for presentation or arithmetic has to ask first.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* bigIntIsSafeNumber(9007199254740991n); // true
|
|
13
|
+
* bigIntIsSafeNumber(9007199254740992n); // false
|
|
14
|
+
* ```;
|
|
15
|
+
*
|
|
16
|
+
* @param value The value to check.
|
|
17
|
+
* @returns True if `Number(value)` loses nothing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function bigIntIsSafeNumber(value: bigint): boolean;
|
|
20
|
+
//# sourceMappingURL=is-safe-number.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-safe-number.d.ts","sourceRoot":"","sources":["../../src/big-int/is-safe-number.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEzD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const MIN_SAFE_ = BigInt(Number.MIN_SAFE_INTEGER);
|
|
2
|
+
const MAX_SAFE_ = BigInt(Number.MAX_SAFE_INTEGER);
|
|
3
|
+
/**
|
|
4
|
+
* Check whether converting a `bigint` to a `number` is exact.
|
|
5
|
+
*
|
|
6
|
+
* True when the value lies within `Number.MIN_SAFE_INTEGER` and
|
|
7
|
+
* `Number.MAX_SAFE_INTEGER` inclusive, which is exactly the range where
|
|
8
|
+
* `Number(value)` round-trips. Outside it, `Number(value)` still succeeds and
|
|
9
|
+
* still returns a finite result — it just returns the wrong one — so a caller
|
|
10
|
+
* narrowing a `bigint` for presentation or arithmetic has to ask first.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* bigIntIsSafeNumber(9007199254740991n); // true
|
|
15
|
+
* bigIntIsSafeNumber(9007199254740992n); // false
|
|
16
|
+
* ```;
|
|
17
|
+
*
|
|
18
|
+
* @param value The value to check.
|
|
19
|
+
* @returns True if `Number(value)` loses nothing.
|
|
20
|
+
*/
|
|
21
|
+
export function bigIntIsSafeNumber(value) {
|
|
22
|
+
return value >= MIN_SAFE_ && value <= MAX_SAFE_;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=is-safe-number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-safe-number.js","sourceRoot":"","sources":["../../src/big-int/is-safe-number.ts"],"names":[],"mappings":"AAAA,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAElD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC/C,OAAO,KAAK,IAAI,SAAS,IAAI,KAAK,IAAI,SAAS,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a `bigint` as two's complement, big-endian bytes.
|
|
3
|
+
*
|
|
4
|
+
* What Java's `BigInteger.toByteArray` and Python's `int.to_bytes` produce.
|
|
5
|
+
* Reach for {@link bigIntToBytesLe} when the least significant byte comes
|
|
6
|
+
* first, and for `@ac-kit/math-integer`'s `limb32`/`limb64` families when the
|
|
7
|
+
* digits feed arithmetic rather than a wire: those are little-endian, unsigned,
|
|
8
|
+
* and of fixed width.
|
|
9
|
+
*
|
|
10
|
+
* Time complexity: O(n) in the byte count.
|
|
11
|
+
*
|
|
12
|
+
* @param value - The value to encode. Zero encodes as a single `0x00`.
|
|
13
|
+
* @param byteLength - Fixed output width, sign-extended to fit. Omit for the
|
|
14
|
+
* minimal encoding.
|
|
15
|
+
* @returns A fresh buffer, never empty.
|
|
16
|
+
* @throws {RangeError} When `byteLength` is too small to hold `value`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function bigIntToBytesBe(value: bigint, byteLength?: number): Uint8Array<ArrayBuffer>;
|
|
19
|
+
//# sourceMappingURL=to-bytes-be.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-bytes-be.d.ts","sourceRoot":"","sources":["../../src/big-int/to-bytes-be.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAC9B,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,GACjB,UAAU,CAAC,WAAW,CAAC,CAqBzB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a `bigint` as two's complement, big-endian bytes.
|
|
3
|
+
*
|
|
4
|
+
* What Java's `BigInteger.toByteArray` and Python's `int.to_bytes` produce.
|
|
5
|
+
* Reach for {@link bigIntToBytesLe} when the least significant byte comes
|
|
6
|
+
* first, and for `@ac-kit/math-integer`'s `limb32`/`limb64` families when the
|
|
7
|
+
* digits feed arithmetic rather than a wire: those are little-endian, unsigned,
|
|
8
|
+
* and of fixed width.
|
|
9
|
+
*
|
|
10
|
+
* Time complexity: O(n) in the byte count.
|
|
11
|
+
*
|
|
12
|
+
* @param value - The value to encode. Zero encodes as a single `0x00`.
|
|
13
|
+
* @param byteLength - Fixed output width, sign-extended to fit. Omit for the
|
|
14
|
+
* minimal encoding.
|
|
15
|
+
* @returns A fresh buffer, never empty.
|
|
16
|
+
* @throws {RangeError} When `byteLength` is too small to hold `value`.
|
|
17
|
+
*/
|
|
18
|
+
export function bigIntToBytesBe(value, byteLength) {
|
|
19
|
+
const minimal = toMinimalBytes(value);
|
|
20
|
+
if (byteLength === undefined) {
|
|
21
|
+
return minimal;
|
|
22
|
+
}
|
|
23
|
+
if (minimal.length > byteLength) {
|
|
24
|
+
throw new RangeError(`bigIntToBytesBe: ${value} needs ${minimal.length} bytes, not ${byteLength}`);
|
|
25
|
+
}
|
|
26
|
+
const out = new Uint8Array(byteLength);
|
|
27
|
+
const padding = byteLength - minimal.length;
|
|
28
|
+
// Sign extension, not zero padding: a negative value's high bytes are 0xff.
|
|
29
|
+
out.fill(value < 0n ? 0xff : 0x00, 0, padding);
|
|
30
|
+
out.set(minimal, padding);
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
function toMinimalBytes(value) {
|
|
34
|
+
if (value === 0n) {
|
|
35
|
+
return new Uint8Array([0x00]);
|
|
36
|
+
}
|
|
37
|
+
const negative = value < 0n;
|
|
38
|
+
// For a negative, encode |value| - 1 and invert: that is two's complement
|
|
39
|
+
// without ever needing to know the final width up front.
|
|
40
|
+
let remaining = negative ? -value - 1n : value;
|
|
41
|
+
const digits = [];
|
|
42
|
+
while (remaining > 0n) {
|
|
43
|
+
digits.unshift(Number(remaining & 0xffn));
|
|
44
|
+
remaining >>= 8n;
|
|
45
|
+
}
|
|
46
|
+
if (negative) {
|
|
47
|
+
for (let index = 0; index < digits.length; index++) {
|
|
48
|
+
digits[index] = ~digits[index] & 0xff;
|
|
49
|
+
}
|
|
50
|
+
// A leading byte without its high bit set would read back as positive.
|
|
51
|
+
if (digits.length === 0 || (digits[0] & 0x80) === 0) {
|
|
52
|
+
digits.unshift(0xff);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if ((digits[0] & 0x80) !== 0) {
|
|
56
|
+
digits.unshift(0x00);
|
|
57
|
+
}
|
|
58
|
+
return new Uint8Array(digits);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=to-bytes-be.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-bytes-be.js","sourceRoot":"","sources":["../../src/big-int/to-bytes-be.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,eAAe,CAC9B,KAAa,EACb,UAAmB;IAEnB,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAEtC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,UAAU,EAAE,CAAC;QACjC,MAAM,IAAI,UAAU,CACnB,oBAAoB,KAAK,UAAU,OAAO,CAAC,MAAM,eAAe,UAAU,EAAE,CAC5E,CAAC;IACH,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAE5C,4EAA4E;IAC5E,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IAC/C,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE1B,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,SAAS,cAAc,CAAC,KAAa;IACpC,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QAClB,OAAO,IAAI,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,QAAQ,GAAG,KAAK,GAAG,EAAE,CAAC;IAC5B,0EAA0E;IAC1E,yDAAyD;IACzD,IAAI,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAC/C,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,OAAO,SAAS,GAAG,EAAE,EAAE,CAAC;QACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC;QAC1C,SAAS,KAAK,EAAE,CAAC;IAClB,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACd,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YACpD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAE,GAAG,IAAI,CAAC;QACxC,CAAC;QAED,uEAAuE;QACvE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACtD,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC;IACF,CAAC;SAAM,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACtC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a `bigint` as two's complement, little-endian bytes.
|
|
3
|
+
*
|
|
4
|
+
* The byte order native to x86 and ARM, and what Python's `int.to_bytes(…,
|
|
5
|
+
* "little")` produces. Reach for {@link bigIntToBytesBe} when the most
|
|
6
|
+
* significant byte comes first, which is what wire formats usually specify, and
|
|
7
|
+
* for `@ac-kit/math-integer`'s `limb32`/`limb64` families when the digits feed
|
|
8
|
+
* arithmetic rather than a buffer: those are wider, unsigned, and of fixed
|
|
9
|
+
* width.
|
|
10
|
+
*
|
|
11
|
+
* Time complexity: O(n) in the byte count.
|
|
12
|
+
*
|
|
13
|
+
* @param value - The value to encode. Zero encodes as a single `0x00`. @param
|
|
14
|
+
* byteLength - Fixed output width, sign-extended to fit. Omit for the minimal
|
|
15
|
+
* encoding. @returns A fresh buffer, never empty. @throws {RangeError} When
|
|
16
|
+
* `byteLength` is too small to hold `value`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function bigIntToBytesLe(value: bigint, byteLength?: number): Uint8Array<ArrayBuffer>;
|
|
19
|
+
//# sourceMappingURL=to-bytes-le.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-bytes-le.d.ts","sourceRoot":"","sources":["../../src/big-int/to-bytes-le.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAC9B,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,GACjB,UAAU,CAAC,WAAW,CAAC,CAEzB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { bigIntToBytesBe } from "./to-bytes-be.js";
|
|
2
|
+
/**
|
|
3
|
+
* Encodes a `bigint` as two's complement, little-endian bytes.
|
|
4
|
+
*
|
|
5
|
+
* The byte order native to x86 and ARM, and what Python's `int.to_bytes(…,
|
|
6
|
+
* "little")` produces. Reach for {@link bigIntToBytesBe} when the most
|
|
7
|
+
* significant byte comes first, which is what wire formats usually specify, and
|
|
8
|
+
* for `@ac-kit/math-integer`'s `limb32`/`limb64` families when the digits feed
|
|
9
|
+
* arithmetic rather than a buffer: those are wider, unsigned, and of fixed
|
|
10
|
+
* width.
|
|
11
|
+
*
|
|
12
|
+
* Time complexity: O(n) in the byte count.
|
|
13
|
+
*
|
|
14
|
+
* @param value - The value to encode. Zero encodes as a single `0x00`. @param
|
|
15
|
+
* byteLength - Fixed output width, sign-extended to fit. Omit for the minimal
|
|
16
|
+
* encoding. @returns A fresh buffer, never empty. @throws {RangeError} When
|
|
17
|
+
* `byteLength` is too small to hold `value`.
|
|
18
|
+
*/
|
|
19
|
+
export function bigIntToBytesLe(value, byteLength) {
|
|
20
|
+
return bigIntToBytesBe(value, byteLength).reverse();
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=to-bytes-le.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-bytes-le.js","sourceRoot":"","sources":["../../src/big-int/to-bytes-le.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,eAAe,CAC9B,KAAa,EACb,UAAmB;IAEnB,OAAO,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies `combine` to each octet pair of two equal-length arrays.
|
|
3
|
+
*
|
|
4
|
+
* The result of `combine` is masked to one octet. Pairing stops at the shorter
|
|
5
|
+
* array only when lengths are allowed to differ, which they are not here: a
|
|
6
|
+
* bitwise operation over mismatched widths has no meaning, so it throws rather
|
|
7
|
+
* than silently truncating.
|
|
8
|
+
*
|
|
9
|
+
* Complexity: O(n) time and O(n) memory in the input length.
|
|
10
|
+
*
|
|
11
|
+
* @param a The left octets.
|
|
12
|
+
* @param b The right octets.
|
|
13
|
+
* @param combine Called with each octet pair and its index.
|
|
14
|
+
* @returns A new array of the same length.
|
|
15
|
+
* @throws RangeError When the two arrays differ in length.
|
|
16
|
+
*/
|
|
17
|
+
export declare function bytesCombine(a: Uint8Array, b: Uint8Array, combine: (left: number, right: number, index: number) => number): Uint8Array<ArrayBuffer>;
|
|
18
|
+
//# sourceMappingURL=bytes-combine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes-combine.d.ts","sourceRoot":"","sources":["../../src/buffer/bytes-combine.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC3B,CAAC,EAAE,UAAU,EACb,CAAC,EAAE,UAAU,EACb,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAC7D,UAAU,CAAC,WAAW,CAAC,CASzB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { bytesMap } from "./bytes-map.js";
|
|
2
|
+
/**
|
|
3
|
+
* Applies `combine` to each octet pair of two equal-length arrays.
|
|
4
|
+
*
|
|
5
|
+
* The result of `combine` is masked to one octet. Pairing stops at the shorter
|
|
6
|
+
* array only when lengths are allowed to differ, which they are not here: a
|
|
7
|
+
* bitwise operation over mismatched widths has no meaning, so it throws rather
|
|
8
|
+
* than silently truncating.
|
|
9
|
+
*
|
|
10
|
+
* Complexity: O(n) time and O(n) memory in the input length.
|
|
11
|
+
*
|
|
12
|
+
* @param a The left octets.
|
|
13
|
+
* @param b The right octets.
|
|
14
|
+
* @param combine Called with each octet pair and its index.
|
|
15
|
+
* @returns A new array of the same length.
|
|
16
|
+
* @throws RangeError When the two arrays differ in length.
|
|
17
|
+
*/
|
|
18
|
+
export function bytesCombine(a, b, combine) {
|
|
19
|
+
if (a.length !== b.length) {
|
|
20
|
+
throw new RangeError(`cannot combine ${a.length} octets with ${b.length} octets`);
|
|
21
|
+
}
|
|
22
|
+
// Non-null: `index` runs over `a`'s length, and `b` has been checked equal.
|
|
23
|
+
return bytesMap(a, (byte, index) => combine(byte, b[index], index));
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=bytes-combine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes-combine.js","sourceRoot":"","sources":["../../src/buffer/bytes-combine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,YAAY,CAC3B,CAAa,EACb,CAAa,EACb,OAA+D;IAE/D,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC3B,MAAM,IAAI,UAAU,CACnB,kBAAkB,CAAC,CAAC,MAAM,gBAAgB,CAAC,CAAC,MAAM,SAAS,CAC3D,CAAC;IACH,CAAC;IAED,4EAA4E;IAC5E,OAAO,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAE,EAAE,KAAK,CAAC,CAAC,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies `map` to every octet of `bytes`, returning a new array.
|
|
3
|
+
*
|
|
4
|
+
* The result of `map` is masked to one octet, so a caller may write `~byte`
|
|
5
|
+
* without restating `& 0xff`.
|
|
6
|
+
*
|
|
7
|
+
* Complexity: O(n) time and O(n) memory in the input length.
|
|
8
|
+
*
|
|
9
|
+
* @param bytes The source octets.
|
|
10
|
+
* @param map Called with each octet and its index.
|
|
11
|
+
* @returns A new array of the same length.
|
|
12
|
+
*/
|
|
13
|
+
export declare function bytesMap(bytes: Uint8Array, map: (byte: number, index: number) => number): Uint8Array<ArrayBuffer>;
|
|
14
|
+
//# sourceMappingURL=bytes-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes-map.d.ts","sourceRoot":"","sources":["../../src/buffer/bytes-map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CACvB,KAAK,EAAE,UAAU,EACjB,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAC1C,UAAU,CAAC,WAAW,CAAC,CASzB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies `map` to every octet of `bytes`, returning a new array.
|
|
3
|
+
*
|
|
4
|
+
* The result of `map` is masked to one octet, so a caller may write `~byte`
|
|
5
|
+
* without restating `& 0xff`.
|
|
6
|
+
*
|
|
7
|
+
* Complexity: O(n) time and O(n) memory in the input length.
|
|
8
|
+
*
|
|
9
|
+
* @param bytes The source octets.
|
|
10
|
+
* @param map Called with each octet and its index.
|
|
11
|
+
* @returns A new array of the same length.
|
|
12
|
+
*/
|
|
13
|
+
export function bytesMap(bytes, map) {
|
|
14
|
+
const result = new Uint8Array(bytes.length);
|
|
15
|
+
for (let index = 0; index < bytes.length; index++) {
|
|
16
|
+
// Non-null: `index` runs over the source array's own length.
|
|
17
|
+
result[index] = map(bytes[index], index) & 0xff;
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=bytes-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes-map.js","sourceRoot":"","sources":["../../src/buffer/bytes-map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,QAAQ,CACvB,KAAiB,EACjB,GAA4C;IAE5C,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAE5C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACnD,6DAA6D;QAC7D,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAE,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;IAClD,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index of the first UTF-8 character boundary at or after `index`.
|
|
3
|
+
*
|
|
4
|
+
* Slicing a UTF-8 buffer at an arbitrary offset can land inside a multi-byte
|
|
5
|
+
* sequence, whose orphaned tail decodes to a leading U+FFFD. Moving the offset
|
|
6
|
+
* forward to a boundary drops the partial character instead.
|
|
7
|
+
*
|
|
8
|
+
* Runs in O(1) on valid input — a sequence is at most four bytes long, so at
|
|
9
|
+
* most three continuation bytes are skipped — and in O(n) on the length of a
|
|
10
|
+
* malformed continuation run. Allocates nothing.
|
|
11
|
+
*
|
|
12
|
+
* @param bytes - UTF-8 encoded bytes.
|
|
13
|
+
* @param index - Offset to align. Negative values align to `0`.
|
|
14
|
+
* @returns The aligned offset, within `[0, bytes.length]`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function nextUtf8Boundary(bytes: Uint8Array, index: number): number;
|
|
17
|
+
//# sourceMappingURL=next-utf8-boundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-utf8-boundary.d.ts","sourceRoot":"","sources":["../../../src/buffer/text/next-utf8-boundary.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAWzE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// A UTF-8 continuation byte is `0b10xxxxxx`; every other byte starts a character.
|
|
2
|
+
const CONTINUATION_MASK_ = 192;
|
|
3
|
+
const CONTINUATION_BITS_ = 128;
|
|
4
|
+
/**
|
|
5
|
+
* Index of the first UTF-8 character boundary at or after `index`.
|
|
6
|
+
*
|
|
7
|
+
* Slicing a UTF-8 buffer at an arbitrary offset can land inside a multi-byte
|
|
8
|
+
* sequence, whose orphaned tail decodes to a leading U+FFFD. Moving the offset
|
|
9
|
+
* forward to a boundary drops the partial character instead.
|
|
10
|
+
*
|
|
11
|
+
* Runs in O(1) on valid input — a sequence is at most four bytes long, so at
|
|
12
|
+
* most three continuation bytes are skipped — and in O(n) on the length of a
|
|
13
|
+
* malformed continuation run. Allocates nothing.
|
|
14
|
+
*
|
|
15
|
+
* @param bytes - UTF-8 encoded bytes.
|
|
16
|
+
* @param index - Offset to align. Negative values align to `0`.
|
|
17
|
+
* @returns The aligned offset, within `[0, bytes.length]`.
|
|
18
|
+
*/
|
|
19
|
+
export function nextUtf8Boundary(bytes, index) {
|
|
20
|
+
let boundary = Math.max(0, index);
|
|
21
|
+
while (boundary < bytes.length &&
|
|
22
|
+
(bytes[boundary] & CONTINUATION_MASK_) === CONTINUATION_BITS_) {
|
|
23
|
+
boundary++;
|
|
24
|
+
}
|
|
25
|
+
return Math.min(boundary, bytes.length);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=next-utf8-boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-utf8-boundary.js","sourceRoot":"","sources":["../../../src/buffer/text/next-utf8-boundary.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,kBAAkB,GAAG,GAAW,CAAC;AACvC,MAAM,kBAAkB,GAAG,GAAW,CAAC;AAEvC;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAiB,EAAE,KAAa;IAChE,IAAI,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAElC,OACC,QAAQ,GAAG,KAAK,CAAC,MAAM;QACvB,CAAC,KAAK,CAAC,QAAQ,CAAE,GAAG,kBAAkB,CAAC,KAAK,kBAAkB,EAC7D,CAAC;QACF,QAAQ,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check whether a value's own prototype is `Object.prototype` or `null`.
|
|
3
|
+
*
|
|
4
|
+
* Strictly narrower than `isPojo`, which follows the whole prototype chain and
|
|
5
|
+
* so also accepts `Object.create({})`. Both ask "is this a data bag"; this one
|
|
6
|
+
* refuses a bag that inherits from another bag.
|
|
7
|
+
*
|
|
8
|
+
* Reach for it when the answer decides how a value is _rebuilt_ rather than how
|
|
9
|
+
* it is read — a traversal that rewrites a node into a fresh `{}`, a serializer
|
|
10
|
+
* choosing between an object form and a tagged form. Inherited keys are lost by
|
|
11
|
+
* such a rebuild, so a chain-following test would claim a fidelity the output
|
|
12
|
+
* does not have. When you only mean to read own keys, `isPojo` is the more
|
|
13
|
+
* forgiving question; see `isObject` for the whole family.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* hasObjectPrototype({}); // true
|
|
18
|
+
* hasObjectPrototype(Object.create(null)); // true
|
|
19
|
+
* hasObjectPrototype(Object.create({})); // false
|
|
20
|
+
* hasObjectPrototype(new Date()); // false
|
|
21
|
+
* ```;
|
|
22
|
+
*
|
|
23
|
+
* @param value The object to check.
|
|
24
|
+
* @returns True if nothing sits between the value and `Object.prototype`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function hasObjectPrototype(value: object): boolean;
|
|
27
|
+
//# sourceMappingURL=has-object-prototype.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-object-prototype.d.ts","sourceRoot":"","sources":["../../src/guards/has-object-prototype.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGzD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check whether a value's own prototype is `Object.prototype` or `null`.
|
|
3
|
+
*
|
|
4
|
+
* Strictly narrower than `isPojo`, which follows the whole prototype chain and
|
|
5
|
+
* so also accepts `Object.create({})`. Both ask "is this a data bag"; this one
|
|
6
|
+
* refuses a bag that inherits from another bag.
|
|
7
|
+
*
|
|
8
|
+
* Reach for it when the answer decides how a value is _rebuilt_ rather than how
|
|
9
|
+
* it is read — a traversal that rewrites a node into a fresh `{}`, a serializer
|
|
10
|
+
* choosing between an object form and a tagged form. Inherited keys are lost by
|
|
11
|
+
* such a rebuild, so a chain-following test would claim a fidelity the output
|
|
12
|
+
* does not have. When you only mean to read own keys, `isPojo` is the more
|
|
13
|
+
* forgiving question; see `isObject` for the whole family.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* hasObjectPrototype({}); // true
|
|
18
|
+
* hasObjectPrototype(Object.create(null)); // true
|
|
19
|
+
* hasObjectPrototype(Object.create({})); // false
|
|
20
|
+
* hasObjectPrototype(new Date()); // false
|
|
21
|
+
* ```;
|
|
22
|
+
*
|
|
23
|
+
* @param value The object to check.
|
|
24
|
+
* @returns True if nothing sits between the value and `Object.prototype`.
|
|
25
|
+
*/
|
|
26
|
+
export function hasObjectPrototype(value) {
|
|
27
|
+
const proto = Object.getPrototypeOf(value);
|
|
28
|
+
return proto === Object.prototype || proto === null;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=has-object-prototype.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-object-prototype.js","sourceRoot":"","sources":["../../src/guards/has-object-prototype.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC/C,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC3C,OAAO,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC"}
|