@nonara/ts-helpers
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.0.4](https://github.com/nonara/ts-helpers/compare/v0.0.3...v0.0.4) (2021-07-08) | ||
### Features | ||
* Add options to case-converters ([34e3010](https://github.com/nonara/ts-helpers/commit/34e3010f7f134a98279c7a639c3f86c4b35a2595)) | ||
### [0.0.3](https://github.com/nonara/ts-helpers/compare/v0.0.2...v0.0.3) (2021-07-07) | ||
@@ -7,0 +14,0 @@ |
@@ -1,2 +0,1 @@ | ||
import { CamelToSnakeCase, SnakeToCamelCase } from './type-helpers'; | ||
import deepCopy from 'rfdc'; | ||
@@ -45,22 +44,2 @@ import deepMerge from 'deepmerge'; | ||
export declare function normalizeAndJoinPaths(...paths: (string | undefined)[]): string; | ||
/** | ||
* Converts string from snake_case to camelCase | ||
*/ | ||
export declare function snakeToCamel<T extends string>(str: T): SnakeToCamelCase<T>; | ||
/** | ||
* Shallow copies object, converting property keys from snake_case to camelCase | ||
*/ | ||
export declare function snakeToCamel<T extends object>(obj: T): T extends Array<infer U> ? T : T extends null ? T : { | ||
[K in keyof T as SnakeToCamelCase<K>]: T[K]; | ||
}; | ||
/** | ||
* Converts string from camelCase to snake_case | ||
*/ | ||
export declare function camelToSnake<T extends string>(str: T): CamelToSnakeCase<T>; | ||
/** | ||
* Shallow copies object, converting property keys from camelCase to snake_case | ||
*/ | ||
export declare function camelToSnake<T extends object>(obj: T): T extends Array<infer U> ? T : T extends null ? T : { | ||
[K in keyof T as CamelToSnakeCase<K>]: T[K]; | ||
}; | ||
export { deepMerge, deepCopy }; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deepCopy = exports.deepMerge = exports.camelToSnake = exports.snakeToCamel = exports.normalizeAndJoinPaths = exports.truthyStr = exports.swallowError = exports.accForEach = exports.reverseMap = exports.cast = exports.isValidJSON = exports.isJSONObject = exports.isJSONObjectString = void 0; | ||
exports.deepCopy = exports.deepMerge = exports.normalizeAndJoinPaths = exports.truthyStr = exports.swallowError = exports.accForEach = exports.reverseMap = exports.cast = exports.isValidJSON = exports.isJSONObject = exports.isJSONObjectString = void 0; | ||
const rfdc_1 = __importDefault(require("rfdc")); | ||
@@ -105,29 +105,3 @@ exports.deepCopy = rfdc_1.default; | ||
exports.normalizeAndJoinPaths = normalizeAndJoinPaths; | ||
// @formatter:on | ||
function snakeToCamel(src) { | ||
if (typeof src === 'string') | ||
return src | ||
.toLowerCase() | ||
.replace(/[-_][a-zA-Z]/g, (group) => group.slice(-1).toUpperCase()); | ||
const res = Object.create(Object.getPrototypeOf(src), Object.getOwnPropertyDescriptors(src)); | ||
for (const [key, value] of Object.entries(res)) { | ||
delete res[key]; | ||
res[snakeToCamel(key)] = value; | ||
} | ||
return res; | ||
} | ||
exports.snakeToCamel = snakeToCamel; | ||
// @formatter:on | ||
function camelToSnake(src) { | ||
if (typeof src === 'string') | ||
return src.replace(/[A-Z]/g, (group) => `_${group.toLowerCase()}`); | ||
const res = Object.create(Object.getPrototypeOf(src), Object.getOwnPropertyDescriptors(src)); | ||
for (const [key, value] of Object.entries(res)) { | ||
delete res[key]; | ||
res[camelToSnake(key)] = value; | ||
} | ||
return res; | ||
} | ||
exports.camelToSnake = camelToSnake; | ||
// endregion | ||
//# sourceMappingURL=general-utils.js.map |
@@ -8,1 +8,2 @@ export * from './general-utils'; | ||
export * from './stash-utils'; | ||
export * from './case-converters'; |
@@ -20,2 +20,3 @@ "use strict"; | ||
__exportStar(require("./stash-utils"), exports); | ||
__exportStar(require("./case-converters"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@nonara/ts-helpers", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Helpers for TypeScript projects", | ||
@@ -12,3 +12,3 @@ "main": "dist/index.js", | ||
"------------- ": "-------------", | ||
"test": "jest --passWithNoTests", | ||
"test": "jest", | ||
"test:coverage": "jest --collect-coverage", | ||
@@ -36,2 +36,3 @@ "------------- ": "-------------", | ||
"@types/rfdc": "^1.1.0", | ||
"@types/jest": "^26.0.24", | ||
"deepmerge": "^4.2.2", | ||
@@ -38,0 +39,0 @@ "reflect-metadata": "^0.1.13", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
55282
45
881
8
+ Added@types/jest@^26.0.24
+ Added@jest/types@26.6.2(transitive)
+ Added@types/istanbul-lib-coverage@2.0.6(transitive)
+ Added@types/istanbul-lib-report@3.0.3(transitive)
+ Added@types/istanbul-reports@3.0.4(transitive)
+ Added@types/jest@26.0.24(transitive)
+ Added@types/node@22.8.6(transitive)
+ Added@types/yargs@15.0.19(transitive)
+ Added@types/yargs-parser@21.0.3(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addeddiff-sequences@26.6.2(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedjest-diff@26.6.2(transitive)
+ Addedjest-get-type@26.3.0(transitive)
+ Addedpretty-format@26.6.2(transitive)
+ Addedreact-is@17.0.2(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedundici-types@6.19.8(transitive)