@takeshape/util 9.40.2 → 9.41.2

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/strings.d.ts CHANGED
@@ -1,4 +1,14 @@
1
1
  export declare const camelCase: (str: string | string[]) => string;
2
+ /**
3
+ * Special function for preserving namespace case when pascal-casing.
4
+ */
5
+ export declare function formatShapeName(str: string): string;
6
+ export declare function formatShapeName(str: string[], options: {
7
+ shapeNameIndex: number;
8
+ }): string;
9
+ /**
10
+ * Optional config triggers a namespace-preserving behavior for built-in shapes starting with `TS`.
11
+ */
2
12
  export declare function pascalCase(str: string | string[]): string;
3
13
  export declare function isUuid(str: string): boolean;
4
14
  export declare function isEmptyString(str: unknown): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/strings.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS,QAAuB,MAAM,GAAG,MAAM,EAAE,KAAK,MAAM,CAAC;AAE1E,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAEzD;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE3C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAEnD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAM7D"}
1
+ {"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/strings.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,SAAS,QAAuB,MAAM,GAAG,MAAM,EAAE,KAAK,MAAM,CAAC;AAE1E;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;AACrD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE;IAAC,cAAc,EAAE,MAAM,CAAA;CAAC,GAAG,MAAM,CAAC;AAkC1F;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAEzD;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE3C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAEnD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAM7D"}
package/dist/strings.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.camelCase = void 0;
7
+ exports.formatShapeName = formatShapeName;
7
8
  exports.isEmptyString = isEmptyString;
8
9
  exports.isIntegerLike = isIntegerLike;
9
10
  exports.isUuid = isUuid;
@@ -17,11 +18,52 @@ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
17
18
 
18
19
  var _isString = _interopRequireDefault(require("lodash/isString"));
19
20
 
21
+ var _arrays = require("./arrays");
22
+
20
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
24
 
22
25
  const camelCase = _camelCase2.default;
26
+ /**
27
+ * Special function for preserving namespace case when pascal-casing.
28
+ */
29
+
23
30
  exports.camelCase = camelCase;
24
31
 
32
+ function formatShapeName(str, options) {
33
+ const strings = (0, _arrays.ensureArray)(str);
34
+ const shapeNameIndex = (options === null || options === void 0 ? void 0 : options.shapeNameIndex) ?? 0;
35
+ const shapeName = strings.at(shapeNameIndex); // If the shapeNameIndex is incorrect, behave as normal
36
+
37
+ if (!shapeName) {
38
+ throw new Error(`Could not find a ShapeName at index '${shapeNameIndex}'`);
39
+ }
40
+
41
+ const prefix = strings.slice(0, Math.max(shapeNameIndex, 0));
42
+ const suffix = strings.slice(shapeNameIndex + 1);
43
+ let arr = [];
44
+
45
+ if (prefix) {
46
+ arr = [...arr, pascalCase(prefix)];
47
+ }
48
+
49
+ if (shapeName.length > 2 && shapeName.startsWith('TS') && shapeName.charAt(2) === shapeName.charAt(2).toUpperCase()) {
50
+ // Built-in shape, prefixed with `TS`
51
+ arr = [...arr, shapeName];
52
+ } else {
53
+ arr = [...arr, pascalCase(shapeName)];
54
+ }
55
+
56
+ if (suffix) {
57
+ arr = [...arr, pascalCase(suffix)];
58
+ }
59
+
60
+ return arr.join('');
61
+ }
62
+ /**
63
+ * Optional config triggers a namespace-preserving behavior for built-in shapes starting with `TS`.
64
+ */
65
+
66
+
25
67
  function pascalCase(str) {
26
68
  return (0, _upperFirst.default)(camelCase(str));
27
69
  }
package/es/strings.js CHANGED
@@ -2,7 +2,46 @@ import upperFirst from 'lodash/upperFirst';
2
2
  import _camelCase from 'lodash/camelCase';
3
3
  import isEmpty from 'lodash/isEmpty';
4
4
  import isString from 'lodash/isString';
5
+ import { ensureArray } from './arrays';
5
6
  export const camelCase = _camelCase;
7
+ /**
8
+ * Special function for preserving namespace case when pascal-casing.
9
+ */
10
+
11
+ export function formatShapeName(str, options) {
12
+ const strings = ensureArray(str);
13
+ const shapeNameIndex = (options === null || options === void 0 ? void 0 : options.shapeNameIndex) ?? 0;
14
+ const shapeName = strings.at(shapeNameIndex); // If the shapeNameIndex is incorrect, behave as normal
15
+
16
+ if (!shapeName) {
17
+ throw new Error(`Could not find a ShapeName at index '${shapeNameIndex}'`);
18
+ }
19
+
20
+ const prefix = strings.slice(0, Math.max(shapeNameIndex, 0));
21
+ const suffix = strings.slice(shapeNameIndex + 1);
22
+ let arr = [];
23
+
24
+ if (prefix) {
25
+ arr = [...arr, pascalCase(prefix)];
26
+ }
27
+
28
+ if (shapeName.length > 2 && shapeName.startsWith('TS') && shapeName.charAt(2) === shapeName.charAt(2).toUpperCase()) {
29
+ // Built-in shape, prefixed with `TS`
30
+ arr = [...arr, shapeName];
31
+ } else {
32
+ arr = [...arr, pascalCase(shapeName)];
33
+ }
34
+
35
+ if (suffix) {
36
+ arr = [...arr, pascalCase(suffix)];
37
+ }
38
+
39
+ return arr.join('');
40
+ }
41
+ /**
42
+ * Optional config triggers a namespace-preserving behavior for built-in shapes starting with `TS`.
43
+ */
44
+
6
45
  export function pascalCase(str) {
7
46
  return upperFirst(camelCase(str));
8
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/util",
3
- "version": "9.40.2",
3
+ "version": "9.41.2",
4
4
  "description": "Shared utilities",
5
5
  "homepage": "https://www.takeshape.io",
6
6
  "repository": {
@@ -32,7 +32,7 @@
32
32
  "prismjs": "^1.25.0",
33
33
  "shortid": "^2.2.16",
34
34
  "url-parse": "^1.5.3",
35
- "@takeshape/routing": "9.40.2"
35
+ "@takeshape/routing": "9.41.2"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/classnames": "^2.2.9",
@@ -45,7 +45,7 @@
45
45
  "@types/prismjs": "^1.16.2",
46
46
  "@types/shortid": "^0.0.29",
47
47
  "stripe": "8.81.0",
48
- "@takeshape/typescript-jest-junit-reporter": "9.40.2"
48
+ "@takeshape/typescript-jest-junit-reporter": "9.41.2"
49
49
  },
50
50
  "engines": {
51
51
  "node": ">=16"