@flumens/utils 0.7.0 → 0.8.0

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.
@@ -0,0 +1,4 @@
1
+ import { CamelizeKeys } from './type';
2
+ export declare const camelCase: (str: string) => string;
3
+ export declare const snakeCase: (str: string) => string;
4
+ export declare const getCamelCaseObj: <T extends Record<string, unknown>>(obj: T) => CamelizeKeys<T>;
package/dist/cases.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getCamelCaseObj=exports.snakeCase=exports.camelCase=void 0;exports.camelCase=e=>{if(!e)return"";return e.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/([A-Z])([A-Z][a-z])/g,"$1 $2").replace(/[^a-zA-Z0-9]+/g," ").trim().toLowerCase().split(/\s+/).map(((e,r)=>0===r?e:e.charAt(0).toUpperCase()+e.slice(1))).join("")};exports.snakeCase=e=>{if(!e)return"";return e.replace(/([a-z\d])([A-Z])/g,"$1 $2").replace(/([A-Z])([A-Z][a-z])/g,"$1 $2").replace(/[^a-zA-Z0-9]+/g," ").trim().toLowerCase().split(/\s+/).join("_")};exports.getCamelCaseObj=e=>((e,r)=>{const a={};return Object.keys(e).forEach((s=>{const t=s,o=r(e[t],s);a[o]=e[t]})),a})(e,((e,r)=>(0,exports.camelCase)(r)));
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { default as string } from './string.js';
2
2
  export { default as device } from './device.js';
3
+ export * from './cases.js';
3
4
  export * from './deferred.js';
4
5
  export * from './date.js';
5
6
  export * from './image.js';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.device=exports.string=void 0;const e=require("tslib");var r=require("./string.js");Object.defineProperty(exports,"string",{enumerable:!0,get:function(){return e.__importDefault(r).default}});var t=require("./device.js");Object.defineProperty(exports,"device",{enumerable:!0,get:function(){return e.__importDefault(t).default}}),e.__exportStar(require("./deferred.js"),exports),e.__exportStar(require("./date.js"),exports),e.__exportStar(require("./image.js"),exports),e.__exportStar(require("./location.js"),exports),e.__exportStar(require("./type.js"),exports),e.__exportStar(require("./sentry.js"),exports),e.__exportStar(require("./errors.js"),exports),e.__exportStar(require("./platform.js"),exports),e.__exportStar(require("./uuid.js"),exports),e.__exportStar(require("./MigrationManager.js"),exports);
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.device=exports.string=void 0;const e=require("tslib");var r=require("./string.js");Object.defineProperty(exports,"string",{enumerable:!0,get:function(){return e.__importDefault(r).default}});var t=require("./device.js");Object.defineProperty(exports,"device",{enumerable:!0,get:function(){return e.__importDefault(t).default}}),e.__exportStar(require("./cases.js"),exports),e.__exportStar(require("./deferred.js"),exports),e.__exportStar(require("./date.js"),exports),e.__exportStar(require("./image.js"),exports),e.__exportStar(require("./location.js"),exports),e.__exportStar(require("./type.js"),exports),e.__exportStar(require("./sentry.js"),exports),e.__exportStar(require("./errors.js"),exports),e.__exportStar(require("./platform.js"),exports),e.__exportStar(require("./uuid.js"),exports),e.__exportStar(require("./MigrationManager.js"),exports);
package/dist/type.d.ts CHANGED
@@ -40,12 +40,11 @@ export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
40
40
  * {a; b?; c}
41
41
  */
42
42
  export type OptionalExcept<T, K extends keyof T> = Pick<T, K> & Partial<T>;
43
+ type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}` : Lowercase<S>;
43
44
  /**
44
45
  * Transforms snake-case keys to camel-case.
45
- * https://medium.com/@fullstack-shepherd/typescript-transforming-types-with-snake-case-keys-to-camelcase-keys-or-how-to-keep-busy-in-9d5f074d9bfa
46
46
  */
47
- type Camelize<T extends string> = T extends `${infer A}_${infer B}` ? `${A}${Camelize<Capitalize<B>>}` : T;
48
- export type CamelizeKeys<T extends object> = {
49
- [key in keyof T as key extends string ? Camelize<key> : key]: T[key];
47
+ export type CamelizeKeys<T> = {
48
+ [K in keyof T as CamelCase<K & string>]: T[K];
50
49
  };
51
50
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flumens/utils",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -9,6 +9,7 @@
9
9
  "prepare": "npm run build",
10
10
  "test:eslint": "eslint src --quiet --ext .jsx --ext .ts --ext .tsx --ext .js && echo '\\033[37;42;1m PASS \\033[00m'",
11
11
  "postpublish": "TAG_NAME=utils-v\"$npm_package_version\" && git tag $TAG_NAME && git push origin \"$TAG_NAME\"",
12
+ "check": "npx tsc --noEmit --skipLibCheck && npm run test:eslint",
12
13
  "test": "jest --passWithNoTests",
13
14
  "test:watch": "jest --watchAll"
14
15
  },