@pezkuwi/x-textdecoder 14.0.1
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/README.md +12 -0
- package/package.json +26 -0
- package/src/browser.ts +10 -0
- package/src/fallback.spec.ts +20 -0
- package/src/fallback.ts +21 -0
- package/src/mod.ts +4 -0
- package/src/node.spec.ts +25 -0
- package/src/node.ts +10 -0
- package/src/packageInfo.ts +6 -0
- package/src/react-native.ts +4 -0
- package/src/shim.ts +7 -0
- package/src/typeCheck.ts +8 -0
- package/tsconfig.build.json +15 -0
- package/tsconfig.spec.json +17 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "Jaco Greeff <jacogr@gmail.com>",
|
|
3
|
+
"bugs": "https://github.com/pezkuwichain/pezkuwi-common/issues",
|
|
4
|
+
"description": "A TextDecoder replacement",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=18"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://github.com/pezkuwichain/pezkuwi-common/tree/master/packages/x-textdecoder#readme",
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"name": "@pezkuwi/x-textdecoder",
|
|
11
|
+
"repository": {
|
|
12
|
+
"directory": "packages/x-textdecoder",
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/pezkuwichain/pezkuwi-common.git"
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"type": "module",
|
|
18
|
+
"version": "14.0.1",
|
|
19
|
+
"browser": "browser.js",
|
|
20
|
+
"main": "node.js",
|
|
21
|
+
"react-native": "react-native.js",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@pezkuwi/x-global": "14.0.1",
|
|
24
|
+
"tslib": "^2.8.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/browser.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { extractGlobal } from '@pezkuwi/x-global';
|
|
5
|
+
|
|
6
|
+
import { TextDecoder as Fallback } from './fallback.js';
|
|
7
|
+
|
|
8
|
+
export { packageInfo } from './packageInfo.js';
|
|
9
|
+
|
|
10
|
+
export const TextDecoder = /*#__PURE__*/ extractGlobal('TextDecoder', Fallback);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
import { TextDecoder } from './fallback.js';
|
|
7
|
+
|
|
8
|
+
describe('TextDecoder (fallback)', (): void => {
|
|
9
|
+
it('decodes correctly', (): void => {
|
|
10
|
+
expect(
|
|
11
|
+
new TextDecoder().decode(new Uint8Array([97, 98, 99]))
|
|
12
|
+
).toEqual('abc');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('decodes correctly (with constructor param)', (): void => {
|
|
16
|
+
expect(
|
|
17
|
+
new TextDecoder('utf-8').decode(new Uint8Array([97, 98, 99, 98, 97]))
|
|
18
|
+
).toEqual('abcba');
|
|
19
|
+
});
|
|
20
|
+
});
|
package/src/fallback.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// This is very limited, only handling Ascii values
|
|
5
|
+
export class TextDecoder {
|
|
6
|
+
__encoding?: string;
|
|
7
|
+
|
|
8
|
+
constructor (encoding?: 'utf-8' | 'utf8') {
|
|
9
|
+
this.__encoding = encoding;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
decode (value: Uint8Array): string {
|
|
13
|
+
let result = '';
|
|
14
|
+
|
|
15
|
+
for (let i = 0, count = value.length; i < count; i++) {
|
|
16
|
+
result += String.fromCharCode(value[i]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/mod.ts
ADDED
package/src/node.spec.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
import { xglobal } from '@pezkuwi/x-global';
|
|
7
|
+
|
|
8
|
+
// @ts-expect-error Clearing this, it is obviously not valid in normal code
|
|
9
|
+
xglobal.TextDecoder = undefined;
|
|
10
|
+
|
|
11
|
+
describe('TextDecoder (node)', (): void => {
|
|
12
|
+
let TD: typeof TextDecoder;
|
|
13
|
+
|
|
14
|
+
beforeEach(async (): Promise<void> => {
|
|
15
|
+
const node = await import('./node.js');
|
|
16
|
+
|
|
17
|
+
TD = node.TextDecoder;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('encodes correctly', (): void => {
|
|
21
|
+
expect(
|
|
22
|
+
new TD().decode(new Uint8Array([97, 98, 99]))
|
|
23
|
+
).toEqual('abc');
|
|
24
|
+
});
|
|
25
|
+
});
|
package/src/node.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import util from 'node:util';
|
|
5
|
+
|
|
6
|
+
import { extractGlobal } from '@pezkuwi/x-global';
|
|
7
|
+
|
|
8
|
+
export { packageInfo } from './packageInfo.js';
|
|
9
|
+
|
|
10
|
+
export const TextDecoder = /*#__PURE__*/ extractGlobal('TextDecoder', util.TextDecoder);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/x-textdecoder authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Do not edit, auto-generated by @polkadot/dev
|
|
5
|
+
|
|
6
|
+
export const packageInfo = { name: '@polkadot/x-textdecoder', path: 'auto', type: 'auto', version: '14.0.1' };
|
package/src/shim.ts
ADDED
package/src/typeCheck.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/x-textdecoder authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { TextDecoder as BrowserTD } from './browser.js';
|
|
5
|
+
import { TextDecoder as NodeTD } from './node.js';
|
|
6
|
+
|
|
7
|
+
console.log(new BrowserTD('utf-8').decode(new Uint8Array([1, 2, 3])));
|
|
8
|
+
console.log(new NodeTD('utf-8').decode(new Uint8Array([1, 2, 3])));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": "..",
|
|
5
|
+
"outDir": "./build",
|
|
6
|
+
"rootDir": "./src"
|
|
7
|
+
},
|
|
8
|
+
"exclude": [
|
|
9
|
+
"**/mod.ts",
|
|
10
|
+
"**/*.spec.ts"
|
|
11
|
+
],
|
|
12
|
+
"references": [
|
|
13
|
+
{ "path": "../x-global/tsconfig.build.json" }
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": "..",
|
|
5
|
+
"outDir": "./build",
|
|
6
|
+
"rootDir": "./src",
|
|
7
|
+
"emitDeclarationOnly": false,
|
|
8
|
+
"noEmit": true
|
|
9
|
+
},
|
|
10
|
+
"include": [
|
|
11
|
+
"**/*.spec.ts"
|
|
12
|
+
],
|
|
13
|
+
"references": [
|
|
14
|
+
{ "path": "../x-global/tsconfig.build.json" },
|
|
15
|
+
{ "path": "../x-textdecoder/tsconfig.build.json" }
|
|
16
|
+
]
|
|
17
|
+
}
|