@dnax/core 0.6.0 → 0.6.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/package.json +1 -1
- package/utils/index.ts +28 -0
package/package.json
CHANGED
package/utils/index.ts
CHANGED
|
@@ -232,6 +232,33 @@ function omit(data: object[] | object, keysToRemove: string[]) {
|
|
|
232
232
|
});
|
|
233
233
|
return json;
|
|
234
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
*
|
|
237
|
+
* @param {object|object[]} data - data
|
|
238
|
+
* @param {string[]} keys - keys to pick
|
|
239
|
+
* @returns {object|object[]} - data with the keys
|
|
240
|
+
|
|
241
|
+
*/
|
|
242
|
+
function pick(data: object | object[], keys: string[]): object {
|
|
243
|
+
const extractValues = (item) => {
|
|
244
|
+
return keys.reduce((result, keyPath) => {
|
|
245
|
+
const keys = keyPath.split(".");
|
|
246
|
+
const value = keys.reduce((acc, key) => acc && acc[key], item);
|
|
247
|
+
if (value !== undefined) {
|
|
248
|
+
result[keyPath] = value;
|
|
249
|
+
}
|
|
250
|
+
return result;
|
|
251
|
+
}, {});
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
if (Array.isArray(data)) {
|
|
255
|
+
return data.map((item) => extractValues(item));
|
|
256
|
+
} else if (typeof data === "object" && data !== null) {
|
|
257
|
+
return extractValues(data);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return {};
|
|
261
|
+
}
|
|
235
262
|
|
|
236
263
|
class contextError extends Error {
|
|
237
264
|
constructor(message: string, code: number) {
|
|
@@ -253,6 +280,7 @@ const password = {
|
|
|
253
280
|
};
|
|
254
281
|
|
|
255
282
|
export {
|
|
283
|
+
pick,
|
|
256
284
|
password, // Hash and verify Password utils
|
|
257
285
|
email, // smtp utils
|
|
258
286
|
moment,
|