@softwear/latestcollectioncore 1.0.187 → 1.0.188
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/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/projectObject.d.ts +5 -0
- package/dist/projectObject.js +23 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/projectObject.ts +16 -0
- package/test/projectObject.spec.js +25 -0
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export { default as hasOnlyDigits } from './hasOnlyDigits';
|
|
|
14
14
|
export { default as imageBinder } from './imageBinder';
|
|
15
15
|
export { default as isean13 } from './isean13';
|
|
16
16
|
export { default as pivotTable } from './pivotTable';
|
|
17
|
+
export { default as projectObject } from './projectObject';
|
|
17
18
|
export { default as reports, genPDF } from './reports';
|
|
18
19
|
export { default as round2 } from './round2';
|
|
19
20
|
export { default as sizeToMap } from './sizeToMap';
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.isAxiosError = exports.exponentialDelay = exports.axiosRetry = exports.createAxiosInstance = exports.lcAxios = exports.transaction = exports.sizeToMap = exports.round2 = exports.genPDF = exports.reports = exports.pivotTable = exports.isean13 = exports.imageBinder = exports.hasOnlyDigits = exports.hashBrand = exports.getPreferedPropertyMappings = exports.getBrandName = exports.findMetaBrandSetting = exports.findSkuByBarcode = exports.ensureImpliedProperties = exports.ensureArray = exports.edifact = exports.ean13 = exports.deepCopy = exports.buildPropertyMappingFn = exports.articleStatus = void 0;
|
|
20
|
+
exports.isAxiosError = exports.exponentialDelay = exports.axiosRetry = exports.createAxiosInstance = exports.lcAxios = exports.transaction = exports.sizeToMap = exports.round2 = exports.genPDF = exports.reports = exports.projectObject = exports.pivotTable = exports.isean13 = exports.imageBinder = exports.hasOnlyDigits = exports.hashBrand = exports.getPreferedPropertyMappings = exports.getBrandName = exports.findMetaBrandSetting = exports.findSkuByBarcode = exports.ensureImpliedProperties = exports.ensureArray = exports.edifact = exports.ean13 = exports.deepCopy = exports.buildPropertyMappingFn = exports.articleStatus = void 0;
|
|
21
21
|
var articleStatus_1 = require("./articleStatus");
|
|
22
22
|
Object.defineProperty(exports, "articleStatus", { enumerable: true, get: function () { return __importDefault(articleStatus_1).default; } });
|
|
23
23
|
var buildPropertyMappingFn_1 = require("./buildPropertyMappingFn");
|
|
@@ -50,6 +50,8 @@ var isean13_1 = require("./isean13");
|
|
|
50
50
|
Object.defineProperty(exports, "isean13", { enumerable: true, get: function () { return __importDefault(isean13_1).default; } });
|
|
51
51
|
var pivotTable_1 = require("./pivotTable");
|
|
52
52
|
Object.defineProperty(exports, "pivotTable", { enumerable: true, get: function () { return __importDefault(pivotTable_1).default; } });
|
|
53
|
+
var projectObject_1 = require("./projectObject");
|
|
54
|
+
Object.defineProperty(exports, "projectObject", { enumerable: true, get: function () { return __importDefault(projectObject_1).default; } });
|
|
53
55
|
var reports_1 = require("./reports");
|
|
54
56
|
Object.defineProperty(exports, "reports", { enumerable: true, get: function () { return __importDefault(reports_1).default; } });
|
|
55
57
|
Object.defineProperty(exports, "genPDF", { enumerable: true, get: function () { return reports_1.genPDF; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whitelist projection: builds a new object from a deep-cloned copy of `source`,
|
|
3
|
+
* copying only the listed property names (nested values are cloned with `source`).
|
|
4
|
+
*/
|
|
5
|
+
export default function projectObject<K extends string>(source: unknown, keys: readonly K[]): Record<K, unknown>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const deepCopy_1 = __importDefault(require("./deepCopy"));
|
|
7
|
+
/**
|
|
8
|
+
* Whitelist projection: builds a new object from a deep-cloned copy of `source`,
|
|
9
|
+
* copying only the listed property names (nested values are cloned with `source`).
|
|
10
|
+
*/
|
|
11
|
+
function projectObject(source, keys) {
|
|
12
|
+
const out = {};
|
|
13
|
+
if (source == null)
|
|
14
|
+
return out;
|
|
15
|
+
if (typeof source !== 'object')
|
|
16
|
+
return out;
|
|
17
|
+
const tmp = (0, deepCopy_1.default)(source);
|
|
18
|
+
for (const k of keys) {
|
|
19
|
+
out[k] = tmp[k];
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
exports.default = projectObject;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export { default as hasOnlyDigits } from './hasOnlyDigits'
|
|
|
14
14
|
export { default as imageBinder } from './imageBinder'
|
|
15
15
|
export { default as isean13 } from './isean13'
|
|
16
16
|
export { default as pivotTable } from './pivotTable'
|
|
17
|
+
export { default as projectObject } from './projectObject'
|
|
17
18
|
export { default as reports, genPDF } from './reports'
|
|
18
19
|
export { default as round2 } from './round2'
|
|
19
20
|
export { default as sizeToMap } from './sizeToMap'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import deepCopy from './deepCopy'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whitelist projection: builds a new object from a deep-cloned copy of `source`,
|
|
5
|
+
* copying only the listed property names (nested values are cloned with `source`).
|
|
6
|
+
*/
|
|
7
|
+
export default function projectObject<K extends string>(source: unknown, keys: readonly K[]): Record<K, unknown> {
|
|
8
|
+
const out = {} as Record<K, unknown>
|
|
9
|
+
if (source == null) return out
|
|
10
|
+
if (typeof source !== 'object') return out
|
|
11
|
+
const tmp = deepCopy(source) as Record<string, unknown>
|
|
12
|
+
for (const k of keys) {
|
|
13
|
+
out[k] = tmp[k]
|
|
14
|
+
}
|
|
15
|
+
return out
|
|
16
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const { deepCopy, projectObject } = require('../dist/index')
|
|
2
|
+
|
|
3
|
+
describe('projectObject', function () {
|
|
4
|
+
it('returns an empty object for null/undefined', function () {
|
|
5
|
+
expect(projectObject(null, ['a'])).toEqual({})
|
|
6
|
+
expect(projectObject(undefined, ['a'])).toEqual({})
|
|
7
|
+
})
|
|
8
|
+
it('returns an empty object for non-object primitives', function () {
|
|
9
|
+
expect(projectObject('x', ['a'])).toEqual({})
|
|
10
|
+
expect(projectObject(1, ['a'])).toEqual({})
|
|
11
|
+
})
|
|
12
|
+
it('copies only listed keys from a deep-cloned source', function () {
|
|
13
|
+
const src = { id: '1', name: 'n', extra: 'drop', nest: { x: 1 } }
|
|
14
|
+
const p = projectObject(src, ['id', 'nest'])
|
|
15
|
+
expect(p).toEqual({ id: '1', nest: { x: 1 } })
|
|
16
|
+
expect(p.nest).not.toBe(src.nest)
|
|
17
|
+
expect(deepCopy(src.nest)).toEqual(p.nest)
|
|
18
|
+
})
|
|
19
|
+
it('does not mutate the original when copying nested data', function () {
|
|
20
|
+
const src = { a: { b: 1 } }
|
|
21
|
+
const p = projectObject(src, ['a'])
|
|
22
|
+
p.a.b = 2
|
|
23
|
+
expect(src.a.b).toBe(1)
|
|
24
|
+
})
|
|
25
|
+
})
|