Compare commits

...

17 Commits

Author SHA1 Message Date
9bb6e0b497 update description 2024-05-29 14:13:49 +02:00
5275e13360 5.0.20 2024-05-28 00:50:30 +02:00
03fe2174d1 fix(core): update 2024-05-28 00:50:30 +02:00
7df82ce64d 5.0.19 2024-04-17 20:19:18 +02:00
09b74e4053 fix(core): update 2024-04-17 20:19:17 +02:00
096cd74773 5.0.18 2024-04-17 20:11:19 +02:00
e9a45ac993 fix(core): update 2024-04-17 20:11:18 +02:00
b3856cb94a 5.0.17 2024-04-17 20:10:59 +02:00
e44d014733 fix(core): update 2024-04-17 20:10:59 +02:00
777d7ae1b3 update tsconfig 2024-04-14 17:45:36 +02:00
f1f6b5fa79 update npmextra.json: githost 2024-04-01 21:35:43 +02:00
65673e9710 update npmextra.json: githost 2024-04-01 19:58:33 +02:00
66f1094cfe update npmextra.json: githost 2024-03-30 21:47:32 +01:00
8e93b8cb73 5.0.16 2024-03-19 13:50:07 +01:00
e38ccd221a fix(core): update 2024-03-19 13:50:06 +01:00
969b892ed8 5.0.15 2024-03-19 13:30:15 +01:00
d1d679ac34 fix(core): update 2024-03-19 13:30:15 +01:00
7 changed files with 4847 additions and 3687 deletions

View File

@ -5,12 +5,28 @@
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartjson",
"description": "typed json handlers",
"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.",
"npmPackagename": "@push.rocks/smartjson",
"license": "MIT"
"license": "MIT",
"keywords": [
"JSON handling",
"typed JSON",
"JSON parsing",
"JSON stringifying",
"base64 encoding",
"buffer handling",
"data serialization",
"data deserialization",
"TypeScript support",
"data encoding",
"data decoding"
]
}
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}

View File

@ -1,8 +1,8 @@
{
"name": "@push.rocks/smartjson",
"version": "5.0.14",
"version": "5.0.20",
"private": false,
"description": "typed json handlers",
"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.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
@ -12,25 +12,24 @@
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/pushrocks/smartjson.git"
"url": "https://code.foss.global/push.rocks/smartjson.git"
},
"author": "Lossless GmbH",
"license": "MIT",
"bugs": {
"url": "https://gitlab.com/pushrocks/smartjson/issues"
},
"homepage": "https://gitlab.com/pushrocks/smartjson#README",
"homepage": "https://code.foss.global/push.rocks/smartjson",
"devDependencies": {
"@git.zone/tsbuild": "^2.1.66",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^1.0.77",
"@push.rocks/tapbundle": "^5.0.8",
"@types/node": "^20.11.24"
"@git.zone/tstest": "^1.0.88",
"@push.rocks/tapbundle": "^5.0.23",
"@types/node": "^20.12.7"
},
"dependencies": {
"@push.rocks/smartbuffer": "^1.0.7",
"@push.rocks/smartenv": "^5.0.12",
"@push.rocks/smartstring": "^4.0.14",
"@push.rocks/smartstring": "^4.0.15",
"fast-json-stable-stringify": "^2.1.0",
"lodash.clonedeep": "^4.5.0"
},
@ -49,5 +48,18 @@
"browserslist": [
"last 1 chrome versions"
],
"type": "module"
}
"type": "module",
"keywords": [
"JSON handling",
"typed JSON",
"JSON parsing",
"JSON stringifying",
"base64 encoding",
"buffer handling",
"data serialization",
"data deserialization",
"TypeScript support",
"data encoding",
"data decoding"
]
}

8269
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

173
readme.md
View File

