update tsconfig
This commit is contained in:
parent
f1f6b5fa79
commit
777d7ae1b3
@ -8,12 +8,25 @@
|
||||
"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"
|
||||
]
|
||||
}
|
||||
},
|
||||
"tsdocs": {
|
||||
"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"
|
||||
}
|
||||
}
|
19
package.json
19
package.json
@ -2,7 +2,7 @@
|
||||
"name": "@push.rocks/smartjson",
|
||||
"version": "5.0.16",
|
||||
"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": {
|
||||
@ -49,5 +49,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"
|
||||
]
|
||||
}
|
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
173
readme.md
173
readme.md
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user