Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
1a22db26da | |||
0d3bcab40f | |||
e11ace6a23 | |||
f29b632bd2 | |||
25f80b6b59 | |||
176ac34504 | |||
2707542234 | |||
ee025d094c | |||
9bc1c4bf93 | |||
5176a34575 | |||
fe9f9299fc |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
@ -1,18 +1,16 @@
|
|||||||
# gitzone ci_default
|
# gitzone ci_default
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
variables:
|
|
||||||
GIT_STRATEGY: clone
|
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -21,20 +19,35 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install --production --ignore-scripts
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command snyk test
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -50,28 +63,27 @@ testStable:
|
|||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
@ -81,11 +93,15 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
|
|
||||||
@ -96,20 +112,20 @@ trigger:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-dbase:npmci
|
|
||||||
services:
|
|
||||||
- docker:18-dind
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
|
- npmci node install lts
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "current file",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"${relativeFile}"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "test.ts",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"test/test.ts"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
53
README.md
53
README.md
@ -1,53 +0,0 @@
|
|||||||
# @pushrocks/smartjson
|
|
||||||
typed json handlers
|
|
||||||
|
|
||||||
## Availabililty and Links
|
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartjson)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartjson)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartjson)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartjson/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
[](https://gitlab.com/pushrocks/smartjson/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartjson/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartjson)
|
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartjson)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://prettier.io/)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
|
||||||
|
|
||||||
### Classes
|
|
||||||
|
|
||||||
SmartJson makes it easy to fold and enfold classes into and from JSON
|
|
||||||
|
|
||||||
```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}
|
|
||||||
myAwesomeInstance.enfoldFromObject({ anotherValueToStore: 'hi' });
|
|
||||||
foldedObject = myAwesomeInstance.foldToObject(); // will return {anotherValueToStore: 'hi'}
|
|
||||||
```
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
|
@ -3,6 +3,7 @@
|
|||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
|
11162
package-lock.json
generated
11162
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
42
package.json
42
package.json
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartjson",
|
"name": "@pushrocks/smartjson",
|
||||||
"version": "3.0.8",
|
"version": "4.0.1",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "typed json handlers",
|
"description": "typed json handlers",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -20,28 +20,34 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartjson#README",
|
"homepage": "https://gitlab.com/pushrocks/smartjson#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.11",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tsrun": "^1.2.8",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tstest": "^1.0.52",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^12.7.2",
|
"@types/node": "^14.11.2",
|
||||||
"tslint": "^5.19.0",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/buffer-json": "^2.0.0",
|
||||||
"@types/fast-json-stable-stringify": "^2.0.0",
|
"@types/fast-json-stable-stringify": "^2.0.0",
|
||||||
"fast-json-stable-stringify": "^2.0.0",
|
"buffer-json": "^2.0.0",
|
||||||
|
"fast-json-stable-stringify": "^2.1.0",
|
||||||
"lodash.clonedeep": "^4.5.0"
|
"lodash.clonedeep": "^4.5.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_*/**/*",
|
||||||
"dist_ts_web/*",
|
"dist_ts/**/*",
|
||||||
"assets/*",
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
10
test/test.ts
10
test/test.ts
@ -20,16 +20,12 @@ tap.test('should create a Foldable extended instance', async () => {
|
|||||||
|
|
||||||
tap.test('should create a folded object', async () => {
|
tap.test('should create a folded object', async () => {
|
||||||
let foldedObject = mySomeClass.foldToObject();
|
let foldedObject = mySomeClass.foldToObject();
|
||||||
expect(foldedObject)
|
expect(foldedObject).property('thisis').to.equal('test');
|
||||||
.property('thisis')
|
|
||||||
.to.equal('test');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should enfold from object', async () => {
|
tap.test('should enfold from object', async () => {
|
||||||
mySomeClass.enfoldFromObject({ thisis: 'test2' });
|
const mySomeClass2 = SomeClass.enfoldFromObject({ thisis: 'test2' });
|
||||||
expect(mySomeClass)
|
expect(mySomeClass2).property('thisis').to.equal('test2');
|
||||||
.property('thisis')
|
|
||||||
.to.equal('test2');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
51
ts/index.ts
51
ts/index.ts
@ -1,13 +1,41 @@
|
|||||||
import * as plugins from './smartjson.plugins';
|
import * as plugins from './smartjson.plugins';
|
||||||
|
|
||||||
export class Smartjson {
|
/**
|
||||||
// ======
|
* allows you to parse a json
|
||||||
// STATIC
|
*/
|
||||||
// ======
|
export const parse = plugins.bufferJson.parse;
|
||||||
public static parse = JSON.parse;
|
|
||||||
|
|
||||||
public static stringify = (objArg: any, optionsArg: plugins.stableJson.Options) => {
|
/**
|
||||||
|
*
|
||||||
|
* @param objArg
|
||||||
|
* @param optionsArg
|
||||||
|
*/
|
||||||
|
export const stringify = (objArg: any, optionsArg: plugins.IStableJsonTypes['Options'] = {}) => {
|
||||||
|
const bufferedJson = plugins.bufferJson.stringify(objArg);
|
||||||
|
objArg = JSON.parse(bufferedJson);
|
||||||
return plugins.stableJson(objArg, optionsArg);
|
return plugins.stableJson(objArg, optionsArg);
|
||||||
|
};
|
||||||
|
|
||||||
|
export class Smartjson {
|
||||||
|
/**
|
||||||
|
* enfolds data from an object
|
||||||
|
*/
|
||||||
|
public static enfoldFromObject(objectArg) {
|
||||||
|
const newInstance = new this();
|
||||||
|
for (const keyName in objectArg) {
|
||||||
|
if (newInstance.saveableProperties.indexOf(keyName) !== -1) {
|
||||||
|
newInstance[keyName] = objectArg[keyName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* enfold from json
|
||||||
|
*/
|
||||||
|
public static enfoldFromJson(jsonArg: string) {
|
||||||
|
const objectFromJson = parse(jsonArg);
|
||||||
|
return this.enfoldFromObject(objectFromJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========
|
// ========
|
||||||
@ -28,14 +56,11 @@ export class Smartjson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* enfolds data from an object
|
* folds a class into an object
|
||||||
*/
|
*/
|
||||||
public enfoldFromObject(objectArg) {
|
public foldToJson() {
|
||||||
for (const keyName in objectArg) {
|
const foldedObject = this.foldToObject();
|
||||||
if (this.saveableProperties.indexOf(keyName) !== -1) {
|
return stringify(foldedObject, {});
|
||||||
this[keyName] = objectArg[keyName];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,26 @@
|
|||||||
|
// third party scope
|
||||||
import lodashCloneDeep from 'lodash.clonedeep';
|
import lodashCloneDeep from 'lodash.clonedeep';
|
||||||
import stableJson from 'fast-json-stable-stringify';
|
import stableJson2 from 'fast-json-stable-stringify';
|
||||||
|
import bufferJson from 'buffer-json';
|
||||||
|
|
||||||
export { lodashCloneDeep, stableJson };
|
const stableJson = stableJson2 as any;
|
||||||
|
|
||||||
|
export { bufferJson, lodashCloneDeep, stableJson };
|
||||||
|
|
||||||
|
export interface IStableJsonTypes {
|
||||||
|
Comparator: (
|
||||||
|
a: IStableJsonTypes['CompareDescriptor'],
|
||||||
|
b: IStableJsonTypes['CompareDescriptor']
|
||||||
|
) => number;
|
||||||
|
CompareDescriptor: {
|
||||||
|
key: string;
|
||||||
|
value: any;
|
||||||
|
};
|
||||||
|
Options: {
|
||||||
|
cmp?: (
|
||||||
|
a: IStableJsonTypes['CompareDescriptor'],
|
||||||
|
b: IStableJsonTypes['CompareDescriptor']
|
||||||
|
) => number;
|
||||||
|
cycles?: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user