@stacksjs/strings 0.70.44 → 0.70.53

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2023 Open Web Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js CHANGED
@@ -298,6 +298,20 @@ function splitPrefixSuffix(input, options = {}) {
298
298
  function toString(v) {
299
299
  return Object.prototype.toString.call(v);
300
300
  }
301
+ function mask(value, character, index, length) {
302
+ if (character === "")
303
+ return value;
304
+ const len = value.length;
305
+ const start = index < 0 ? Math.max(0, len + index) : index;
306
+ if (start >= len)
307
+ return value;
308
+ const maskLen = length === undefined ? len - start : Math.max(0, length);
309
+ if (maskLen === 0)
310
+ return value;
311
+ const end = Math.min(len, start + maskLen);
312
+ const fill = character.charAt(0).repeat(end - start);
313
+ return value.slice(0, start) + fill + value.slice(end);
314
+ }
301
315
 
302
316
  // src/pluralize.ts
303
317
  var pluralRules = [];
@@ -1240,6 +1254,7 @@ export {
1240
1254
  pascalCase,
1241
1255
  paramCase,
1242
1256
  noCase,
1257
+ mask,
1243
1258
  lowercase,
1244
1259
  kebabCase,
1245
1260
  isUUID,
@@ -1 +1,23 @@
1
1
  export declare function toString(v: any): string;
2
+ /**
3
+ * Mask a portion of a string with a repeated character, Laravel-style
4
+ * (stacksjs/stacks#314).
5
+ *
6
+ * Useful for redacting PII in logs (credit card middle, phone digits,
7
+ * email local part) without losing the format. The mask character is
8
+ * repeated for `length` characters starting at `index`; `length` defaults
9
+ * to "all remaining characters from index to end of string."
10
+ *
11
+ * `index` is the character offset, not a byte offset. Negative `index`
12
+ * counts from the end of the string (`-4` = "start four characters from
13
+ * the end"). An out-of-range `index` returns the original string.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * mask('1234567890123456', '*', 4, 8) // → '1234********3456'
18
+ * mask('1234567890123456', '*', 4) // → '1234************'
19
+ * mask('1234567890123456', '*', -4, 4) // → '123456789012****'
20
+ * mask('hello@example.com', '*', 1, 4) // → 'h****@example.com'
21
+ * ```
22
+ */
23
+ export declare function mask(value: string, character: string, index: number, length?: number): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/strings",
3
3
  "type": "module",
4
- "version": "0.70.44",
4
+ "version": "0.70.53",
5
5
  "description": "The Stacks string utilities.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -60,9 +60,9 @@
60
60
  "prepublishOnly": "bun run build"
61
61
  },
62
62
  "devDependencies": {
63
- "@stacksjs/alias": "^0.70.44",
63
+ "@stacksjs/alias": "0.70.53",
64
64
  "better-dx": "^0.2.12",
65
- "@stacksjs/types": "^0.70.44"
65
+ "@stacksjs/types": "0.70.53"
66
66
  },
67
67
  "sideEffects": false
68
68
  }