cafe-utility 18.1.0 → 18.3.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 +9 -0
  2. package/index.js +33 -1
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -199,6 +199,11 @@ declare function hashCode(string: string): number;
199
199
  declare function replaceWord(string: string, search: string, replace: string, whitespaceOnly?: boolean): string;
200
200
  declare function replacePascalCaseWords(string: string, replacer: (word: string) => string): string;
201
201
  declare function stripHtml(string: string): string;
202
+ declare function breakLine(string: string): {
203
+ line: string;
204
+ rest: string;
205
+ };
206
+ declare function toLines(string: string, maxWidth: number, characterWidths?: Record<string, number>): string[];
202
207
  declare function containsWord(string: string, word: string): boolean;
203
208
  declare function containsWords(string: string, words: string[], mode: 'any' | 'all'): boolean;
204
209
  declare function parseHtmlAttributes(string: string): Record<string, string>;
@@ -382,6 +387,7 @@ interface Newable<T> extends Function {
382
387
  new (...args: any[]): T;
383
388
  }
384
389
  declare function findInstance<T, K extends T>(array: T[], type: Newable<K>): Optional<K>;
390
+ declare function filterInstances<T, K extends T>(array: T[], type: Newable<K>): K[];
385
391
  declare function interleave<T, K>(arrayA: T[], arrayB: K[]): (T | K)[];
386
392
  type Playbook<T> = {
387
393
  ttl: number;
@@ -472,6 +478,7 @@ export declare const Arrays: {
472
478
  bringToFront: typeof bringToFront;
473
479
  bringToFrontInPlace: typeof bringToFrontInPlace;
474
480
  findInstance: typeof findInstance;
481
+ filterInstances: typeof filterInstances;
475
482
  interleave: typeof interleave;
476
483
  };
477
484
  export declare const System: {
@@ -707,6 +714,8 @@ export declare const Strings: {
707
714
  replaceWord: typeof replaceWord;
708
715
  replacePascalCaseWords: typeof replacePascalCaseWords;
709
716
  stripHtml: typeof stripHtml;
717
+ breakLine: typeof breakLine;
718
+ toLines: typeof toLines;
710
719
  };
711
720
  export declare const Assertions: {
712
721
  asEqual: typeof asEqual;
package/index.js CHANGED
@@ -1053,6 +1053,32 @@ function replacePascalCaseWords(n, t) {
1053
1053
  function stripHtml(n) {
1054
1054
  return n.replace(/<[^>]*>/g, '')
1055
1055
  }
1056
+ function breakLine(n) {
1057
+ const t = n.lastIndexOf(' ')
1058
+ if (t === -1) return { line: n, rest: '' }
1059
+ const e = n.slice(0, t),
1060
+ r = n.slice(t + 1)
1061
+ return { line: e, rest: r }
1062
+ }
1063
+ function toLines(n, t, e = {}) {
1064
+ const r = []
1065
+ let o = '',
1066
+ i = 0
1067
+ for (let s = 0; s < n.length; s++) {
1068
+ const c = n[s],
1069
+ u = e[c] || 1
1070
+ if (((o += c), (i += u), i > t)) {
1071
+ const { line: l, rest: f } = breakLine(o)
1072
+ r.push(l),
1073
+ (o = f),
1074
+ (i = f
1075
+ .split('')
1076
+ .map(a => e[a] || 1)
1077
+ .reduce((a, h) => a + h, 0))
1078
+ }
1079
+ }
1080
+ return o && r.push(o), r
1081
+ }
1056
1082
  function containsWord(n, t) {
1057
1083
  return new RegExp(`\\b${t}\\b`).test(n)
1058
1084
  }
@@ -1802,6 +1828,9 @@ function findInstance(n, t) {
1802
1828
  const e = n.find(r => r instanceof t)
1803
1829
  return Optional.of(e)
1804
1830
  }
1831
+ function filterInstances(n, t) {
1832
+ return n.filter(e => e instanceof t)
1833
+ }
1805
1834
  function interleave(n, t) {
1806
1835
  const e = [],
1807
1836
  r = Math.max(n.length, t.length)
@@ -2089,6 +2118,7 @@ function raycastCircle(n, t, e) {
2089
2118
  bringToFront,
2090
2119
  bringToFrontInPlace,
2091
2120
  findInstance,
2121
+ filterInstances,
2092
2122
  interleave
2093
2123
  }),
2094
2124
  (exports.System = { sleepMillis, forever, scheduleMany, waitFor, expandError }),
@@ -2312,7 +2342,9 @@ function raycastCircle(n, t, e) {
2312
2342
  hashCode,
2313
2343
  replaceWord,
2314
2344
  replacePascalCaseWords,
2315
- stripHtml
2345
+ stripHtml,
2346
+ breakLine,
2347
+ toLines
2316
2348
  }),
2317
2349
  (exports.Assertions = { asEqual, asTrue, asTruthy, asFalse, asFalsy, asEither }),
2318
2350
  (exports.Cache = { get: getCached }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "18.1.0",
3
+ "version": "18.3.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {