fix(build,json): replace lodash.clonedeep with structuredClone and migrate package metadata to smartconfig

This commit is contained in:
2026-04-30 06:59:14 +00:00
parent 6ac04e2069
commit ba38d4377b
9 changed files with 2245 additions and 2986 deletions
+1 -1
View File
@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartjson',
version: '6.0.0',
version: '6.0.1',
description: 'A library for handling typed JSON data, providing functionalities for parsing, stringifying, and working with JSON objects, including support for encoding and decoding buffers.'
}
+20 -8
View File
@@ -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
+3 -3
View File
@@ -163,7 +163,7 @@ export class Smartjson {
// INSTANCE
// ========
public saveableProperties: string[];
public saveableProperties: string[] = [];
/**
* folds a class into an object
@@ -187,11 +187,11 @@ export class Smartjson {
if (Array.isArray(val)) {
return val.map((item) => foldValue(item));
}
return plugins.lodashCloneDeep(val);
return structuredClone(val);
};
const props: string[] = (this as any).saveableProperties || [];
for (const keyName of props) {
const value = this[keyName];
const value = (this as unknown as Record<string, unknown>)[keyName];
result[keyName] = foldValue(value);
}
return result;
+1 -2
View File
@@ -5,12 +5,11 @@ import * as smartstring from '@push.rocks/smartstring';
export { smartenv, smartstring };
// third party scope
import lodashCloneDeep from 'lodash.clonedeep';
import stableJson2 from 'fast-json-stable-stringify';
const stableJson = stableJson2 as any;
export { lodashCloneDeep, stableJson };
export { stableJson };
export interface IStableJsonTypes {
Comparator: (