mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 02:07:56 +00:00
Initial rebrand: @polkadot -> @pezkuwi (14 packages)
- Package namespace: @polkadot/* -> @pezkuwi/* - Repository: polkadot-js/common -> pezkuwichain/pezkuwi-common - Author: Pezkuwi Team <team@pezkuwichain.io> Core packages: - @pezkuwi/util (utilities) - @pezkuwi/util-crypto (crypto primitives) - @pezkuwi/keyring (account management) - @pezkuwi/networks (chain metadata) - @pezkuwi/hw-ledger (Ledger hardware wallet) - @pezkuwi/x-* (10 polyfill packages) Total: 14 packages Upstream: polkadot-js/common v14.0.1
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
# @pezkuwi/x-textencoder
|
||||
|
||||
A cross-environment TextEncoder.
|
||||
|
||||
Install it via `yarn add @pezkuwi/x-textencoder`
|
||||
|
||||
```js
|
||||
import { TextEncoder } from '@pezkuwi/x-textencoder';
|
||||
|
||||
...
|
||||
const encoder = new TextEncoder();
|
||||
```
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/pezkuwichain/pezkuwi-common/issues",
|
||||
"description": "A TextDecoder replacement",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"homepage": "https://github.com/pezkuwichain/pezkuwi-common/tree/master/packages/x-textencoder#readme",
|
||||
"license": "Apache-2.0",
|
||||
"name": "@pezkuwi/x-textencoder",
|
||||
"repository": {
|
||||
"directory": "packages/x-textencoder",
|
||||
"type": "git",
|
||||
"url": "https://github.com/pezkuwichain/pezkuwi-common.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "14.0.1",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@pezkuwi/x-global": "14.0.1",
|
||||
"tslib": "^2.8.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { extractGlobal } from '@pezkuwi/x-global';
|
||||
|
||||
import { TextEncoder as Fallback } from './fallback.js';
|
||||
|
||||
export { packageInfo } from './packageInfo.js';
|
||||
|
||||
export const TextEncoder = /*#__PURE__*/ extractGlobal('TextEncoder', Fallback);
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
||||
|
||||
import { TextEncoder } from './fallback.js';
|
||||
|
||||
describe('TextEncoder (fallback)', (): void => {
|
||||
it('encodes correctly', (): void => {
|
||||
expect(
|
||||
new TextEncoder().encode('abc')
|
||||
).toEqual(new Uint8Array([97, 98, 99]));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// This is very limited, only handling Ascii values
|
||||
export class TextEncoder {
|
||||
encode (value: string): Uint8Array {
|
||||
const count = value.length;
|
||||
const u8a = new Uint8Array(count);
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
u8a[i] = value.charCodeAt(i);
|
||||
}
|
||||
|
||||
return u8a;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './browser.js';
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
||||
|
||||
import { xglobal } from '@pezkuwi/x-global';
|
||||
|
||||
// @ts-expect-error Clearing this, it is obviously not valid in normal code
|
||||
xglobal.TextEncoder = undefined;
|
||||
|
||||
describe('TextEncoder (node)', (): void => {
|
||||
let TE: typeof TextEncoder;
|
||||
|
||||
beforeEach(async (): Promise<void> => {
|
||||
const node = await import('./node.js');
|
||||
|
||||
TE = node.TextEncoder;
|
||||
});
|
||||
|
||||
it('encodes correctly', (): void => {
|
||||
expect(
|
||||
new TE().encode('abc')
|
||||
).toEqual(new Uint8Array([97, 98, 99]));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import util from 'node:util';
|
||||
|
||||
import { extractGlobal } from '@pezkuwi/x-global';
|
||||
|
||||
export { packageInfo } from './packageInfo.js';
|
||||
|
||||
class Fallback {
|
||||
#encoder: util.TextEncoder;
|
||||
|
||||
constructor () {
|
||||
this.#encoder = new util.TextEncoder();
|
||||
}
|
||||
|
||||
// For a Jest 26.0.1 environment, Buffer !== Uint8Array
|
||||
encode (value: string): Uint8Array {
|
||||
return Uint8Array.from(this.#encoder.encode(value));
|
||||
}
|
||||
}
|
||||
|
||||
export const TextEncoder = /*#__PURE__*/ extractGlobal('TextEncoder', Fallback);
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-textencoder', path: 'auto', type: 'auto', version: '14.0.1' };
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './browser.js';
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { exposeGlobal } from '@pezkuwi/x-global';
|
||||
import { TextEncoder } from '@pezkuwi/x-textencoder';
|
||||
|
||||
exposeGlobal('TextEncoder', TextEncoder);
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TextEncoder as BrowserTE } from './browser.js';
|
||||
import { TextEncoder as NodeTE } from './node.js';
|
||||
|
||||
console.log(new BrowserTE().encode('abc'));
|
||||
console.log(new NodeTE().encode('abc'));
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"exclude": [
|
||||
"**/mod.ts",
|
||||
"**/*.spec.ts"
|
||||
],
|
||||
"references": [
|
||||
{ "path": "../x-global/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src",
|
||||
"emitDeclarationOnly": false,
|
||||
"noEmit": true
|
||||
},
|
||||
"include": [
|
||||
"**/*.spec.ts"
|
||||
],
|
||||
"references": [
|
||||
{ "path": "../x-global/tsconfig.build.json" },
|
||||
{ "path": "../x-textencoder/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user