feat(helpers): move set, delete, serialize, type, get, to helpers

This commit is contained in:
Gervwyk 2020-10-17 18:12:27 +02:00
parent 56e14389be
commit f2d9999c27
40 changed files with 642 additions and 1029 deletions

1119
.pnp.js generated

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,13 +0,0 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "12",
"esmodules": true
}
}
]
]
}

View File

@ -1,11 +0,0 @@
module.exports = {
clearMocks: true,
collectCoverage: true,
collectCoverageFrom: ['src/**/*.js'],
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/test/'],
coverageReporters: ['lcov', 'text', 'clover'],
errorOnDeprecated: true,
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/dist/'],
};

View File

@ -1,43 +0,0 @@
{
"name": "@lowdefy/delete",
"version": "1.0.1",
"license": "Apache-2.0",
"description": "",
"homepage": "https://lowdefy.com",
"bugs": {
"url": "https://github.com/lowdefy/lowdefy/issues"
},
"contributors": [
{
"name": "Sam Tolmay",
"url": "https://github.com/SamTolmay"
},
{
"name": "Gerrie van Wyk",
"url": "https://github.com/Gervwyk"
}
],
"repository": {
"type": "git",
"url": "https://github.com/lowdefy/lowdefy.git"
},
"main": "dist/delete.js",
"scripts": {
"build": "babel src --out-dir dist",
"test": "jest --coverage",
"prepare": "yarn build",
"prepublishOnly": "yarn build",
"npm-publish": "npm publish --access public"
},
"dependencies": {
"@lowdefy/get": "1.0.1",
"@lowdefy/type": "1.0.1"
},
"devDependencies": {
"@babel/cli": "7.12.1",
"@babel/core": "7.12.1",
"@babel/preset-env": "7.12.1",
"babel-jest": "26.5.2",
"jest": "26.5.3"
}
}

View File

@ -1,13 +0,0 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "12",
"esmodules": true
}
}
]
]
}

View File

@ -1,11 +0,0 @@
module.exports = {
clearMocks: true,
collectCoverage: true,
collectCoverageFrom: ['src/**/*.js'],
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/test/'],
coverageReporters: ['lcov', 'text', 'clover'],
errorOnDeprecated: true,
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/dist/'],
};

View File

@ -1,43 +0,0 @@
{
"name": "@lowdefy/get",
"version": "1.0.1",
"license": "Apache-2.0",
"description": "",
"homepage": "https://lowdefy.com",
"bugs": {
"url": "https://github.com/lowdefy/lowdefy/issues"
},
"contributors": [
{
"name": "Sam Tolmay",
"url": "https://github.com/SamTolmay"
},
{
"name": "Gerrie van Wyk",
"url": "https://github.com/Gervwyk"
}
],
"repository": {
"type": "git",
"url": "https://github.com/lowdefy/lowdefy.git"
},
"main": "dist/get.js",
"scripts": {
"build": "babel src --out-dir dist",
"test": "jest --coverage",
"prepare": "yarn build",
"prepublishOnly": "yarn build",
"npm-publish": "npm publish --access public"
},
"dependencies": {
"@lowdefy/type": "1.0.1"
},
"devDependencies": {
"@babel/cli": "7.12.1",
"@babel/core": "7.12.1",
"@babel/preset-env": "7.12.1",
"babel-jest": "26.5.2",
"jest": "26.5.3",
"jest-diff": "26.5.2"
}
}

View File

@ -30,9 +30,6 @@
"npm-publish": "npm publish --access public"
},
"dependencies": {
"@lowdefy/delete": "1.0.1",
"@lowdefy/serializer": "1.0.0",
"@lowdefy/type": "1.0.1",
"lodash.merge": "4.6.2",
"query-string": "6.13.5"
},
@ -41,6 +38,7 @@
"@babel/core": "7.12.1",
"@babel/preset-env": "7.12.1",
"babel-jest": "26.5.2",
"jest": "26.5.3"
"jest": "26.5.3",
"jest-diff": "26.5.2"
}
}

