fix(build,json): replace lodash.clonedeep with structuredClone and migrate package metadata to smartconfig
This commit is contained in:
+20
-8
@@ -14,22 +14,34 @@ interface IEncodedBuffer {
|
||||
type TParseReviver = (this: any, key: string, value: any) => any;
|
||||
type TParseReplacer = (this: any, key: string, value: any) => any;
|
||||
|
||||
interface INodeBufferLike extends Uint8Array {
|
||||
toString(): string;
|
||||
toString(encoding: 'base64'): string;
|
||||
}
|
||||
|
||||
interface INodeBufferConstructor {
|
||||
from(data: Uint8Array): INodeBufferLike;
|
||||
from(data: string, encoding: 'base64'): INodeBufferLike;
|
||||
}
|
||||
|
||||
const getNodeBuffer = (): INodeBufferConstructor | undefined => {
|
||||
return (globalThis as typeof globalThis & { Buffer?: INodeBufferConstructor }).Buffer;
|
||||
};
|
||||
|
||||
// Utility functions to handle base64 encoding/decoding in a cross-platform way
|
||||
function base64Encode(data: Uint8Array): string {
|
||||
// Prefer Node's Buffer when available
|
||||
if (typeof Buffer !== 'undefined') {
|
||||
// @ts-ignore Buffer might not exist in browser builds
|
||||
return Buffer.from(data).toString('base64');
|
||||
const NodeBuffer = getNodeBuffer();
|
||||
if (NodeBuffer) {
|
||||
return NodeBuffer.from(data).toString('base64');
|
||||
}
|
||||
// Fallback for browsers
|
||||
return btoa(String.fromCharCode(...data));
|
||||
}
|
||||
|
||||
function base64Decode(str: string): Uint8Array {
|
||||
// Prefer Node's Buffer when available
|
||||
if (typeof Buffer !== 'undefined') {
|
||||
// @ts-ignore Buffer might not exist in browser builds
|
||||
const buf = Buffer.from(str, 'base64');
|
||||
const NodeBuffer = getNodeBuffer();
|
||||
if (NodeBuffer) {
|
||||
const buf = NodeBuffer.from(str, 'base64');
|
||||
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
||||
}
|
||||
// Fallback for browsers
|
||||
|
||||
Reference in New Issue
Block a user