@kikiutils/shared 14.0.1 → 14.1.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/dist/buffer.d.ts +18 -19
- package/dist/buffer.d.ts.map +1 -1
- package/dist/buffer.js +22 -20
- package/dist/buffer.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/buffer.ts +23 -20
- package/src/types/index.ts +1 -1
package/dist/buffer.d.ts
CHANGED
|
@@ -4,34 +4,33 @@ import { Buffer } from "node:buffer";
|
|
|
4
4
|
//#region src/buffer.d.ts
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Converts
|
|
7
|
+
* Converts various binary data types to a Node.js Buffer.
|
|
8
8
|
*
|
|
9
|
-
* This function provides a unified way to convert
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* This function provides a unified, efficient way to convert different binary formats
|
|
10
|
+
* (Blob, Buffer, File, ArrayBuffer, or Uint8Array) into a Node.js Buffer.
|
|
11
|
+
* It prioritizes zero-copy conversions for TypedArrays and ArrayBuffers to ensure
|
|
12
|
+
* optimal performance.
|
|
12
13
|
*
|
|
13
|
-
* @param {Blob | Buffer | File} input - The input to convert
|
|
14
|
+
* @param {ArrayBuffer | Blob | Buffer | File | Uint8Array} input - The binary data input to convert.
|
|
15
|
+
* Supports Blob, Buffer, File, ArrayBuffer, and Uint8Array.
|
|
14
16
|
*
|
|
15
|
-
* @returns {Promise<Buffer>} A
|
|
17
|
+
* @returns {Promise<Buffer>} A promise that resolves to a Node.js Buffer.
|
|
16
18
|
*
|
|
17
19
|
* @example
|
|
18
20
|
* ```typescript
|
|
19
|
-
* import { toBuffer } from '@kikiutils/shared/
|
|
21
|
+
* import { toBuffer } from '@kikiutils/shared/buffer';
|
|
20
22
|
*
|
|
21
|
-
* //
|
|
22
|
-
* const
|
|
23
|
-
* const
|
|
24
|
-
* console.log(result1); // <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>
|
|
23
|
+
* // From ArrayBuffer
|
|
24
|
+
* const ab = new ArrayBuffer(8);
|
|
25
|
+
* const bufferFromAB = await toBuffer(ab);
|
|
25
26
|
*
|
|
26
|
-
* //
|
|
27
|
-
* const
|
|
28
|
-
* const
|
|
29
|
-
* console.log(result2.toString()); // 'Hello from Blob'
|
|
27
|
+
* // From Uint8Array (Zero-copy)
|
|
28
|
+
* const u8 = new Uint8Array([10, 20, 30]);
|
|
29
|
+
* const bufferFromU8 = await toBuffer(u8);
|
|
30
30
|
*
|
|
31
|
-
* //
|
|
32
|
-
* const
|
|
33
|
-
* const
|
|
34
|
-
* console.log(result3.toString()); // 'File content'
|
|
31
|
+
* // From Blob or File
|
|
32
|
+
* const blob = new Blob(['data'], { type: 'text/plain' });
|
|
33
|
+
* const bufferFromBlob = await toBuffer(blob);
|
|
35
34
|
* ```
|
|
36
35
|
*/
|
|
37
36
|
declare function toBuffer(input: BinaryInput): Promise<Buffer<ArrayBufferLike>>;
|
package/dist/buffer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.d.ts","names":[],"sources":["../src/buffer.ts"],"sourcesContent":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"buffer.d.ts","names":[],"sources":["../src/buffer.ts"],"sourcesContent":[],"mappings":";;;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAsB,QAAA,QAAgB,cAAW,QAAA,OAAA"}
|
package/dist/buffer.js
CHANGED
|
@@ -2,39 +2,41 @@ import { Buffer } from "node:buffer";
|
|
|
2
2
|
|
|
3
3
|
//#region src/buffer.ts
|
|
4
4
|
/**
|
|
5
|
-
* Converts
|
|
5
|
+
* Converts various binary data types to a Node.js Buffer.
|
|
6
6
|
*
|
|
7
|
-
* This function provides a unified way to convert
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* This function provides a unified, efficient way to convert different binary formats
|
|
8
|
+
* (Blob, Buffer, File, ArrayBuffer, or Uint8Array) into a Node.js Buffer.
|
|
9
|
+
* It prioritizes zero-copy conversions for TypedArrays and ArrayBuffers to ensure
|
|
10
|
+
* optimal performance.
|
|
10
11
|
*
|
|
11
|
-
* @param {Blob | Buffer | File} input - The input to convert
|
|
12
|
+
* @param {ArrayBuffer | Blob | Buffer | File | Uint8Array} input - The binary data input to convert.
|
|
13
|
+
* Supports Blob, Buffer, File, ArrayBuffer, and Uint8Array.
|
|
12
14
|
*
|
|
13
|
-
* @returns {Promise<Buffer>} A
|
|
15
|
+
* @returns {Promise<Buffer>} A promise that resolves to a Node.js Buffer.
|
|
14
16
|
*
|
|
15
17
|
* @example
|
|
16
18
|
* ```typescript
|
|
17
|
-
* import { toBuffer } from '@kikiutils/shared/
|
|
19
|
+
* import { toBuffer } from '@kikiutils/shared/buffer';
|
|
18
20
|
*
|
|
19
|
-
* //
|
|
20
|
-
* const
|
|
21
|
-
* const
|
|
22
|
-
* console.log(result1); // <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>
|
|
21
|
+
* // From ArrayBuffer
|
|
22
|
+
* const ab = new ArrayBuffer(8);
|
|
23
|
+
* const bufferFromAB = await toBuffer(ab);
|
|
23
24
|
*
|
|
24
|
-
* //
|
|
25
|
-
* const
|
|
26
|
-
* const
|
|
27
|
-
* console.log(result2.toString()); // 'Hello from Blob'
|
|
25
|
+
* // From Uint8Array (Zero-copy)
|
|
26
|
+
* const u8 = new Uint8Array([10, 20, 30]);
|
|
27
|
+
* const bufferFromU8 = await toBuffer(u8);
|
|
28
28
|
*
|
|
29
|
-
* //
|
|
30
|
-
* const
|
|
31
|
-
* const
|
|
32
|
-
* console.log(result3.toString()); // 'File content'
|
|
29
|
+
* // From Blob or File
|
|
30
|
+
* const blob = new Blob(['data'], { type: 'text/plain' });
|
|
31
|
+
* const bufferFromBlob = await toBuffer(blob);
|
|
33
32
|
* ```
|
|
34
33
|
*/
|
|
35
34
|
async function toBuffer(input) {
|
|
36
35
|
if (Buffer.isBuffer(input)) return input;
|
|
37
|
-
return Buffer.from(
|
|
36
|
+
if (input instanceof ArrayBuffer) return Buffer.from(input);
|
|
37
|
+
if (input instanceof Uint8Array) return Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
|
38
|
+
if (typeof input.arrayBuffer === "function") return Buffer.from(await input.arrayBuffer());
|
|
39
|
+
throw new TypeError("The provided input is not a supported binary type (Blob, Buffer, File, ArrayBuffer, or Uint8Array).");
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
//#endregion
|
package/dist/buffer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.js","names":[],"sources":["../src/buffer.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\n\nimport type { BinaryInput } from './types';\n\n/**\n * Converts
|
|
1
|
+
{"version":3,"file":"buffer.js","names":[],"sources":["../src/buffer.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\n\nimport type { BinaryInput } from './types';\n\n/**\n * Converts various binary data types to a Node.js Buffer.\n *\n * This function provides a unified, efficient way to convert different binary formats\n * (Blob, Buffer, File, ArrayBuffer, or Uint8Array) into a Node.js Buffer.\n * It prioritizes zero-copy conversions for TypedArrays and ArrayBuffers to ensure\n * optimal performance.\n *\n * @param {ArrayBuffer | Blob | Buffer | File | Uint8Array} input - The binary data input to convert.\n * Supports Blob, Buffer, File, ArrayBuffer, and Uint8Array.\n *\n * @returns {Promise<Buffer>} A promise that resolves to a Node.js Buffer.\n *\n * @example\n * ```typescript\n * import { toBuffer } from '@kikiutils/shared/buffer';\n *\n * // From ArrayBuffer\n * const ab = new ArrayBuffer(8);\n * const bufferFromAB = await toBuffer(ab);\n *\n * // From Uint8Array (Zero-copy)\n * const u8 = new Uint8Array([10, 20, 30]);\n * const bufferFromU8 = await toBuffer(u8);\n *\n * // From Blob or File\n * const blob = new Blob(['data'], { type: 'text/plain' });\n * const bufferFromBlob = await toBuffer(blob);\n * ```\n */\nexport async function toBuffer(input: BinaryInput) {\n if (Buffer.isBuffer(input)) return input;\n if (input instanceof ArrayBuffer) return Buffer.from(input);\n if (input instanceof Uint8Array) return Buffer.from(input.buffer, input.byteOffset, input.byteLength);\n if (typeof input.arrayBuffer === 'function') return Buffer.from(await input.arrayBuffer());\n // eslint-disable-next-line style/max-len\n throw new TypeError('The provided input is not a supported binary type (Blob, Buffer, File, ArrayBuffer, or Uint8Array).');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,eAAsB,SAAS,OAAoB;AAC/C,KAAI,OAAO,SAAS,MAAM,CAAE,QAAO;AACnC,KAAI,iBAAiB,YAAa,QAAO,OAAO,KAAK,MAAM;AAC3D,KAAI,iBAAiB,WAAY,QAAO,OAAO,KAAK,MAAM,QAAQ,MAAM,YAAY,MAAM,WAAW;AACrG,KAAI,OAAO,MAAM,gBAAgB,WAAY,QAAO,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAE1F,OAAM,IAAI,UAAU,sGAAsG"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Blob as Blob$1, Buffer, File as File$1 } from "node:buffer";
|
|
|
3
3
|
|
|
4
4
|
//#region src/types/index.d.ts
|
|
5
5
|
type AnyRecord = Record<string, any>;
|
|
6
|
-
type BinaryInput = Blob | Buffer | File | Blob$1 | File$1;
|
|
6
|
+
type BinaryInput = ArrayBuffer | Blob | Buffer | File | Blob$1 | File$1 | Uint8Array;
|
|
7
7
|
type Booleanish = 'false' | 'true' | boolean;
|
|
8
8
|
type MaybePartial<T> = Partial<T> | T;
|
|
9
9
|
type MaybeReadonly<T> = Readonly<T> | T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":[],"mappings":";;;;KAQY,SAAA,GAAY;KACZ,WAAA,GAAc,OAAO,SAAS,OAAO,SAAW;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":[],"mappings":";;;;KAQY,SAAA,GAAY;KACZ,WAAA,GAAc,cAAc,OAAO,SAAS,OAAO,SAAW,SAAW;AADzE,KAEA,UAAA,GAFS,OAAG,GAAM,MAAA,GAAA,OAAA;AAClB,KAEA,YAFW,CAAA,CAAA,CAAA,GAEO,OAFP,CAEe,CAFf,CAAA,GAEoB,CAFpB;AAAG,KAGd,aAHc,CAAA,CAAA,CAAA,GAGK,QAHL,CAGc,CAHd,CAAA,GAGmB,CAHnB;AAAc,KAI5B,QAJ4B,CAAA,CAAA,CAAA,GAAA,IAAA,GAIP,CAJO;AAAO,KAKnC,SAAA,GALmC,MAAA,GAAA,MAAA;AAAS,KAM5C,aAN4C,CAAA,UAAA,MAAA,GAAA,EAAA,CAAA,CAAA,GAMJ,OANI,CAMI,MANJ,CAMW,CANX,EAMc,CANd,CAAA,CAAA;AAAO,KAOnD,qBAPmD,CAAA,UAAA,MAAA,GAAA,EAAA,CAAA,CAAA,GAOH,QAPG,CAOM,aAPN,CAOoB,CAPpB,EAOuB,CAPvB,CAAA,CAAA;AAAW,KAQ9D,cAR8D,CAAA,UAAA,MAAA,GAAA,EAAA,CAAA,CAAA,GAQrB,QARqB,CAQZ,MARY,CAQL,CARK,EAQF,CARE,CAAA,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "14.0
|
|
4
|
+
"version": "14.1.0",
|
|
5
5
|
"description": "A lightweight and modular utility library for modern JavaScript and TypeScript — includes secure hashing, flexible logging, datetime tools, Vue/web helpers, storage abstraction, and more.",
|
|
6
6
|
"author": "kiki-kanri",
|
|
7
7
|
"license": "MIT",
|
|
@@ -170,7 +170,7 @@
|
|
|
170
170
|
"depcheck": "^1.4.7",
|
|
171
171
|
"element-plus": "^2.13.0",
|
|
172
172
|
"fs-extra": "^11.3.3",
|
|
173
|
-
"jsdom": "^27.
|
|
173
|
+
"jsdom": "^27.4.0",
|
|
174
174
|
"lru-cache": "^11.2.4",
|
|
175
175
|
"millify": "^6.1.0",
|
|
176
176
|
"msgpackr": "^1.11.8",
|
|
@@ -179,7 +179,7 @@
|
|
|
179
179
|
"pino-pretty": "^13.1.3",
|
|
180
180
|
"publint": "^0.3.16",
|
|
181
181
|
"ts-unused-exports": "^11.0.1",
|
|
182
|
-
"tsdown": "^0.18.
|
|
182
|
+
"tsdown": "^0.18.4",
|
|
183
183
|
"typescript": "^5.9.3",
|
|
184
184
|
"unplugin-unused": "^0.5.6",
|
|
185
185
|
"vitest": "^4.0.16",
|
package/src/buffer.ts
CHANGED
|
@@ -3,37 +3,40 @@ import { Buffer } from 'node:buffer';
|
|
|
3
3
|
import type { BinaryInput } from './types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Converts
|
|
6
|
+
* Converts various binary data types to a Node.js Buffer.
|
|
7
7
|
*
|
|
8
|
-
* This function provides a unified way to convert
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* This function provides a unified, efficient way to convert different binary formats
|
|
9
|
+
* (Blob, Buffer, File, ArrayBuffer, or Uint8Array) into a Node.js Buffer.
|
|
10
|
+
* It prioritizes zero-copy conversions for TypedArrays and ArrayBuffers to ensure
|
|
11
|
+
* optimal performance.
|
|
11
12
|
*
|
|
12
|
-
* @param {Blob | Buffer | File} input - The input to convert
|
|
13
|
+
* @param {ArrayBuffer | Blob | Buffer | File | Uint8Array} input - The binary data input to convert.
|
|
14
|
+
* Supports Blob, Buffer, File, ArrayBuffer, and Uint8Array.
|
|
13
15
|
*
|
|
14
|
-
* @returns {Promise<Buffer>} A
|
|
16
|
+
* @returns {Promise<Buffer>} A promise that resolves to a Node.js Buffer.
|
|
15
17
|
*
|
|
16
18
|
* @example
|
|
17
19
|
* ```typescript
|
|
18
|
-
* import { toBuffer } from '@kikiutils/shared/
|
|
20
|
+
* import { toBuffer } from '@kikiutils/shared/buffer';
|
|
19
21
|
*
|
|
20
|
-
* //
|
|
21
|
-
* const
|
|
22
|
-
* const
|
|
23
|
-
* console.log(result1); // <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>
|
|
22
|
+
* // From ArrayBuffer
|
|
23
|
+
* const ab = new ArrayBuffer(8);
|
|
24
|
+
* const bufferFromAB = await toBuffer(ab);
|
|
24
25
|
*
|
|
25
|
-
* //
|
|
26
|
-
* const
|
|
27
|
-
* const
|
|
28
|
-
* console.log(result2.toString()); // 'Hello from Blob'
|
|
26
|
+
* // From Uint8Array (Zero-copy)
|
|
27
|
+
* const u8 = new Uint8Array([10, 20, 30]);
|
|
28
|
+
* const bufferFromU8 = await toBuffer(u8);
|
|
29
29
|
*
|
|
30
|
-
* //
|
|
31
|
-
* const
|
|
32
|
-
* const
|
|
33
|
-
* console.log(result3.toString()); // 'File content'
|
|
30
|
+
* // From Blob or File
|
|
31
|
+
* const blob = new Blob(['data'], { type: 'text/plain' });
|
|
32
|
+
* const bufferFromBlob = await toBuffer(blob);
|
|
34
33
|
* ```
|
|
35
34
|
*/
|
|
36
35
|
export async function toBuffer(input: BinaryInput) {
|
|
37
36
|
if (Buffer.isBuffer(input)) return input;
|
|
38
|
-
return Buffer.from(
|
|
37
|
+
if (input instanceof ArrayBuffer) return Buffer.from(input);
|
|
38
|
+
if (input instanceof Uint8Array) return Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
|
39
|
+
if (typeof input.arrayBuffer === 'function') return Buffer.from(await input.arrayBuffer());
|
|
40
|
+
// eslint-disable-next-line style/max-len
|
|
41
|
+
throw new TypeError('The provided input is not a supported binary type (Blob, Buffer, File, ArrayBuffer, or Uint8Array).');
|
|
39
42
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
export type { FilteredKeyPath } from './filtered-key-path';
|
|
8
8
|
|
|
9
9
|
export type AnyRecord = Record<string, any>;
|
|
10
|
-
export type BinaryInput = Blob | Buffer | File | NodeBlob | NodeFile;
|
|
10
|
+
export type BinaryInput = ArrayBuffer | Blob | Buffer | File | NodeBlob | NodeFile | Uint8Array;
|
|
11
11
|
export type Booleanish = 'false' | 'true' | boolean;
|
|
12
12
|
export type MaybePartial<T> = Partial<T> | T;
|
|
13
13
|
export type MaybeReadonly<T> = Readonly<T> | T;
|