View File

@ -14,7 +14,7 @@
limitations under the License.
*/
import type from '@lowdefy/type';
import type from './type';
const applyArrayIndices = (arrayIndices, name) => {
if (!type.isArray(arrayIndices)) return name;

View File

@ -16,7 +16,7 @@
limitations under the License.
*/
// Source:
// Derived from source:
// https://github.com/jonschlinkert/get-value/blob/master/index.js
// https://www.npmjs.com/package/get-value
@ -42,7 +42,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import typeTest from '@lowdefy/type';
import typeTest from './type';
function join(segs, joinChar, options) {
if (typeof options.join === 'function') {

View File

@ -15,8 +15,25 @@
*/
import applyArrayIndices from './applyArrayIndices';
import get from './get';
import mergeObjects from './mergeObjects';
import omit from './omit';
import serializer from './serializer';
import set from './set';
import stableStringify from './stableStringify';
import type from './type';
import unset from './unset';
import urlQuery from './urlQuery';
export { applyArrayIndices, mergeObjects, omit, urlQuery };
export {
applyArrayIndices,
get,
mergeObjects,
omit,
serializer,
set,
stableStringify,
type,
unset,
urlQuery,
};

View File

@ -14,9 +14,10 @@
limitations under the License.
*/
import type from '@lowdefy/type';
import merge from 'lodash.merge';
import type from './type';
const mergeObjects = (objects) => {
let merged = objects;
if (type.isArray(objects)) {

View File

@ -14,11 +14,11 @@
limitations under the License.
*/
import del from '@lowdefy/delete';
import unset from './unset';
const omit = (obj, list) => {
list.forEach((item) => {
del(obj, item);
unset(obj, item);
});
return obj;
};

View File

@ -16,7 +16,7 @@
limitations under the License.
*/
import type from '@lowdefy/type';
import type from './type';
import stableStringify from './stableStringify';
const makeReplacer = (customReplacer, isoStringDates) => (key, value) => {

View File

@ -18,7 +18,7 @@
limitations under the License.
*/
// Source:
// Derived from source:
// https://github.com/jonschlinkert/set-value/blob/master/index.js
// https://www.npmjs.com/package/set-value
@ -44,7 +44,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import type from '@lowdefy/type';
import type from './type';
function isValidKey(key) {
return key !== '__proto__' && key !== 'constructor' && key !== 'prototype';

View File

@ -19,6 +19,7 @@
limitations under the License.
*/
// Derived from source:
// https://github.com/substack/json-stable-stringify
// https://github.com/substack/json-stable-stringify/LICENCE
@ -41,7 +42,7 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import type from '@lowdefy/type';
import type from './type';
function stableStringify(obj, opts) {
if (!opts) opts = {};

View File

@ -17,8 +17,10 @@
limitations under the License.
*/
// Derived from source:
// because both js typeof and instance of sucks! use this.
// https://ultimatecourses.com/blog/understanding-javascript-types-and-reliable-type-checking
const { toString } = Object.prototype;
function ctorName(val) {

View File

@ -16,6 +16,7 @@
limitations under the License.
*/
// Derived from source:
// https://github.com/jonschlinkert/unset-value/blob/master/index.js
// https://github.com/jonschlinkert/unset-value/issues/3
// The MIT License (MIT)
@ -39,8 +40,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import type from '@lowdefy/type';
import get from '@lowdefy/get';
import type from './type';
import get from './get';
const hasValues = (val) => {
switch (type.typeOf(val)) {

View File

@ -14,9 +14,10 @@
limitations under the License.
*/
import type from '@lowdefy/type';
import queryString from 'query-string';
import serializer from '@lowdefy/serializer';
import serializer from './serializer';
import type from './type';
const parse = (str) => {
const parsed = queryString.parse(str);

View File

@ -19,10 +19,9 @@
// Copyright (c) 2014-2018, Jon Schlinkert.
// https://www.npmjs.com/package/get-value
import diff from 'jest-diff';
import get from '../src/get';
const diff = require('jest-diff');
const expectToEqual = (result, value) => {
expect(result).toEqual(value);
};

View File

@ -14,7 +14,7 @@
limitations under the License.
*/
import serializer from '../src/index';
import serializer from '../src/serializer';
test('serialize convert object js date to _date', () => {
let object = {

View File

@ -14,8 +14,7 @@
limitations under the License.
*/
import typeTest from '@lowdefy/type';
import typeTest from '../src/type';
import set, { split } from '../src/set';
test('setNestedValue - set a nested value in array object', () => {

View File

@ -14,118 +14,118 @@
limitations under the License.
*/
import del from '../src/delete';
import unset from '../src/unset';
test('delete a.1.b', () => {
test('unset a.1.b', () => {
const obj = {
a: [{ b: 2 }, { b: 5 }],
};
del(obj, 'a.1.b');
unset(obj, 'a.1.b');
expect(obj).toEqual({ a: [{ b: 2 }, {}] });
});
test('delete a.b', () => {
test('unset a.b', () => {
const obj = {
a: { b: [] },
};
del(obj, 'a.b');
unset(obj, 'a.b');
expect(obj).toEqual({ a: {} });
});
test('should update the given object when a property is deleted:', () => {
test('should update the given object when a property is unsetd:', () => {
const obj = { a: 'b' };
del(obj, 'a');
unset(obj, 'a');
expect(obj).toEqual({});
});
test('should delete nested values:', () => {
test('should unset nested values:', () => {
const one = { a: { b: { c: 'd' } } };
del(one, 'a.b');
unset(one, 'a.b');
expect(one).toEqual({ a: {} });
const two = { a: { b: { c: 'd' } } };
del(two, 'a.b.c');
unset(two, 'a.b.c');
expect(two).toEqual({ a: { b: {} } });
const three = { a: { b: { c: 'd', e: 'f' } } };
del(three, 'a.b.c');
unset(three, 'a.b.c');
expect(three).toEqual({ a: { b: { e: 'f' } } });
});
test('should delete...:', () => {
test('should unset...:', () => {
const three = { 'a.b': 'c', d: 'e' };
del(three, 'a.b');
unset(three, 'a.b');
expect(three).toEqual({ d: 'e' });
});
test('should delete nested escaped values:', () => {
test('should unset nested escaped values:', () => {
const one = { a: { 'b.c': 'd' } };
del(one, 'a.b\\.c');
unset(one, 'a.b\\.c');
expect(one).toEqual({ a: {} });
const two = { 'a.b.c': 'd' };
del(two, 'a\\.b\\.c');
unset(two, 'a\\.b\\.c');
expect(two).toEqual({});
const three = { 'a.b': 'c', d: 'e' };
del(three, 'a\\.b');
unset(three, 'a\\.b');
expect(three).toEqual({ d: 'e' });
});
describe('del', () => {
test('should update the given object when a property is deleted:', () => {
describe('unset', () => {
test('should update the given object when a property is unsetd:', () => {
const obj = { a: 'b' };
del(obj, 'a');
unset(obj, 'a');
expect(obj).toEqual({});
});
test('should return true when a property is deleted:', () => {
const res = del({ a: 'b' }, 'a');
test('should return true when a property is unsetd:', () => {
const res = unset({ a: 'b' }, 'a');
expect(res).toEqual(true);
});
test('should return true when the given property does not exist:', () => {
const res = del({ a: 'b' }, 'z');
const res = unset({ a: 'b' }, 'z');
expect(res).toEqual(true);
});
test('should delete nested values:', () => {
test('should unset nested values:', () => {
const one = { a: { b: { c: 'd' } } };
del(one, 'a.b');
unset(one, 'a.b');
expect(one).toEqual({ a: {} });
const two = { a: { b: { c: 'd' } } };
del(two, 'a.b.c');
unset(two, 'a.b.c');
expect(two).toEqual({ a: { b: {} } });
const three = { a: { b: { c: 'd', e: 'f' } } };
del(three, 'a.b.c');
unset(three, 'a.b.c');
expect(three).toEqual({ a: { b: { e: 'f' } } });
});
test('should delete...:', () => {
test('should unset...:', () => {
const three = { 'a.b': 'c', d: 'e' };
del(three, 'a.b');
unset(three, 'a.b');
expect(three).toEqual({ d: 'e' });
});
test('should delete nested escaped values:', () => {
test('should unset nested escaped values:', () => {
const one = { a: { 'b.c': 'd' } };
del(one, 'a.b\\.c');
unset(one, 'a.b\\.c');
expect(one).toEqual({ a: {} });
const two = { 'a.b.c': 'd' };
del(two, 'a\\.b\\.c');
unset(two, 'a\\.b\\.c');
expect(two).toEqual({});
const three = { 'a.b': 'c', d: 'e' };
del(three, 'a\\.b');
unset(three, 'a\\.b');
expect(three).toEqual({ d: 'e' });
});
test('should throw an error when invalid args are passed:', () => {
expect(() => {
del();
unset();
}).toThrow('expected an object.');
});
});

View File

@ -1,13 +0,0 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "12",
"esmodules": true
}
}
]
]
}

View File

@ -1,11 +0,0 @@
module.exports = {
clearMocks: true,
collectCoverage: true,
collectCoverageFrom: ['src/**/*.js'],
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/test/'],
coverageReporters: ['lcov', 'text', 'clover'],
errorOnDeprecated: true,
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/dist/'],
};

View File

@ -1,42 +0,0 @@
{
"name": "@lowdefy/serializer",
"version": "1.0.0",
"license": "Apache-2.0",
"description": "",
"homepage": "https://lowdefy.com",
"bugs": {
"url": "https://github.com/lowdefy/lowdefy/issues"
},
"contributors": [
{
"name": "Sam Tolmay",
"url": "https://github.com/SamTolmay"
},
{
"name": "Gerrie van Wyk",
"url": "https://github.com/Gervwyk"
}
],
"repository": {
"type": "git",
"url": "https://github.com/lowdefy/lowdefy.git"
},
"main": "dist/index.js",
"scripts": {
"build": "babel src --out-dir dist",
"test": "jest --coverage",
"prepare": "yarn build",
"prepublishOnly": "yarn build",
"npm-publish": "npm publish --access public"
},
"dependencies": {
"@lowdefy/type": "1.0.1"
},
"devDependencies": {
"@babel/cli": "7.12.1",
"@babel/core": "7.12.1",
"@babel/preset-env": "7.12.1",
"babel-jest": "26.5.2",
"jest": "26.5.3"
}
}

View File

@ -1,13 +0,0 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "12",
"esmodules": true
}
}
]
]
}

View File

@ -1,11 +0,0 @@
module.exports = {
clearMocks: true,
collectCoverage: true,
collectCoverageFrom: ['src/**/*.js'],
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/test/'],
coverageReporters: ['lcov', 'text', 'clover'],
errorOnDeprecated: true,
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/dist/'],
};

View File

@ -1,42 +0,0 @@
{
"name": "@lowdefy/set",
"version": "1.0.1",
"license": "Apache-2.0",
"description": "",
"homepage": "https://lowdefy.com",
"bugs": {
"url": "https://github.com/lowdefy/lowdefy/issues"
},
"contributors": [
{
"name": "Sam Tolmay",
"url": "https://github.com/SamTolmay"
},
{
"name": "Gerrie van Wyk",
"url": "https://github.com/Gervwyk"
}
],
"repository": {
"type": "git",
"url": "https://github.com/lowdefy/lowdefy.git"
},
"main": "dist/set.js",
"scripts": {
"build": "babel src --out-dir dist",
"test": "jest --coverage",
"prepare": "yarn build",
"prepublishOnly": "yarn build",
"npm-publish": "npm publish --access public"
},
"dependencies": {
"@lowdefy/type": "1.0.1"
},
"devDependencies": {
"@babel/cli": "7.12.1",
"@babel/core": "7.12.1",
"@babel/preset-env": "7.12.1",
"babel-jest": "26.5.2",
"jest": "26.5.3"
}
}

View File

@ -1,13 +0,0 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "12",
"esmodules": true
}
}
]
]
}

View File

@ -1,11 +0,0 @@
module.exports = {
clearMocks: true,
collectCoverage: true,
collectCoverageFrom: ['src/**/*.js'],
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/test/'],
coverageReporters: ['lcov', 'text', 'clover'],
errorOnDeprecated: true,
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/dist/'],
};

View File

@ -1,39 +0,0 @@
{
"name": "@lowdefy/type",
"version": "1.0.1",
"licence": "Apache-2.0",
"description": "",
"homepage": "https://lowdefy.com",
"bugs": {
"url": "https://github.com/lowdefy/lowdefy/issues"
},
"contributors": [
{
"name": "Sam Tolmay",
"url": "https://github.com/SamTolmay"
},
{
"name": "Gerrie van Wyk",
"url": "https://github.com/Gervwyk"
}
],
"repository": {
"type": "git",
"url": "https://github.com/lowdefy/lowdefy.git"
},
"main": "dist/type.js",
"scripts": {
"build": "babel src --out-dir dist",
"test": "jest --coverage",
"prepare": "yarn build",
"prepublishOnly": "yarn build",
"npm-publish": "npm publish --access public"
},
"devDependencies": {
"@babel/cli": "7.12.1",
"@babel/core": "7.12.1",
"@babel/preset-env": "7.12.1",
"babel-jest": "26.5.2",
"jest": "26.5.3"
}
}

View File

@ -3730,19 +3730,15 @@ __metadata:
languageName: unknown
linkType: soft
"@lowdefy/delete@1.0.1, @lowdefy/delete@workspace:packages/delete":
version: 0.0.0-use.local
resolution: "@lowdefy/delete@workspace:packages/delete"
"@lowdefy/delete@npm:1.0.1":
version: 1.0.1
resolution: "@lowdefy/delete@npm:1.0.1"
dependencies:
"@babel/cli": 7.12.1
"@babel/core": 7.12.1
"@babel/preset-env": 7.12.1
"@lowdefy/get": 1.0.1
"@lowdefy/type": 1.0.1
babel-jest: 26.5.2
jest: 26.5.3
languageName: unknown
linkType: soft
checksum: fee9d86f52643b4d2a8f68d732fec64f1805628fe6d1b42ff1bfea515b767ff8fb6198ee3fce49033f9edcb943676d0993ef537048e3118b6e7855dee4535c6e
languageName: node
linkType: hard
"@lowdefy/engine@0.0.0-experimental.0, @lowdefy/engine@workspace:packages/engine":
version: 0.0.0-use.local
@ -3804,19 +3800,14 @@ __metadata:
languageName: unknown
linkType: soft
"@lowdefy/get@1.0.1, @lowdefy/get@workspace:packages/get":
version: 0.0.0-use.local
resolution: "@lowdefy/get@workspace:packages/get"
"@lowdefy/get@npm:1.0.1":
version: 1.0.1
resolution: "@lowdefy/get@npm:1.0.1"
dependencies:
"@babel/cli": 7.12.1
"@babel/core": 7.12.1
"@babel/preset-env": 7.12.1
"@lowdefy/type": 1.0.1
babel-jest: 26.5.2
jest: 26.5.3
jest-diff: 26.5.2
languageName: unknown
linkType: soft
checksum: 6f66955a79f693620309ceb98684b7e612bef7d7e787fb7c4791498653b4911c7d8131e205bee781bf66c1c536b94db605fdca498d86699c7e13bac82d2a84f3
languageName: node
linkType: hard
"@lowdefy/graphql@0.0.0-experimental.0, @lowdefy/graphql@workspace:packages/graphql":
version: 0.0.0-use.local
@ -3847,11 +3838,9 @@ __metadata:
"@babel/cli": 7.12.1
"@babel/core": 7.12.1
"@babel/preset-env": 7.12.1
"@lowdefy/delete": 1.0.1
"@lowdefy/serializer": 1.0.0
"@lowdefy/type": 1.0.1
babel-jest: 26.5.2
jest: 26.5.3
jest-diff: 26.5.2
lodash.merge: 4.6.2
query-string: 6.13.5
languageName: unknown
@ -3981,43 +3970,23 @@ __metadata:
languageName: unknown
linkType: soft
"@lowdefy/serializer@1.0.0, @lowdefy/serializer@workspace:packages/serializer":
version: 0.0.0-use.local
resolution: "@lowdefy/serializer@workspace:packages/serializer"
"@lowdefy/serializer@npm:1.0.0":
version: 1.0.0
resolution: "@lowdefy/serializer@npm:1.0.0"
dependencies:
"@babel/cli": 7.12.1
"@babel/core": 7.12.1
"@babel/preset-env": 7.12.1
"@lowdefy/type": 1.0.1
babel-jest: 26.5.2
jest: 26.5.3
languageName: unknown
linkType: soft
checksum: 8880af5555339624160884adf32d611457d316779af312ea90ebfb64c555fe6021aa034b86bd76656c823db0a98fd0006f1e5cc80b94fb0bd92789bf8d8aa79c
languageName: node
linkType: hard
"@lowdefy/set@1.0.1, @lowdefy/set@workspace:packages/set":
version: 0.0.0-use.local
resolution: "@lowdefy/set@workspace:packages/set"
"@lowdefy/set@npm:1.0.1":
version: 1.0.1
resolution: "@lowdefy/set@npm:1.0.1"
dependencies:
"@babel/cli": 7.12.1
"@babel/core": 7.12.1
"@babel/preset-env": 7.12.1
"@lowdefy/type": 1.0.1
babel-jest: 26.5.2
jest: 26.5.3
languageName: unknown
linkType: soft
"@lowdefy/type@1.0.1, @lowdefy/type@workspace:packages/type":
version: 0.0.0-use.local
resolution: "@lowdefy/type@workspace:packages/type"
dependencies:
"@babel/cli": 7.12.1
"@babel/core": 7.12.1
"@babel/preset-env": 7.12.1
babel-jest: 26.5.2
jest: 26.5.3
languageName: unknown
linkType: soft
checksum: 80ef56f1873edd085bb72be4eb9f0241e9eb6709dc57c3387769b571f5c423157ab601234c32a24485c79789f04b9d4018686f5d44118ba02acff04d3d0d4351
languageName: node
linkType: hard
"@lowdefy/type@npm:1.0.0":
version: 1.0.0
@ -4026,6 +3995,13 @@ __metadata:
languageName: node
linkType: hard
"@lowdefy/type@npm:1.0.1":
version: 1.0.1
resolution: "@lowdefy/type@npm:1.0.1"
checksum: 42778b9f54ac984cc14f29e600d0e3cb794b9b944c66bc9098154c1c7cb50a3113161e4a9afc07815bd0f330014185aff0eabe34f3ebe07a02b4df4063ba8f5d
languageName: node
linkType: hard
"@mrmlnc/readdir-enhanced@npm:^2.2.1":
version: 2.2.1
resolution: "@mrmlnc/readdir-enhanced@npm:2.2.1"