@stryke/convert 0.3.1 → 0.4.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/array-buffer-to-string.cjs +14 -0
- package/dist/array-buffer-to-string.d.ts +7 -0
- package/dist/array-buffer-to-string.mjs +1 -0
- package/dist/index.cjs +33 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +1 -1
- package/dist/string-to-uint8-array.cjs +15 -3
- package/dist/string-to-uint8-array.d.ts +15 -1
- package/dist/string-to-uint8-array.mjs +1 -1
- package/dist/uint8-array-to-stream.cjs +31 -0
- package/dist/uint8-array-to-stream.d.ts +21 -0
- package/dist/uint8-array-to-stream.mjs +1 -0
- package/dist/uint8-array-to-string.cjs +6 -1
- package/dist/uint8-array-to-string.d.ts +9 -2
- package/dist/uint8-array-to-string.mjs +1 -1
- package/package.json +32 -4
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.arrayBufferToString = arrayBufferToString;
|
|
7
|
+
function arrayBufferToString(a) {
|
|
8
|
+
const r = new Uint8Array(a),
|
|
9
|
+
t = r.byteLength;
|
|
10
|
+
if (t < 65535) return String.fromCharCode.apply(null, r);
|
|
11
|
+
let e = "";
|
|
12
|
+
for (let n = 0; n < t; n++) e += String.fromCharCode(r[n]);
|
|
13
|
+
return e;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function arrayBufferToString(a){const r=new Uint8Array(a),t=r.byteLength;if(t<65535)return String.fromCharCode.apply(null,r);let e="";for(let n=0;n<t;n++)e+=String.fromCharCode(r[n]);return e}
|
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _arrayBufferToString = require("./array-buffer-to-string.cjs");
|
|
7
|
+
Object.keys(_arrayBufferToString).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _arrayBufferToString[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _arrayBufferToString[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
6
17
|
var _bufferToString = require("./buffer-to-string.cjs");
|
|
7
18
|
Object.keys(_bufferToString).forEach(function (key) {
|
|
8
19
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -25,6 +36,17 @@ Object.keys(_parseTypeDefinition).forEach(function (key) {
|
|
|
25
36
|
}
|
|
26
37
|
});
|
|
27
38
|
});
|
|
39
|
+
var _stringToBuffer = require("./string-to-buffer.cjs");
|
|
40
|
+
Object.keys(_stringToBuffer).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _stringToBuffer[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _stringToBuffer[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
28
50
|
var _stringToUint8Array = require("./string-to-uint8-array.cjs");
|
|
29
51
|
Object.keys(_stringToUint8Array).forEach(function (key) {
|
|
30
52
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -58,6 +80,17 @@ Object.keys(_toStringKey).forEach(function (key) {
|
|
|
58
80
|
}
|
|
59
81
|
});
|
|
60
82
|
});
|
|
83
|
+
var _uint8ArrayToStream = require("./uint8-array-to-stream.cjs");
|
|
84
|
+
Object.keys(_uint8ArrayToStream).forEach(function (key) {
|
|
85
|
+
if (key === "default" || key === "__esModule") return;
|
|
86
|
+
if (key in exports && exports[key] === _uint8ArrayToStream[key]) return;
|
|
87
|
+
Object.defineProperty(exports, key, {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return _uint8ArrayToStream[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
61
94
|
var _uint8ArrayToString = require("./uint8-array-to-string.cjs");
|
|
62
95
|
Object.keys(_uint8ArrayToString).forEach(function (key) {
|
|
63
96
|
if (key === "default" || key === "__esModule") return;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*/
|
|
9
|
+
export * from "./array-buffer-to-string";
|
|
9
10
|
export * from "./buffer-to-string";
|
|
10
11
|
export * from "./parse-type-definition";
|
|
12
|
+
export * from "./string-to-buffer";
|
|
11
13
|
export * from "./string-to-uint8-array";
|
|
12
14
|
export * from "./to-array";
|
|
13
15
|
export * from "./to-string-key";
|
|
16
|
+
export * from "./uint8-array-to-stream";
|
|
14
17
|
export * from "./uint8-array-to-string";
|
|
15
18
|
export * from "./utf8-array-to-string";
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./buffer-to-string";export*from"./parse-type-definition";export*from"./string-to-uint8-array";export*from"./to-array";export*from"./to-string-key";export*from"./uint8-array-to-string";export*from"./utf8-array-to-string";
|
|
1
|
+
export*from"./array-buffer-to-string";export*from"./buffer-to-string";export*from"./parse-type-definition";export*from"./string-to-buffer";export*from"./string-to-uint8-array";export*from"./to-array";export*from"./to-string-key";export*from"./uint8-array-to-stream";export*from"./uint8-array-to-string";export*from"./utf8-array-to-string";
|
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
exports.stringToUint8Array = stringToUint8Array;
|
|
6
|
+
exports.base64StringToUint8Array = base64StringToUint8Array;
|
|
7
|
+
exports.binaryStringToUint8Array = binaryStringToUint8Array;
|
|
8
|
+
exports.stringToUint8Array = stringToUint8Array;
|
|
9
|
+
function stringToUint8Array(r) {
|
|
10
|
+
return Uint8Array.from([...encodeURIComponent(r)].map(n => n.codePointAt(0)));
|
|
11
|
+
}
|
|
12
|
+
function binaryStringToUint8Array(r) {
|
|
13
|
+
const n = r.length,
|
|
14
|
+
o = new Uint8Array(n);
|
|
15
|
+
for (let t = 0; t < n; t++) o[t] = r.charCodeAt(t);
|
|
16
|
+
return o;
|
|
17
|
+
}
|
|
18
|
+
function base64StringToUint8Array(r) {
|
|
19
|
+
return stringToUint8Array(atob(r));
|
|
20
|
+
}
|
|
@@ -4,4 +4,18 @@
|
|
|
4
4
|
* @param text - The text to convert
|
|
5
5
|
* @returns The converted Uint8Array
|
|
6
6
|
*/
|
|
7
|
-
export declare
|
|
7
|
+
export declare function stringToUint8Array(text: string): Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* Convert a binary string to Uint8Array
|
|
10
|
+
*
|
|
11
|
+
* @param binary - The binary string to convert
|
|
12
|
+
* @returns The converted Uint8Array
|
|
13
|
+
*/
|
|
14
|
+
export declare function binaryStringToUint8Array(binary: string): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* Convert a base64 string to a Uint8Array
|
|
17
|
+
*
|
|
18
|
+
* @param data - The base64 string to convert
|
|
19
|
+
* @returns The converted Uint8Array
|
|
20
|
+
*/
|
|
21
|
+
export declare function base64StringToUint8Array(data: string): Uint8Array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export function stringToUint8Array(r){return Uint8Array.from([...encodeURIComponent(r)].map(n=>n.codePointAt(0)))}export function binaryStringToUint8Array(r){const n=r.length,o=new Uint8Array(n);for(let t=0;t<n;t++)o[t]=r.charCodeAt(t);return o}export function base64StringToUint8Array(r){return stringToUint8Array(atob(r))}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.concatUint8Array = concatUint8Array;
|
|
7
|
+
exports.concatUint8ArrayStream = concatUint8ArrayStream;
|
|
8
|
+
exports.uint8ArrayToStream = uint8ArrayToStream;
|
|
9
|
+
function uint8ArrayToStream(r) {
|
|
10
|
+
return new ReadableStream({
|
|
11
|
+
start(t) {
|
|
12
|
+
t.enqueue(r), t.close();
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function concatUint8Array(r) {
|
|
17
|
+
let t = 0;
|
|
18
|
+
for (const n of r) t += n.length;
|
|
19
|
+
const e = new Uint8Array(t);
|
|
20
|
+
let a = 0;
|
|
21
|
+
for (const n of r) e.set(n, a), a += n.length;
|
|
22
|
+
return e;
|
|
23
|
+
}
|
|
24
|
+
async function concatUint8ArrayStream(r) {
|
|
25
|
+
const t = [];
|
|
26
|
+
return await r.pipeTo(new WritableStream({
|
|
27
|
+
write(e) {
|
|
28
|
+
t.push(e);
|
|
29
|
+
}
|
|
30
|
+
})), concatUint8Array(t);
|
|
31
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a Uint8Array to a ReadableStream
|
|
3
|
+
*
|
|
4
|
+
* @param data - The Uint8Array to convert
|
|
5
|
+
* @returns The converted ReadableStream
|
|
6
|
+
*/
|
|
7
|
+
export declare function uint8ArrayToStream(data: Uint8Array): ReadableStream<Uint8Array>;
|
|
8
|
+
/**
|
|
9
|
+
* Concatenate an array of Uint8Array chunks into a single Uint8Array
|
|
10
|
+
*
|
|
11
|
+
* @param chunks - Array of Uint8Array chunks to concatenate
|
|
12
|
+
* @returns The concatenated Uint8Array
|
|
13
|
+
*/
|
|
14
|
+
export declare function concatUint8Array(chunks: Uint8Array[]): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* Concatenate a ReadableStream of Uint8Array chunks into a single Uint8Array
|
|
17
|
+
*
|
|
18
|
+
* @param stream - The ReadableStream of Uint8Array chunks to concatenate
|
|
19
|
+
* @returns A promise that resolves to the concatenated Uint8Array
|
|
20
|
+
*/
|
|
21
|
+
export declare function concatUint8ArrayStream(stream: ReadableStream<Uint8Array>): Promise<Uint8Array>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function uint8ArrayToStream(r){return new ReadableStream({start(t){t.enqueue(r),t.close()}})}export function concatUint8Array(r){let t=0;for(const n of r)t+=n.length;const e=new Uint8Array(t);let a=0;for(const n of r)e.set(n,a),a+=n.length;return e}export async function concatUint8ArrayStream(r){const t=[];return await r.pipeTo(new WritableStream({write(e){t.push(e)}})),concatUint8Array(t)}
|
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.base64Uint8ArrayToString = base64Uint8ArrayToString;
|
|
6
7
|
exports.uint8ArrayToString = void 0;
|
|
7
8
|
var _nodeBuffer = require("node:buffer");
|
|
9
|
+
var _arrayBufferToString = require("./array-buffer-to-string.cjs");
|
|
8
10
|
const uint8ArrayToString = r => decodeURIComponent(_nodeBuffer.Buffer.from(r).toString("utf8"));
|
|
9
|
-
exports.uint8ArrayToString = uint8ArrayToString;
|
|
11
|
+
exports.uint8ArrayToString = uint8ArrayToString;
|
|
12
|
+
function base64Uint8ArrayToString(r) {
|
|
13
|
+
return btoa((0, _arrayBufferToString.arrayBufferToString)(r));
|
|
14
|
+
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Convert a
|
|
2
|
+
* Convert a Uint8Array array to string
|
|
3
3
|
*
|
|
4
4
|
* @see https://stackoverflow.com/a/41798356/1465919
|
|
5
5
|
* @see https://stackoverflow.com/a/36949791/1465919
|
|
6
6
|
*
|
|
7
|
-
* @param arr -
|
|
7
|
+
* @param arr - Uint8Array to convert
|
|
8
8
|
* @returns The converted string
|
|
9
9
|
*/
|
|
10
10
|
export declare const uint8ArrayToString: (arr: Uint8Array) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Convert a Uint8Array to a base64 string
|
|
13
|
+
*
|
|
14
|
+
* @param buffer - The Uint8Array to convert
|
|
15
|
+
* @returns The converted base64 string
|
|
16
|
+
*/
|
|
17
|
+
export declare function base64Uint8ArrayToString(buffer: Uint8Array): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Buffer as t}from"node:buffer";export const uint8ArrayToString=r=>decodeURIComponent(t.from(r).toString("utf8"));
|
|
1
|
+
import{Buffer as t}from"node:buffer";import{arrayBufferToString as o}from"./array-buffer-to-string";export const uint8ArrayToString=r=>decodeURIComponent(t.from(r).toString("utf8"));export function base64Uint8ArrayToString(r){return btoa(o(r))}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/convert",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A utility package that helps convert between different data types.",
|
|
6
6
|
"repository": {
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"devDependencies": { "@types/node": "^22.14.0" },
|
|
13
13
|
"publishConfig": { "access": "public" },
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@stryke/type-checks": "^0.3.
|
|
16
|
-
"@stryke/types": "^0.8.
|
|
15
|
+
"@stryke/type-checks": "^0.3.9",
|
|
16
|
+
"@stryke/types": "^0.8.9"
|
|
17
17
|
},
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"files": ["dist/**/*"],
|
|
@@ -86,6 +86,20 @@
|
|
|
86
86
|
"default": "./dist/uint8-array-to-string.mjs"
|
|
87
87
|
}
|
|
88
88
|
},
|
|
89
|
+
"./uint8-array-to-stream": {
|
|
90
|
+
"import": {
|
|
91
|
+
"types": "./dist/uint8-array-to-stream.d.ts",
|
|
92
|
+
"default": "./dist/uint8-array-to-stream.mjs"
|
|
93
|
+
},
|
|
94
|
+
"require": {
|
|
95
|
+
"types": "./dist/uint8-array-to-stream.d.ts",
|
|
96
|
+
"default": "./dist/uint8-array-to-stream.cjs"
|
|
97
|
+
},
|
|
98
|
+
"default": {
|
|
99
|
+
"types": "./dist/uint8-array-to-stream.d.ts",
|
|
100
|
+
"default": "./dist/uint8-array-to-stream.mjs"
|
|
101
|
+
}
|
|
102
|
+
},
|
|
89
103
|
"./to-string-key": {
|
|
90
104
|
"import": {
|
|
91
105
|
"types": "./dist/to-string-key.d.ts",
|
|
@@ -178,6 +192,20 @@
|
|
|
178
192
|
"default": "./dist/buffer-to-string.mjs"
|
|
179
193
|
}
|
|
180
194
|
},
|
|
195
|
+
"./array-buffer-to-string": {
|
|
196
|
+
"import": {
|
|
197
|
+
"types": "./dist/array-buffer-to-string.d.ts",
|
|
198
|
+
"default": "./dist/array-buffer-to-string.mjs"
|
|
199
|
+
},
|
|
200
|
+
"require": {
|
|
201
|
+
"types": "./dist/array-buffer-to-string.d.ts",
|
|
202
|
+
"default": "./dist/array-buffer-to-string.cjs"
|
|
203
|
+
},
|
|
204
|
+
"default": {
|
|
205
|
+
"types": "./dist/array-buffer-to-string.d.ts",
|
|
206
|
+
"default": "./dist/array-buffer-to-string.mjs"
|
|
207
|
+
}
|
|
208
|
+
},
|
|
181
209
|
".": {
|
|
182
210
|
"import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
|
|
183
211
|
"require": {
|
|
@@ -191,5 +219,5 @@
|
|
|
191
219
|
"main": "./dist/index.cjs",
|
|
192
220
|
"module": "./dist/index.mjs",
|
|
193
221
|
"types": "./dist/index.d.ts",
|
|
194
|
-
"gitHead": "
|
|
222
|
+
"gitHead": "fdcb844c7710325be3bd12a6eca54556dca05268"
|
|
195
223
|
}
|