@ -1,64 +1,141 @@
# @push.rocks/smartjson
typed json handlers
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartjson)
* [gitlab.com (source)](https://gitlab.com/push.rocks/smartjson)
* [github.com (source mirror)](https://github.com/push.rocks/smartjson)
* [docs (typedoc)](https://push.rocks.gitlab.io/smartjson/)
## Install
## Status for master
To install `@push.rocks/smartjson`, you can use npm or yarn as follows:
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/smartjson/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/smartjson/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartjson)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/smartjson)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smartjson)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartjson)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartjson)](https://lossless.cloud)
```shell
npm install @push.rocks/smartjson --save
# or using yarn
yarn add @push.rocks/smartjson
```
## Usage
Use TypeScript for best in class instellisense.
`@push.rocks/smartjson` offers typed JSON handling, including features like folding and enfolding classes from JSON, JSON parsing with support for buffers, and comparison of JSON objects for equality. This guide will walk through various use cases and scenarios to effectively utilize `@push.rocks/smartjson` in your projects.
### Classes
### Basic Import
SmartJson makes it easy to fold and enfold classes into and from JSON
First, make sure to import the module:
```javascript
import { Smartjson, foldDec } from 'smartjson';
class AwesomeClass extends Smartjson {
static stringify;
computedValue: string;
@foldDec() // mark anotherValueToStore as foldable
anotherValueToStore: string = null;
constructor() {
super(); // this is important
}
}
let myAwesomeInstance = new AwesomeClass();
let foldedObject = myAwesomeInstance.foldToObject(); // will return {anotherValueToStore: null}
// You can also fold to Json, with support for buffers
// const jsonString = myAwesomeInstance.foldToJson();
myAwesomeInstance = AwesomeClass.enfoldFromObject({ anotherValueToStore: 'hi' });
foldedObject = myAwesomeInstance.foldToObject(); // will return {anotherValueToStore: 'hi'}
```typescript
import * as smartjson from '@push.rocks/smartjson';
```
## Contribution
### Parsing and Stringifying JSON
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
- **Parsing JSON Strings:**
For further information read the linked docs at the top of this readme.
`smartjson` enhances JSON parsing by supporting JavaScript's typed arrays, particularly with `Buffer` handling.
## Legal
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
```typescript
const jsonString = '{"type":"Buffer","data":[116,101,115,116]}';
const parsedObject = smartjson.parse(jsonString);
console.log(parsedObject); // Output will be based on the content of jsonString
```
- **Stringifying Objects:**
`@push.rocks/smartjson` provides a `stringify` function that can convert JavaScript objects into JSON strings, with special handling for `Buffer` objects.
```typescript
const myObject = {
exampleBuffer: new Uint8Array([116, 101, 115, 116])
};
const jsonString = smartjson.stringify(myObject);
console.log(jsonString); // Will include `exampleBuffer` encoded in a special format
```
### Working with Base64 Encoded JSON
For cases where JSON strings are encoded in base64 format, `smartjson` offers methods to encode and decode these strings transparently.
```typescript
const objectToEncode = { hello: 'world' };
const base64EncodedJson = smartjson.stringifyBase64(objectToEncode);
console.log(base64EncodedJson); // Encoded JSON string
const decodedObject = smartjson.parseBase64(base64EncodedJson);
console.log(decodedObject); // Original object
```
### Folding and Enfolding Classes
`@push.rocks/smartjson` allows you to fold (serialize) and enfold (deserialize) class instances to and from JSON. This is particularly useful when working with typed objects and you need to maintain type integrity across serialization.
- **Defining a Foldable Class:**
Decorate properties that should be included in JSON with `@smartjson.foldDec()`.
```typescript
import { Smartjson, foldDec } from '@push.rocks/smartjson';
class MyDataModel extends Smartjson {
@foldDec() public someProperty: string = 'default';
constructor(public id: number, someProperty?: string) {
super();
if (someProperty) this.someProperty = someProperty;
}
}
```
- **Folding and Enfolding Instances:**
```typescript
const instance = new MyDataModel(1, 'value');
const folded = instance.foldToJson(); // Serialize to JSON
console.log(folded);
const enfoldedInstance = MyDataModel.enfoldFromJson(folded); // Deserialize back to instance
console.log(enfoldedInstance);
```
### Deep Comparison
`@push.rocks/smartjson` enables deep comparison of objects to determine if they are equivalent.
```typescript
const obj1 = { a: 1, b: { c: 2 }};
const obj2 = { a: 1, b: { c: 2 }};
const isEqual = smartjson.deepEqualObjects(obj1, obj2);
console.log(isEqual); // true
```
### Handling Buffers and Typed Arrays
`smartjson` transparently handles JavaScript's `Buffer` and Typed Arrays during JSON serialization, making it effortless to work with binary data in JSON format.
```typescript
const buffer = new Uint8Array([1, 2, 3]);
const objWithBuffer = { key: buffer };
const serialized = smartjson.stringify(objWithBuffer);
const deserialized = smartjson.parse(serialized);
console.log(deserialized.key); // Instance of Uint8Array or Buffer
```
In addition to these features, `@push.rocks/smartjson` supports efficient base64 encoding/decoding, deep object comparison, and JSON Lines parsing, making it a versatile library for dealing with JSON in TypeScript projects.
For further information and more detailed examples, referring to the API documentation and the source code on [GitLab](https://gitlab.com/push.rocks/smartjson) can provide deeper insights into `@push.rocks/smartjson`'s capabilities.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartjson',
version: '5.0.14',
description: 'typed json handlers'
version: '5.0.20',
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.'
}

View File

@ -1,11 +1,26 @@
import * as plugins from './smartjson.plugins.js';
import * as bufferhandling from './bufferhandling.js';
interface JsonObject {
[key: string]: any;
}
/**
* allows you to parse a json
*/
export const parse = bufferhandling.parse;
export const parseJsonL = (jsonlData: string): JsonObject[] => {
const lines = jsonlData.trim().split('\n');
const parsedData: JsonObject[] = lines.reduce((acc, line) => {
if (line.trim().length > 0) {
acc.push(JSON.parse(line));
}
return acc;
}, [] as JsonObject[]);
return parsedData;
}
/**
*
* @param objArg
@ -114,3 +129,19 @@ export const deepEqualObjects = (object1: any, object2: any): boolean => {
const object2String = stringify(object2);
return object1String === object2String;
};
export const deepEqualJsonLStrings = (jsonLString1: string, jsonLString2: string): boolean => {
const firstArray = [];
jsonLString1.split('\n').forEach((line) => {
if (line) {
firstArray.push(parse(line));
}
});
const secondArray = [];
jsonLString2.split('\n').forEach((line) => {
if (line) {
secondArray.push(parse(line));
}
});
return deepEqualObjects(firstArray, secondArray);
}