mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 10:17:57 +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,10 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { extractGlobal } from '@pezkuwi/x-global';
|
||||
|
||||
import { TextDecoder as Fallback } from './fallback.js';
|
||||
|
||||
export { packageInfo } from './packageInfo.js';
|
||||
|
||||
export const TextDecoder = /*#__PURE__*/ extractGlobal('TextDecoder', Fallback);
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
||||
|
||||
import { TextDecoder } from './fallback.js';
|
||||
|
||||
describe('TextDecoder (fallback)', (): void => {
|
||||
it('decodes correctly', (): void => {
|
||||
expect(
|
||||
new TextDecoder().decode(new Uint8Array([97, 98, 99]))
|
||||
).toEqual('abc');
|
||||
});
|
||||
|
||||
it('decodes correctly (with constructor param)', (): void => {
|
||||
expect(
|
||||
new TextDecoder('utf-8').decode(new Uint8Array([97, 98, 99, 98, 97]))
|
||||
).toEqual('abcba');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// This is very limited, only handling Ascii values
|
||||
export class TextDecoder {
|
||||
__encoding?: string;
|
||||
|
||||
constructor (encoding?: 'utf-8' | 'utf8') {
|
||||
this.__encoding = encoding;
|
||||
}
|
||||
|
||||
decode (value: Uint8Array): string {
|
||||
let result = '';
|
||||
|
||||
for (let i = 0, count = value.length; i < count; i++) {
|
||||
result += String.fromCharCode(value[i]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -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.TextDecoder = undefined;
|
||||
|
||||
describe('TextDecoder (node)', (): void => {
|
||||
let TD: typeof TextDecoder;
|
||||
|
||||
beforeEach(async (): Promise<void> => {
|
||||
const node = await import('./node.js');
|
||||
|
||||
TD = node.TextDecoder;
|
||||
});
|
||||
|
||||
it('encodes correctly', (): void => {
|
||||
expect(
|
||||
new TD().decode(new Uint8Array([97, 98, 99]))
|
||||
).toEqual('abc');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
// 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';
|
||||
|
||||
export const TextDecoder = /*#__PURE__*/ extractGlobal('TextDecoder', util.TextDecoder);
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textdecoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-textdecoder', 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-textdecoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { exposeGlobal } from '@pezkuwi/x-global';
|
||||
import { TextDecoder } from '@pezkuwi/x-textdecoder';
|
||||
|
||||
exposeGlobal('TextDecoder', TextDecoder);
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2025 @polkadot/x-textdecoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TextDecoder as BrowserTD } from './browser.js';
|
||||
import { TextDecoder as NodeTD } from './node.js';
|
||||
|
||||
console.log(new BrowserTD('utf-8').decode(new Uint8Array([1, 2, 3])));
|
||||
console.log(new NodeTD('utf-8').decode(new Uint8Array([1, 2, 3])));
|
||||
Reference in New Issue
Block a user