Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ccc67215c | |||
| 6c9b19cb9f | |||
| 5944310af9 | |||
| 5732f0e2cd | |||
| cd2d162738 | |||
| afc639c20e | |||
| 665891e168 |
@@ -19,23 +19,35 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
audit:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --production --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
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 --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm audit --audit-level=high
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@@ -50,9 +62,7 @@ testStable:
|
|||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
@@ -63,9 +73,7 @@ testBuild:
|
|||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@@ -85,6 +93,8 @@ 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 prepare
|
||||||
|
|||||||
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -15,7 +15,7 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"projectType": {
|
"projectType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["website", "element", "service", "npm"]
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4117
package-lock.json
generated
4117
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartobject",
|
"name": "@pushrocks/smartobject",
|
||||||
"version": "1.0.2",
|
"version": "1.0.6",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "work with objects",
|
"description": "work with objects",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@@ -9,18 +9,20 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)",
|
"build": "(tsbuild --web)",
|
||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.52",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"@types/node": "^10.11.7",
|
"@types/node": "^14.14.35",
|
||||||
"tslint": "^5.11.0",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {},
|
"dependencies": {
|
||||||
|
"fast-deep-equal": "^3.1.3"
|
||||||
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
],
|
],
|
||||||
|
|||||||
17
test/test.both.ts
Normal file
17
test/test.both.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
import * as smartobject from '../ts/index';
|
||||||
|
|
||||||
|
tap.test('first test', async () => {
|
||||||
|
const result = smartobject.compareObjects(
|
||||||
|
{ thisIsEq: 'wow', thisIsDeepEq: { deeper: 'sodeep' } },
|
||||||
|
{ thisIsEq: 'wow', thisIsDeepEq: { deeper: 'sodeep' }, hey: 'there' }
|
||||||
|
);
|
||||||
|
console.log(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should fast deep equal objects', async () => {
|
||||||
|
expect(smartobject.fastDeepEqual({ hello: 'yes' }, { hello: 'yes' })).to.be.true;
|
||||||
|
expect(smartobject.fastDeepEqual({ hello: 'yes' }, { hello: 3 })).to.be.false;
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
12
test/test.ts
12
test/test.ts
@@ -1,12 +0,0 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
|
||||||
import * as smartobject from '../ts/index';
|
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
|
||||||
const result = smartobject.compareObjects(
|
|
||||||
{ thisIsEq: 'wow', thisIsDeepEq: { deeper: 'sodeep' } },
|
|
||||||
{ thisIsEq: 'wow', thisIsDeepEq: { deeper: 'sodeep' }, hey: 'there' }
|
|
||||||
);
|
|
||||||
console.log(result);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
||||||
24
ts/index.ts
24
ts/index.ts
@@ -1,5 +1,8 @@
|
|||||||
import * as plugins from './smartobject.plugins';
|
import * as plugins from './smartobject.plugins';
|
||||||
|
|
||||||
|
const fastDeepEqual = plugins.fastDeepEqual;
|
||||||
|
export { fastDeepEqual };
|
||||||
|
|
||||||
export interface IObjectCompareResult {
|
export interface IObjectCompareResult {
|
||||||
presentInBothProperties: string[];
|
presentInBothProperties: string[];
|
||||||
missingProperties: string[];
|
missingProperties: string[];
|
||||||
@@ -10,7 +13,10 @@ export interface IObjectCompareResult {
|
|||||||
equalProperties: string[];
|
equalProperties: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const compareObjects = (referenceObjectArg: any, comparisonObjectArg: any): IObjectCompareResult => {
|
export const compareObjects = (
|
||||||
|
referenceObjectArg: any,
|
||||||
|
comparisonObjectArg: any
|
||||||
|
): IObjectCompareResult => {
|
||||||
const returnComparisonObject = {
|
const returnComparisonObject = {
|
||||||
missingProperties: [],
|
missingProperties: [],
|
||||||
additionalProperties: [],
|
additionalProperties: [],
|
||||||
@@ -49,19 +55,27 @@ export const compareObjects = (referenceObjectArg: any, comparisonObjectArg: any
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lets find divergingProperties
|
// lets find divergingProperties
|
||||||
if (JSON.stringify(referenceObjectArg[currentProperty]) !== JSON.stringify(comparisonObjectArg[currentProperty])) {
|
if (
|
||||||
|
JSON.stringify(referenceObjectArg[currentProperty]) !==
|
||||||
|
JSON.stringify(comparisonObjectArg[currentProperty])
|
||||||
|
) {
|
||||||
returnComparisonObject.divergingProperties.push(currentProperty);
|
returnComparisonObject.divergingProperties.push(currentProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
// lets find equalProperties
|
// lets find equalProperties
|
||||||
if (JSON.stringify(referenceObjectArg[currentProperty]) === JSON.stringify(comparisonObjectArg[currentProperty])) {
|
if (
|
||||||
|
JSON.stringify(referenceObjectArg[currentProperty]) ===
|
||||||
|
JSON.stringify(comparisonObjectArg[currentProperty])
|
||||||
|
) {
|
||||||
returnComparisonObject.equalProperties.push(currentProperty);
|
returnComparisonObject.equalProperties.push(currentProperty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const currentProperty of Object.keys(returnComparisonObject)) {
|
for (const currentProperty of Object.keys(returnComparisonObject)) {
|
||||||
const propertySet = new Set(returnComparisonObject[currentProperty]);
|
const onlyUnique = (value, index, self) => {
|
||||||
const uniqueArray = [...propertySet];
|
return self.indexOf(value) === index;
|
||||||
|
};
|
||||||
|
const uniqueArray = returnComparisonObject[currentProperty].filter(onlyUnique);
|
||||||
returnComparisonObject[currentProperty] = uniqueArray;
|
returnComparisonObject[currentProperty] = uniqueArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
const removeme = {};
|
// tslint:disable-next-line: no-submodule-imports
|
||||||
export { removeme };
|
import fastDeepEqual from 'fast-deep-equal/es6';
|
||||||
|
|
||||||
|
export { fastDeepEqual };
|
||||||
|
|||||||
Reference in New Issue
Block a user