smob 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.MD +94 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/module.js +89 -0
- package/dist/module.js.map +1 -0
- package/dist/type.js +9 -0
- package/dist/type.js.map +1 -0
- package/dist/utils/check.js +51 -0
- package/dist/utils/check.js.map +1 -0
- package/dist/utils/cut.js +41 -0
- package/dist/utils/cut.js.map +1 -0
- package/dist/utils/has-own-property.js +15 -0
- package/dist/utils/has-own-property.js.map +1 -0
- package/dist/utils/index.js +27 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/options.js +18 -0
- package/dist/utils/options.js.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Peter Placzek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.MD
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# SMOB 🧪
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/smob)
|
|
4
|
+
[](https://github.com/tada5hi/smob/actions/workflows/main.yml)
|
|
5
|
+
[](https://codecov.io/gh/tada5hi/smob)
|
|
6
|
+
|
|
7
|
+
This is a library to **s**afe **m**erge **ob**jects and other data structures.
|
|
8
|
+
|
|
9
|
+
**Table of Contents**
|
|
10
|
+
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Usage](#usage)
|
|
13
|
+
- [Merger](#merger)
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install smob --save
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { merge } from "smob";
|
|
25
|
+
|
|
26
|
+
const ob = merge(target, ...sources);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The following merge options are set by default:
|
|
30
|
+
- **priority**: `left`
|
|
31
|
+
The source aka leftmost object has by **default** the highest priority.
|
|
32
|
+
- **arrays**: `true`
|
|
33
|
+
Merge source and target arrays by priority order.
|
|
34
|
+
|
|
35
|
+
The merge behaviour can be changed by creating a custom [merger](#merger).
|
|
36
|
+
|
|
37
|
+
**Arguments**
|
|
38
|
+
- target `Record<string, any>`: The destination object to merge the source object(s).
|
|
39
|
+
- sources `Record<string, any>[]`: The source object(s).
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { merge } from 'smob';
|
|
43
|
+
|
|
44
|
+
console.log(merge({ a: 1 }, { a: 2 }, { a: 3 }));
|
|
45
|
+
// => { a: 1 }
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Merger
|
|
49
|
+
|
|
50
|
+
A custom merger can simply be created by using the `createMerger` method.
|
|
51
|
+
|
|
52
|
+
**Priority**
|
|
53
|
+
```typescript
|
|
54
|
+
import { createMerger } from 'smob';
|
|
55
|
+
|
|
56
|
+
const merge = createMerger({ priority: 'right' });
|
|
57
|
+
|
|
58
|
+
console.log(merge({ a: 1 }, { a: 2 }, { a: 3 }));
|
|
59
|
+
// => { a: 3 }
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Arrays**
|
|
63
|
+
```typescript
|
|
64
|
+
import { createMerger } from 'smob';
|
|
65
|
+
|
|
66
|
+
const merge = createMerger({ arrays: false });
|
|
67
|
+
|
|
68
|
+
console.log(merge({ a: [1,2,3] }, { a: [4,5,6] }));
|
|
69
|
+
// => { a: [1,2,3] }
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Strategy**
|
|
73
|
+
```typescript
|
|
74
|
+
import { createMerger } from 'smob';
|
|
75
|
+
|
|
76
|
+
const merge = createMerger({
|
|
77
|
+
strategy: (target, key, value) => {
|
|
78
|
+
if (
|
|
79
|
+
typeof target[key] === 'number' &&
|
|
80
|
+
typeof value === 'number'
|
|
81
|
+
) {
|
|
82
|
+
target[key] += value;
|
|
83
|
+
return target;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
console.log(merge({ a: 1 }, { a: 2 }, { a: 3 }));
|
|
91
|
+
// => { a: 6 }
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Return **undefined** if the default merge behaviour should be used for the current target source pair.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./module"), exports);
|
|
24
|
+
__exportStar(require("./utils"), exports);
|
|
25
|
+
__exportStar(require("./type"), exports);
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,0CAAwB;AACxB,yCAAuB"}
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
9
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
10
|
+
if (ar || !(i in from)) {
|
|
11
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
12
|
+
ar[i] = from[i];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.merge = exports.createMerger = exports.baseMerger = void 0;
|
|
19
|
+
var utils_1 = require("./utils");
|
|
20
|
+
function baseMerger(options, target) {
|
|
21
|
+
var _a, _b, _c, _d;
|
|
22
|
+
var sources = [];
|
|
23
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
24
|
+
sources[_i - 2] = arguments[_i];
|
|
25
|
+
}
|
|
26
|
+
if (!sources.length)
|
|
27
|
+
return target;
|
|
28
|
+
var source = sources.shift();
|
|
29
|
+
if ((0, utils_1.isObject)(target) &&
|
|
30
|
+
(0, utils_1.isObject)(source)) {
|
|
31
|
+
var keys = Object.keys(source);
|
|
32
|
+
for (var i = 0; i < keys.length; i++) {
|
|
33
|
+
var key = keys[i];
|
|
34
|
+
if (!(0, utils_1.isSafeKey)(key)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if ((0, utils_1.hasOwnProperty)(target, key)) {
|
|
38
|
+
if (options.strategy) {
|
|
39
|
+
var applied = options.strategy(target, key, source[key]);
|
|
40
|
+
if (typeof applied !== 'undefined') {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!(0, utils_1.isSafeObject)(source[key])) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if ((0, utils_1.isObject)(target[key]) &&
|
|
48
|
+
(0, utils_1.isObject)(source[key])) {
|
|
49
|
+
baseMerger(options, target[key], source[key]);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (options.arrays &&
|
|
53
|
+
Array.isArray(target[key]) &&
|
|
54
|
+
Array.isArray(source[key])) {
|
|
55
|
+
switch (options.priority) {
|
|
56
|
+
case 'left':
|
|
57
|
+
Object.assign(target, (_a = {}, _a[key] = target[key].concat(source[key]), _a));
|
|
58
|
+
break;
|
|
59
|
+
case 'right':
|
|
60
|
+
Object.assign(target, (_b = {}, _b[key] = source[key].concat(target[key]), _b));
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (options.priority === 'right') {
|
|
66
|
+
Object.assign(target, (_c = {}, _c[key] = source[key], _c));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
Object.assign(target, (_d = {}, _d[key] = source[key], _d));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return baseMerger.apply(void 0, __spreadArray([options, target], sources, false));
|
|
75
|
+
}
|
|
76
|
+
exports.baseMerger = baseMerger;
|
|
77
|
+
function createMerger(input) {
|
|
78
|
+
var options = (0, utils_1.buildOptions)(input);
|
|
79
|
+
return function (target) {
|
|
80
|
+
var sources = [];
|
|
81
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
82
|
+
sources[_i - 1] = arguments[_i];
|
|
83
|
+
}
|
|
84
|
+
return baseMerger.apply(void 0, __spreadArray([options, target], sources, false));
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
exports.createMerger = createMerger;
|
|
88
|
+
exports.merge = createMerger();
|
|
89
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;AAGH,iCAKiB;AAEjB,SAAgB,UAAU,CACtB,OAAgB,EAChB,MAAS;;IACT,iBAAe;SAAf,UAAe,EAAf,qBAAe,EAAf,IAAe;QAAf,gCAAe;;IAEf,IAAI,CAAC,OAAO,CAAC,MAAM;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+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
//# sourceMappingURL=type.js.map
|
package/dist/type.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.isSafeKey = exports.isSafeObject = exports.isObjectDeeperThan = exports.isObject = void 0;
|
|
10
|
+
var has_own_property_1 = require("./has-own-property");
|
|
11
|
+
function isObject(item) {
|
|
12
|
+
return (item &&
|
|
13
|
+
typeof item === 'object' &&
|
|
14
|
+
!Array.isArray(item));
|
|
15
|
+
}
|
|
16
|
+
exports.isObject = isObject;
|
|
17
|
+
function isObjectDeeperThan(value, depth) {
|
|
18
|
+
if (depth <= 0) {
|
|
19
|
+
return isObject(value);
|
|
20
|
+
}
|
|
21
|
+
if (typeof value !== 'object') {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
var nextDepth = depth - 1;
|
|
25
|
+
var keys = Object.keys(value);
|
|
26
|
+
for (var i = 0; i < keys.length; i++) {
|
|
27
|
+
if ((0, has_own_property_1.hasOwnProperty)(value, keys[i]) &&
|
|
28
|
+
isObjectDeeperThan(value[keys[i]], nextDepth)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
exports.isObjectDeeperThan = isObjectDeeperThan;
|
|
35
|
+
function isSafeObject(object) {
|
|
36
|
+
try {
|
|
37
|
+
JSON.stringify(object);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.isSafeObject = isSafeObject;
|
|
45
|
+
function isSafeKey(key) {
|
|
46
|
+
return key !== '__proto__' &&
|
|
47
|
+
key !== 'prototype' &&
|
|
48
|
+
key !== 'constructor';
|
|
49
|
+
}
|
|
50
|
+
exports.isSafeKey = isSafeKey;
|
|
51
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/utils/check.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uDAAoD;AAEpD,SAAgB,QAAQ,CAAC,IAAa;IAClC,OAAO,CACH,IAAI;QACJ,OAAO,IAAI,KAAK,QAAQ;QACxB,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CACvB,CAAC;AACN,CAAC;AAND,4BAMC;AAED,SAAgB,kBAAkB,CAAC,KAAc,EAAE,KAAa;IAC5D,IAAI,KAAK,IAAI,CAAC,EAAE;QACZ,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;KAC1B;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC3B,OAAO,KAAK,CAAC;KAChB;IAED,IAAM,SAAS,GAAG,KAAK,GAAG,CAAC,CAAC;IAC5B,IAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAClC,IACI,IAAA,iCAAc,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;YAC9B,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAC/C;YACE,OAAO,IAAI,CAAC;SACf;KACJ;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AArBD,gDAqBC;AAED,SAAgB,YAAY,CAAC,MAA2B;IACpD,IAAI;QACA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;KACf;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,KAAK,CAAC;KAChB;AACL,CAAC;AAPD,oCAOC;AAED,SAAgB,SAAS,CAAC,GAAW;IACjC,OAAO,GAAG,KAAK,WAAW;QACtB,GAAG,KAAK,WAAW;QACnB,GAAG,KAAK,aAAa,CAAC;AAC9B,CAAC;AAJD,8BAIC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
var __assign = (this && this.__assign) || function () {
|
|
9
|
+
__assign = Object.assign || function(t) {
|
|
10
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
11
|
+
s = arguments[i];
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
}
|
|
15
|
+
return t;
|
|
16
|
+
};
|
|
17
|
+
return __assign.apply(this, arguments);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.cutObject = void 0;
|
|
21
|
+
var check_1 = require("./check");
|
|
22
|
+
function cutObject(input, depth) {
|
|
23
|
+
if (depth < 0) {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
var value = __assign({}, input);
|
|
27
|
+
var keys = Object.keys(value);
|
|
28
|
+
for (var i = 0; i < keys.length; i++) {
|
|
29
|
+
if ((0, check_1.isObject)(value[keys[i]])) {
|
|
30
|
+
if (depth === 0) {
|
|
31
|
+
value[keys[i]] = {};
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
value[keys[i]] = cutObject(value[keys[i]], depth - 1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
exports.cutObject = cutObject;
|
|
41
|
+
//# sourceMappingURL=cut.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cut.js","sourceRoot":"","sources":["../../src/utils/cut.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;AAEH,iCAAmC;AAEnC,SAAgB,SAAS,CAAgC,KAAQ,EAAE,KAAa;IAC5E,IAAI,KAAK,GAAG,CAAC,EAAE;QACX,OAAO,EAAO,CAAC;KAClB;IAED,IAAM,KAAK,gBAAQ,KAAK,CAAE,CAAC;IAC3B,IAAM,IAAI,GAAiB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAE9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAClC,IAAI,IAAA,gBAAQ,EAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;YAC1B,IAAI,KAAK,KAAK,CAAC,EAAE;gBACb,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,EAAgB,CAAC;aACrC;iBAAM;gBACH,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;aACzD;SACJ;KACJ;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAnBD,8BAmBC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2021.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.hasOwnProperty = void 0;
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
11
|
+
function hasOwnProperty(obj, prop) {
|
|
12
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
}
|
|
14
|
+
exports.hasOwnProperty = hasOwnProperty;
|
|
15
|
+
//# sourceMappingURL=has-own-property.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-own-property.js","sourceRoot":"","sources":["../../src/utils/has-own-property.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,wDAAwD;AACxD,SAAgB,cAAc,CAAsC,GAAM,EAAE,IAAO;IAC/E,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAC3D,CAAC;AAFD,wCAEC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./check"), exports);
|
|
24
|
+
__exportStar(require("./cut"), exports);
|
|
25
|
+
__exportStar(require("./has-own-property"), exports);
|
|
26
|
+
__exportStar(require("./options"), exports);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,wCAAsB;AACtB,qDAAmC;AACnC,4CAA0B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.buildOptions = void 0;
|
|
10
|
+
function buildOptions(options) {
|
|
11
|
+
var _a;
|
|
12
|
+
options = options || {};
|
|
13
|
+
options.arrays = (_a = options.arrays) !== null && _a !== void 0 ? _a : true;
|
|
14
|
+
options.priority = options.priority || 'left';
|
|
15
|
+
return options;
|
|
16
|
+
}
|
|
17
|
+
exports.buildOptions = buildOptions;
|
|
18
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/utils/options.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAIH,SAAgB,YAAY,CAAC,OAA0B;;IACnD,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;IAExB,OAAO,CAAC,MAAM,GAAG,MAAA,OAAO,CAAC,MAAM,mCAAI,IAAI,CAAC;IACxC,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,MAAM,CAAC;IAE9C,OAAO,OAAkB,CAAC;AAC9B,CAAC;AAPD,oCAOC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "smob",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Safe merge objects.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"typings": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "rm -rf ./dist && tsc",
|
|
12
|
+
"lint": "eslint --ext .js,.ts ./src",
|
|
13
|
+
"lint:fix": "npm run lint -- --fix",
|
|
14
|
+
"test": "cross-env NODE_ENV=test jest --config ./test/jest.config.js",
|
|
15
|
+
"test:coverage": "npm run test -- --coverage",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "Peter Placzek",
|
|
20
|
+
"email": "contact@tada5hi.net",
|
|
21
|
+
"url": "https://github.com/tada5hi"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"keywords": [
|
|
25
|
+
"object",
|
|
26
|
+
"merge",
|
|
27
|
+
"safe",
|
|
28
|
+
"deep-merge",
|
|
29
|
+
"merge-deep"
|
|
30
|
+
],
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/Tada5hi/smob.git"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/Tada5hi/smob/issues"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/Tada5hi/smob#readme",
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@tada5hi/eslint-config-typescript": "^1.0.7",
|
|
41
|
+
"@types/jest": "^27.5.0",
|
|
42
|
+
"@types/node": "^18.7.17",
|
|
43
|
+
"cross-env": "^7.0.3",
|
|
44
|
+
"eslint": "^8.23.1",
|
|
45
|
+
"jest": "^27.5.1",
|
|
46
|
+
"np": "^7.6.2",
|
|
47
|
+
"ts-jest": "^27.1.4",
|
|
48
|
+
"typescript": "^4.8.3"
|
|
49
|
+
}
|
|
50
|
+
}
|