cafe-utility 10.1.0 → 10.2.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.
Files changed (3) hide show
  1. package/index.d.ts +2 -0
  2. package/index.js +14 -1
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -214,6 +214,7 @@ declare function containsWord(string: string, word: string): boolean;
214
214
  declare function containsWords(string: string, words: string[]): boolean;
215
215
  declare function getCached<T>(key: string, ttlMillis: number, handler: () => Promise<T>): Promise<T>;
216
216
  declare function joinUrl(...parts: unknown[]): string;
217
+ declare function replaceBetweenStrings(string: string, start: string, end: string, replacement: string, keepBoundaries?: boolean): string;
217
218
  declare function sortObject<T>(object: CafeObject<T>): CafeObject<T>;
218
219
  declare function sortArray<T>(array: T[]): T[];
219
220
  declare function sortAny(any: unknown): unknown;
@@ -555,6 +556,7 @@ export declare const Strings: {
555
556
  resolveMarkdownLinks: typeof resolveMarkdownLinks;
556
557
  buildUrl: typeof buildUrl;
557
558
  isChinese: typeof isChinese;
559
+ replaceBetweenStrings: typeof replaceBetweenStrings;
558
560
  };
559
561
  export declare const Assertions: {
560
562
  asEqual: typeof asEqual;
package/index.js CHANGED
@@ -1421,6 +1421,18 @@ function joinUrl(...parts) {
1421
1421
  return url
1422
1422
  }
1423
1423
 
1424
+ function replaceBetweenStrings(string, start, end, replacement, keepBoundaries = true) {
1425
+ const startsAt = string.indexOf(start)
1426
+ const endsAt = string.indexOf(end, startsAt + start.length)
1427
+ if (startsAt === -1 || endsAt === -1) {
1428
+ throw Error('Start or end not found')
1429
+ }
1430
+ if (keepBoundaries) {
1431
+ return string.substring(0, startsAt + start.length) + replacement + string.substring(endsAt)
1432
+ }
1433
+ return string.substring(0, startsAt) + replacement + string.substring(endsAt + end.length)
1434
+ }
1435
+
1424
1436
  function sortObject(object) {
1425
1437
  const keys = Object.keys(object)
1426
1438
  const orderedKeys = keys.sort((a, b) => a.localeCompare(b))
@@ -2560,7 +2572,8 @@ exports.Strings = {
2560
2572
  represent,
2561
2573
  resolveMarkdownLinks,
2562
2574
  buildUrl,
2563
- isChinese
2575
+ isChinese,
2576
+ replaceBetweenStrings
2564
2577
  }
2565
2578
 
2566
2579
  exports.Assertions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "10.1.0",
3
+ "version": "10.2.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {