@papillonarts/library 0.39.0 → 0.41.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.
@@ -1,8 +1,67 @@
1
- export declare function getCapizalizedString({ string, separator }: {
2
- string: string;
3
- separator: string;
1
+ /**
2
+ * Capitalize the first character of each segment in a string split by a separator.
3
+ *
4
+ * Splits the input string by the specified separator, trims whitespace from each segment,
5
+ * filters out empty segments, capitalizes the first character of each remaining segment,
6
+ * and joins them with spaces.
7
+ *
8
+ * @param {Object} params - Function parameters
9
+ * @param {string} [params.input] - The string to capitalize. Accepts undefined or empty strings, which return an empty string.
10
+ * @param {string} [params.separator='-'] - The delimiter to split segments. Defaults to hyphen.
11
+ * @returns {string} Capitalized string with segments joined by spaces, or empty string if input is falsy/empty.
12
+ *
13
+ * @example
14
+ * getCapitalizedString({ input: 'hello-world', separator: '-' })
15
+ * // => 'Hello World'
16
+ *
17
+ * @example
18
+ * getCapitalizedString({ input: ' foo - bar ', separator: '-' })
19
+ * // => 'Foo Bar'
20
+ *
21
+ * @example
22
+ * getCapitalizedString({ input: undefined })
23
+ * // => ''
24
+ */
25
+ export declare function getCapitalizedString({ input, separator }: {
26
+ input?: string;
27
+ separator?: string;
4
28
  }): string;
29
+ /**
30
+ * Generate a random alphanumeric string using base-36 encoding.
31
+ *
32
+ * Uses `Math.random()` (non-cryptographic) to produce a lowercase alphanumeric string.
33
+ * String length is variable (~11 characters typical, but not guaranteed).
34
+ *
35
+ * @returns {string} A random alphanumeric string with letters (a-z) and digits (0-9).
36
+ *
37
+ * @example
38
+ * getRandomAlphanumericString()
39
+ * // => '4feornbt361' (example output, varies each call)
40
+ *
41
+ * @note For cryptographic purposes, use `crypto.getRandomValues()` or `crypto.randomUUID()` instead.
42
+ */
5
43
  export declare function getRandomAlphanumericString(): string;
44
+ /**
45
+ * Generate a random alphanumeric string of a specific length.
46
+ *
47
+ * Creates a string of the requested length using characters from the alphanumeric set
48
+ * (A-Z, a-z, 0-9). Uses `Math.random()` for character selection (non-cryptographic).
49
+ *
50
+ * @param {Object} params - Function parameters
51
+ * @param {number} params.length - Desired string length. Must be a non-negative integer.
52
+ * @returns {string} A random alphanumeric string of exactly the specified length, or empty string if length is 0.
53
+ * @throws {TypeError} If length is not a non-negative integer.
54
+ *
55
+ * @example
56
+ * getRandomAlphanumericStringByLength({ length: 8 })
57
+ * // => 'aB3xYz9W' (example output, varies each call)
58
+ *
59
+ * @example
60
+ * getRandomAlphanumericStringByLength({ length: 0 })
61
+ * // => ''
62
+ *
63
+ * @note For cryptographic purposes, use `crypto.getRandomValues()` instead.
64
+ */
6
65
  export declare function getRandomAlphanumericStringByLength({ length }: {
7
66
  length: number;
8
67
  }): string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,EAAE,MAAM,EAAE,SAAe,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAK/G;AAED,wBAAgB,2BAA2B,IAAI,MAAM,CAEpD;AAED,wBAAgB,mCAAmC,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAO1F"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,KAAK,EAAE,SAAe,EAAE,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAS/G;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CAEpD;AAID;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mCAAmC,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAY1F"}
@@ -3,26 +3,96 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getCapizalizedString = getCapizalizedString;
6
+ exports.getCapitalizedString = getCapitalizedString;
7
7
  exports.getRandomAlphanumericString = getRandomAlphanumericString;
8
8
  exports.getRandomAlphanumericStringByLength = getRandomAlphanumericStringByLength;
9
- function getCapizalizedString(_ref) {
10
- var string = _ref.string,
9
+ /**
10
+ * Capitalize the first character of each segment in a string split by a separator.
11
+ *
12
+ * Splits the input string by the specified separator, trims whitespace from each segment,
13
+ * filters out empty segments, capitalizes the first character of each remaining segment,
14
+ * and joins them with spaces.
15
+ *
16
+ * @param {Object} params - Function parameters
17
+ * @param {string} [params.input] - The string to capitalize. Accepts undefined or empty strings, which return an empty string.
18
+ * @param {string} [params.separator='-'] - The delimiter to split segments. Defaults to hyphen.
19
+ * @returns {string} Capitalized string with segments joined by spaces, or empty string if input is falsy/empty.
20
+ *
21
+ * @example
22
+ * getCapitalizedString({ input: 'hello-world', separator: '-' })
23
+ * // => 'Hello World'
24
+ *
25
+ * @example
26
+ * getCapitalizedString({ input: ' foo - bar ', separator: '-' })
27
+ * // => 'Foo Bar'
28
+ *
29
+ * @example
30
+ * getCapitalizedString({ input: undefined })
31
+ * // => ''
32
+ */
33
+ function getCapitalizedString(_ref) {
34
+ var input = _ref.input,
11
35
  _ref$separator = _ref.separator,
12
36
  separator = _ref$separator === void 0 ? '-' : _ref$separator;
13
- var splitted = string.split(separator);
14
- var capitalized = splitted.map(function (splittedItem) {
15
- return "".concat(splittedItem.charAt(0).toUpperCase()).concat(splittedItem.slice(1));
16
- });
17
- return capitalized.join(' ');
37
+ if (typeof input !== 'string' || input.length === 0) return '';
38
+ var parts = input.split(separator).map(function (p) {
39
+ return p.trim();
40
+ }).filter(Boolean);
41
+ if (parts.length === 0) return '';
42
+ return parts.map(function (part) {
43
+ return "".concat(part.charAt(0).toUpperCase()).concat(part.slice(1));
44
+ }).join(' ');
18
45
  }
46
+
47
+ /**
48
+ * Generate a random alphanumeric string using base-36 encoding.
49
+ *
50
+ * Uses `Math.random()` (non-cryptographic) to produce a lowercase alphanumeric string.
51
+ * String length is variable (~11 characters typical, but not guaranteed).
52
+ *
53
+ * @returns {string} A random alphanumeric string with letters (a-z) and digits (0-9).
54
+ *
55
+ * @example
56
+ * getRandomAlphanumericString()
57
+ * // => '4feornbt361' (example output, varies each call)
58
+ *
59
+ * @note For cryptographic purposes, use `crypto.getRandomValues()` or `crypto.randomUUID()` instead.
60
+ */
19
61
  function getRandomAlphanumericString() {
20
62
  return Math.random().toString(36).slice(2);
21
63
  }
64
+ var ALPHANUMERIC_CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
65
+
66
+ /**
67
+ * Generate a random alphanumeric string of a specific length.
68
+ *
69
+ * Creates a string of the requested length using characters from the alphanumeric set
70
+ * (A-Z, a-z, 0-9). Uses `Math.random()` for character selection (non-cryptographic).
71
+ *
72
+ * @param {Object} params - Function parameters
73
+ * @param {number} params.length - Desired string length. Must be a non-negative integer.
74
+ * @returns {string} A random alphanumeric string of exactly the specified length, or empty string if length is 0.
75
+ * @throws {TypeError} If length is not a non-negative integer.
76
+ *
77
+ * @example
78
+ * getRandomAlphanumericStringByLength({ length: 8 })
79
+ * // => 'aB3xYz9W' (example output, varies each call)
80
+ *
81
+ * @example
82
+ * getRandomAlphanumericStringByLength({ length: 0 })
83
+ * // => ''
84
+ *
85
+ * @note For cryptographic purposes, use `crypto.getRandomValues()` instead.
86
+ */
22
87
  function getRandomAlphanumericStringByLength(_ref2) {
23
88
  var length = _ref2.length;
24
- var randomAlphanumericString = '';
25
- var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
26
- for (var i = 0; i < length; i += 1) randomAlphanumericString += characters.charAt(Math.floor(Math.random() * characters.length));
27
- return randomAlphanumericString !== '' ? randomAlphanumericString : getRandomAlphanumericString();
89
+ var n = Number(length);
90
+ if (!Number.isInteger(n) || n < 0) throw new TypeError('length must be a non-negative integer');
91
+ if (n === 0) return '';
92
+ var result = '';
93
+ var charsLen = ALPHANUMERIC_CHARACTERS.length;
94
+ for (var i = 0; i < n; i += 1) {
95
+ result += ALPHANUMERIC_CHARACTERS.charAt(Math.floor(Math.random() * charsLen));
96
+ }
97
+ return result;
28
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@papillonarts/library",
3
- "version": "0.39.0",
3
+ "version": "0.41.0",
4
4
  "description": "Papillon Arts Library",
5
5
  "homepage": "https://github.com/papillonarts/papillonarts/tree/master/packages/library",
6
6
  "repository": {
@@ -43,5 +43,5 @@
43
43
  "build-acceptance": "npm run build",
44
44
  "build-release": "npm run build"
45
45
  },
46
- "gitHead": "b8f07f71414d7133bc1cfa967ecf30ebca383ef7"
46
+ "gitHead": "38632df415e9a45e174ea18880ce31b17f8ae2e5"
47
47
  }
@@ -1,2 +0,0 @@
1
- export declare function getAppMockStore(customAppState: any): any;
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/store/mock/index.ts"],"names":[],"mappings":"AAIA,wBAAgB,eAAe,CAAC,cAAc,KAAA,OAE7C"}
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getAppMockStore = getAppMockStore;
8
- var _reduxMockStore = _interopRequireDefault(require("redux-mock-store"));
9
- var _reduxThunk = require("redux-thunk");
10
- /* eslint-disable import-x/no-named-as-default */
11
-
12
- function getAppMockStore(customAppState) {
13
- return (0, _reduxMockStore["default"])([_reduxThunk.thunk])(customAppState);
14
- }