@bitbeater/ecma-utils 2.7.0 → 2.8.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ecma-utils
2
2
 
3
- [See Documentation](https://bitbeater.github.io/)
3
+ [See Documentation](https://bitbeater.github.io/ecma-utils/)
4
4
 
5
5
  Simple, lightweight, dependenciesless, TypeScript generic helper library.
6
6
 
@@ -2,7 +2,7 @@
2
2
  * A circular array implementation that allows for wrapping around the ends.
3
3
  * @example
4
4
  * ```ts
5
- * import { collection } from 'iggs-utils';
5
+ * import { collection } from '@bitbeater/ecma-utils';
6
6
  *
7
7
  * const circularArray = new collection.CircularArray<string>(monday, tuesday, wednesday, thursday, friday, saturday, sunday);
8
8
  *
@@ -5,7 +5,7 @@ exports.CircularArray = void 0;
5
5
  * A circular array implementation that allows for wrapping around the ends.
6
6
  * @example
7
7
  * ```ts
8
- * import { collection } from 'iggs-utils';
8
+ * import { collection } from '@bitbeater/ecma-utils';
9
9
  *
10
10
  * const circularArray = new collection.CircularArray<string>(monday, tuesday, wednesday, thursday, friday, saturday, sunday);
11
11
  *
package/dist/strings.d.ts CHANGED
@@ -12,5 +12,23 @@ export declare function isJson(str: string): boolean;
12
12
  * @returns
13
13
  */
14
14
  export declare function templateToString(template: TemplateStringsArray, ...expressions: TemplateExpression[]): string;
15
+ /**
16
+ * Separates text into an array of [whitespace, word] tuples, preserving the whitespace.
17
+ * @example
18
+ * ```ts
19
+ * spacedWords('\t Hello \n world ')`
20
+ * // Returns:
21
+ * // [
22
+ * // ['\t ', 'Hello'],
23
+ * // [' \n ', 'world'],
24
+ * // [' ', '']
25
+ * // ]
26
+ * ```
27
+ * @param text
28
+ * @returns [[whitespace, word], ...]
29
+ */
30
+ export declare function spacedWords(text: string): [string, string][];
31
+ export declare const isWhitespace: (char: string) => boolean;
32
+ export declare function isUpperCase(str: string): boolean;
15
33
  export type TemplateExpression = string | number | Array<string | number>;
16
34
  //# sourceMappingURL=strings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../src/strings.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO3C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,GAAG,WAAW,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAS7G;AAED,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../src/strings.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO3C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,GAAG,WAAW,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAS7G;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAyB5D;AAED,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,OAE3C,CAAC;AAEF,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC"}
package/dist/strings.js CHANGED
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWhitespace = void 0;
3
4
  exports.isJson = isJson;
4
5
  exports.templateToString = templateToString;
6
+ exports.spacedWords = spacedWords;
7
+ exports.isUpperCase = isUpperCase;
5
8
  function isJson(str) {
6
9
  try {
7
10
  JSON.parse(str);
@@ -31,4 +34,47 @@ function templateToString(template, ...expressions) {
31
34
  }
32
35
  return merged.join('');
33
36
  }
37
+ /**
38
+ * Separates text into an array of [whitespace, word] tuples, preserving the whitespace.
39
+ * @example
40
+ * ```ts
41
+ * spacedWords('\t Hello \n world ')`
42
+ * // Returns:
43
+ * // [
44
+ * // ['\t ', 'Hello'],
45
+ * // [' \n ', 'world'],
46
+ * // [' ', '']
47
+ * // ]
48
+ * ```
49
+ * @param text
50
+ * @returns [[whitespace, word], ...]
51
+ */
52
+ function spacedWords(text) {
53
+ const _spacedWords = [];
54
+ let isPreviousCharWhitespace = null;
55
+ let [whitespaces, currentWord] = ['', ''];
56
+ for (const char of text) {
57
+ if ((0, exports.isWhitespace)(char)) {
58
+ if (isPreviousCharWhitespace === false) {
59
+ _spacedWords.push([whitespaces, currentWord]);
60
+ currentWord = '';
61
+ whitespaces = '';
62
+ }
63
+ const whiteSpace = char;
64
+ whitespaces += whiteSpace;
65
+ isPreviousCharWhitespace = true;
66
+ continue;
67
+ }
68
+ currentWord += char;
69
+ isPreviousCharWhitespace = false;
70
+ }
71
+ return _spacedWords.concat([[whitespaces, currentWord]]);
72
+ }
73
+ const isWhitespace = (char) => {
74
+ return /\s/.test(char);
75
+ };
76
+ exports.isWhitespace = isWhitespace;
77
+ function isUpperCase(str) {
78
+ return str === str.toUpperCase();
79
+ }
34
80
  //# sourceMappingURL=strings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"strings.js","sourceRoot":"","sources":["../src/strings.ts"],"names":[],"mappings":";;AAAA,wBAOC;AAcD,4CASC;AA9BD,SAAgB,MAAM,CAAC,GAAW;IACjC,IAAI,CAAC;QACJ,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;;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AY;IACvC,MAAM,YAAY,GAAuB,EAAE,CAAC;IAE5C,IAAI,wBAAwB,GAAG,IAAI,CAAC;IACpC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAE1C,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACzB,IAAI,IAAA,oBAAY,EAAC,IAAI,CAAC,EAAE,CAAC;YACxB,IAAI,wBAAwB,KAAK,KAAK,EAAE,CAAC;gBACxC,YAAY,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;gBAC9C,WAAW,GAAG,EAAE,CAAC;gBACjB,WAAW,GAAG,EAAE,CAAC;YAClB,CAAC;YAED,MAAM,UAAU,GAAG,IAAI,CAAC;YACxB,WAAW,IAAI,UAAU,CAAC;YAC1B,wBAAwB,GAAG,IAAI,CAAC;YAChC,SAAS;QACV,CAAC;QAED,WAAW,IAAI,IAAI,CAAC;QACpB,wBAAwB,GAAG,KAAK,CAAC;IAClC,CAAC;IAED,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC;AAEM,MAAM,YAAY,GAAG,CAAC,IAAY,EAAW,EAAE;IACrD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC,CAAC;AAFW,QAAA,YAAY,gBAEvB;AAEF,SAAgB,WAAW,CAAC,GAAW;IACtC,OAAO,GAAG,KAAK,GAAG,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC"}
@@ -3,7 +3,7 @@ import { Duration } from './time';
3
3
  * A simple timer that can be started, paused, and resumed.
4
4
  * @example
5
5
  * ```js
6
- * import { Timer } from 'iggs-utils/time/timer';
6
+ * import { Timer } from '@bitbeater/ecma-utils/time/timer';
7
7
  *
8
8
  * const timer = new Timer(5000, (totalDuration) => {
9
9
  * console.log(`Timer completed in ${totalDuration} ms`);
@@ -18,7 +18,7 @@ const time_1 = require("./time");
18
18
  * A simple timer that can be started, paused, and resumed.
19
19
  * @example
20
20
  * ```js
21
- * import { Timer } from 'iggs-utils/time/timer';
21
+ * import { Timer } from '@bitbeater/ecma-utils/time/timer';
22
22
  *
23
23
  * const timer = new Timer(5000, (totalDuration) => {
24
24
  * console.log(`Timer completed in ${totalDuration} ms`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitbeater/ecma-utils",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "sideEffects": false,