cafe-utility 18.2.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 +7 -0
  2. package/index.js +29 -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>;
@@ -709,6 +714,8 @@ export declare const Strings: {
709
714
  replaceWord: typeof replaceWord;
710
715
  replacePascalCaseWords: typeof replacePascalCaseWords;
711
716
  stripHtml: typeof stripHtml;
717
+ breakLine: typeof breakLine;
718
+ toLines: typeof toLines;
712
719
  };
713
720
  export declare const Assertions: {
714
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
  }
@@ -2316,7 +2342,9 @@ function raycastCircle(n, t, e) {
2316
2342
  hashCode,
2317
2343
  replaceWord,
2318
2344
  replacePascalCaseWords,
2319
- stripHtml
2345
+ stripHtml,
2346
+ breakLine,
2347
+ toLines
2320
2348
  }),
2321
2349
  (exports.Assertions = { asEqual, asTrue, asTruthy, asFalse, asFalsy, asEither }),
2322
2350
  (exports.Cache = { get: getCached }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "18.2.0",
3
+ "version": "18.3.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {