@stryke/convert 0.3.2 → 0.5.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 +44 -0
- package/dist/index.d.ts +4 -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/string-to-utf8-array.cjs +10 -0
- package/dist/string-to-utf8-array.d.ts +7 -0
- package/dist/string-to-utf8-array.mjs +1 -0
- 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/dist/utf8-array-to-string.cjs +5 -3
- package/dist/utf8-array-to-string.d.ts +3 -6
- package/dist/utf8-array-to-string.mjs +1 -1
- package/package.json +44 -2
|
@@ -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;
|
|
@@ -36,6 +58,17 @@ Object.keys(_stringToUint8Array).forEach(function (key) {
|
|
|
36
58
|
}
|
|
37
59
|
});
|
|
38
60
|
});
|
|
61
|
+
var _stringToUtf8Array = require("./string-to-utf8-array.cjs");
|
|
62
|
+
Object.keys(_stringToUtf8Array).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _stringToUtf8Array[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () {
|
|
68
|
+
return _stringToUtf8Array[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
39
72
|
var _toArray = require("./to-array.cjs");
|
|
40
73
|
Object.keys(_toArray).forEach(function (key) {
|
|
41
74
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -58,6 +91,17 @@ Object.keys(_toStringKey).forEach(function (key) {
|
|
|
58
91
|
}
|
|
59
92
|
});
|
|
60
93
|
});
|
|
94
|
+
var _uint8ArrayToStream = require("./uint8-array-to-stream.cjs");
|
|
95
|
+
Object.keys(_uint8ArrayToStream).forEach(function (key) {
|
|
96
|
+
if (key === "default" || key === "__esModule") return;
|
|
97
|
+
if (key in exports && exports[key] === _uint8ArrayToStream[key]) return;
|
|
98
|
+
Object.defineProperty(exports, key, {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () {
|
|
101
|
+
return _uint8ArrayToStream[key];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
61
105
|
var _uint8ArrayToString = require("./uint8-array-to-string.cjs");
|
|
62
106
|
Object.keys(_uint8ArrayToString).forEach(function (key) {
|
|
63
107
|
if (key === "default" || key === "__esModule") return;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,14 @@
|
|
|
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";
|
|
14
|
+
export * from "./string-to-utf8-array";
|
|
12
15
|
export * from "./to-array";
|
|
13
16
|
export * from "./to-string-key";
|
|
17
|
+
export * from "./uint8-array-to-stream";
|
|
14
18
|
export * from "./uint8-array-to-string";
|
|
15
19
|
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"./string-to-utf8-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 @@
|
|
|
1
|
+
const r=new TextEncoder;export function stringToUtf8Array(n){return r.encode(n)}
|
|
@@ -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))}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.utf8ArrayToString =
|
|
7
|
-
const
|
|
8
|
-
|
|
6
|
+
exports.utf8ArrayToString = utf8ArrayToString;
|
|
7
|
+
const r = new TextDecoder();
|
|
8
|
+
function utf8ArrayToString(e) {
|
|
9
|
+
return r.decode(e);
|
|
10
|
+
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Convert a
|
|
2
|
+
* Convert a utf-8 array to string
|
|
3
3
|
*
|
|
4
|
-
* @
|
|
5
|
-
* @credits https://stackoverflow.com/a/36949791/1465919
|
|
6
|
-
*
|
|
7
|
-
* @param arr - Utf-8 Array
|
|
4
|
+
* @param input - Utf-8 Array
|
|
8
5
|
* @returns The converted string
|
|
9
6
|
*/
|
|
10
|
-
export declare
|
|
7
|
+
export declare function utf8ArrayToString(input: AllowSharedBufferSource): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const r=new TextDecoder;export function utf8ArrayToString(e){return r.decode(e)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/convert",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A utility package that helps convert between different data types.",
|
|
6
6
|
"repository": {
|
|
@@ -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",
|
|
@@ -114,6 +128,20 @@
|
|
|
114
128
|
"default": "./dist/to-array.mjs"
|
|
115
129
|
}
|
|
116
130
|
},
|
|
131
|
+
"./string-to-utf8-array": {
|
|
132
|
+
"import": {
|
|
133
|
+
"types": "./dist/string-to-utf8-array.d.ts",
|
|
134
|
+
"default": "./dist/string-to-utf8-array.mjs"
|
|
135
|
+
},
|
|
136
|
+
"require": {
|
|
137
|
+
"types": "./dist/string-to-utf8-array.d.ts",
|
|
138
|
+
"default": "./dist/string-to-utf8-array.cjs"
|
|
139
|
+
},
|
|
140
|
+
"default": {
|
|
141
|
+
"types": "./dist/string-to-utf8-array.d.ts",
|
|
142
|
+
"default": "./dist/string-to-utf8-array.mjs"
|
|
143
|
+
}
|
|
144
|
+
},
|
|
117
145
|
"./string-to-uint8-array": {
|
|
118
146
|
"import": {
|
|
119
147
|
"types": "./dist/string-to-uint8-array.d.ts",
|
|
@@ -178,6 +206,20 @@
|
|
|
178
206
|
"default": "./dist/buffer-to-string.mjs"
|
|
179
207
|
}
|
|
180
208
|
},
|
|
209
|
+
"./array-buffer-to-string": {
|
|
210
|
+
"import": {
|
|
211
|
+
"types": "./dist/array-buffer-to-string.d.ts",
|
|
212
|
+
"default": "./dist/array-buffer-to-string.mjs"
|
|
213
|
+
},
|
|
214
|
+
"require": {
|
|
215
|
+
"types": "./dist/array-buffer-to-string.d.ts",
|
|
216
|
+
"default": "./dist/array-buffer-to-string.cjs"
|
|
217
|
+
},
|
|
218
|
+
"default": {
|
|
219
|
+
"types": "./dist/array-buffer-to-string.d.ts",
|
|
220
|
+
"default": "./dist/array-buffer-to-string.mjs"
|
|
221
|
+
}
|
|
222
|
+
},
|
|
181
223
|
".": {
|
|
182
224
|
"import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
|
|
183
225
|
"require": {
|
|
@@ -191,5 +233,5 @@
|
|
|
191
233
|
"main": "./dist/index.cjs",
|
|
192
234
|
"module": "./dist/index.mjs",
|
|
193
235
|
"types": "./dist/index.d.ts",
|
|
194
|
-
"gitHead": "
|
|
236
|
+
"gitHead": "7331a32032c42269626a48f5011938b82dc80c45"
|
|
195
237
|
}
|