@crowdlinker/nestjs-commons
Advanced tools
Comparing version 0.0.17 to 0.0.18
@@ -7,2 +7,3 @@ /** | ||
export interface ModelErrorsInterface { | ||
EXPIRED?: string; | ||
INVALID?: string; | ||
@@ -12,2 +13,3 @@ DISABLED?: string; | ||
DUPLICATE_FOUND?: string; | ||
[key: string]: string; | ||
} | ||
@@ -14,0 +16,0 @@ /** |
@@ -10,2 +10,3 @@ "use strict"; | ||
exports.ModelErrors = { | ||
EXPIRED: 'Record has expired.', | ||
INVALID: 'Record is invalid.', | ||
@@ -12,0 +13,0 @@ DISABLED: 'Record is not accessible.', |
@@ -13,1 +13,39 @@ /** | ||
export declare const unsetObjectProperties: <T = any>(data: T, keys?: string[] | number[], shouldClone?: boolean) => Partial<T>; | ||
/** | ||
* Maps keys deeply | ||
* | ||
* @param {T} data | ||
* @param {callback: (cbValue?: any, cbKey?: any) => any} callback | ||
* | ||
* @returns {T} | ||
*/ | ||
export declare const mapKeysDeep: (data: any, callback: (cbValue?: any, cbKey?: any) => any) => any; | ||
/** | ||
* Maps values deeply | ||
* | ||
* @param {any} data | ||
* @param {callback: (cbValue?: any, cbKey?: any) => any} callback | ||
* | ||
* @returns {any} | ||
*/ | ||
export declare const mapValuesDeep: (data: any, callback: (cbValue?: any, cbKey?: any) => any) => any; | ||
/** | ||
* Converts object keys from snake_case to camelCase | ||
* | ||
* @function | ||
* | ||
* @param {any} data | ||
* | ||
* @returns {any} Returns data with converted key. | ||
*/ | ||
export declare const convertKeysFromSnakeToCamel: (data: any) => any; | ||
/** | ||
* Converts object keys from camelCases to snake_case | ||
* | ||
* @function | ||
* | ||
* @param {any} data | ||
* | ||
* @returns {any} Returns data with converted key. | ||
*/ | ||
export declare const convertKeysFromCamelToSnake: (data: any) => any; |
@@ -6,8 +6,13 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unsetObjectProperties = void 0; | ||
exports.convertKeysFromCamelToSnake = exports.convertKeysFromSnakeToCamel = exports.mapValuesDeep = exports.mapKeysDeep = exports.unsetObjectProperties = void 0; | ||
const has_1 = __importDefault(require("lodash/has")); | ||
const omit_1 = __importDefault(require("lodash/omit")); | ||
const unset_1 = __importDefault(require("lodash/unset")); | ||
const mapKeys_1 = __importDefault(require("lodash/mapKeys")); | ||
const isArray_1 = __importDefault(require("lodash/isArray")); | ||
const isObject_1 = __importDefault(require("lodash/isObject")); | ||
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep")); | ||
const mapValues_1 = __importDefault(require("lodash/mapValues")); | ||
const camelCase_1 = __importDefault(require("lodash/camelCase")); | ||
const snakeCase_1 = __importDefault(require("lodash/snakeCase")); | ||
/** | ||
@@ -37,1 +42,65 @@ * Unsets object properties. | ||
exports.unsetObjectProperties = unsetObjectProperties; | ||
/** | ||
* Maps keys deeply | ||
* | ||
* @param {T} data | ||
* @param {callback: (cbValue?: any, cbKey?: any) => any} callback | ||
* | ||
* @returns {T} | ||
*/ | ||
const mapKeysDeep = (data, callback) => { | ||
if (!data || isArray_1.default(data) || !isObject_1.default(data)) { | ||
return data; | ||
} | ||
return mapValues_1.default(mapKeys_1.default(data, callback), (value) => isObject_1.default(value) ? exports.mapKeysDeep(value, callback) : value); | ||
}; | ||
exports.mapKeysDeep = mapKeysDeep; | ||
/** | ||
* Maps values deeply | ||
* | ||
* @param {any} data | ||
* @param {callback: (cbValue?: any, cbKey?: any) => any} callback | ||
* | ||
* @returns {any} | ||
*/ | ||
const mapValuesDeep = (data, callback) => { | ||
if (!data || isArray_1.default(data) || !isObject_1.default(data)) { | ||
return data; | ||
} | ||
return isObject_1.default(data) | ||
? mapValues_1.default(data, (value) => exports.mapValuesDeep(value, callback)) | ||
: callback(data); | ||
}; | ||
exports.mapValuesDeep = mapValuesDeep; | ||
/** | ||
* Converts object keys from snake_case to camelCase | ||
* | ||
* @function | ||
* | ||
* @param {any} data | ||
* | ||
* @returns {any} Returns data with converted key. | ||
*/ | ||
const convertKeysFromSnakeToCamel = (data) => { | ||
if (!data || isArray_1.default(data) || !isObject_1.default(data)) { | ||
return data; | ||
} | ||
return exports.mapKeysDeep(data, (_, key) => camelCase_1.default(key)); | ||
}; | ||
exports.convertKeysFromSnakeToCamel = convertKeysFromSnakeToCamel; | ||
/** | ||
* Converts object keys from camelCases to snake_case | ||
* | ||
* @function | ||
* | ||
* @param {any} data | ||
* | ||
* @returns {any} Returns data with converted key. | ||
*/ | ||
const convertKeysFromCamelToSnake = (data) => { | ||
if (!data || isArray_1.default(data) || !isObject_1.default(data)) { | ||
return data; | ||
} | ||
return mapKeys_1.default(data, (_, key) => snakeCase_1.default(key)); | ||
}; | ||
exports.convertKeysFromCamelToSnake = convertKeysFromCamelToSnake; |
{ | ||
"name": "@crowdlinker/nestjs-commons", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"description": "Commons for NestJS based projects", | ||
@@ -5,0 +5,0 @@ "author": "Crowdlinker Inc.", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
143851
4545