@thi.ng/strings 3.0.0 → 3.1.2

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/CHANGELOG.md CHANGED
@@ -3,6 +3,57 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.1.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@3.1.1...@thi.ng/strings@3.1.2) (2021-10-28)
7
+
8
+ **Note:** Version bump only for package @thi.ng/strings
9
+
10
+
11
+
12
+
13
+
14
+ ## [3.1.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@3.1.0...@thi.ng/strings@3.1.1) (2021-10-28)
15
+
16
+ **Note:** Version bump only for package @thi.ng/strings
17
+
18
+
19
+
20
+
21
+
22
+ # [3.1.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@3.0.3...@thi.ng/strings@3.1.0) (2021-10-25)
23
+
24
+
25
+ ### Features
26
+
27
+ * **strings:** migrate/add entities, regexes, fns ([57c246d](https://github.com/thi-ng/umbrella/commit/57c246df06279a2e70cfb28ce34ff8d9666b0199))
28
+
29
+
30
+
31
+
32
+
33
+ ## [3.0.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@3.0.2...@thi.ng/strings@3.0.3) (2021-10-15)
34
+
35
+ **Note:** Version bump only for package @thi.ng/strings
36
+
37
+
38
+
39
+
40
+
41
+ ## [3.0.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@3.0.1...@thi.ng/strings@3.0.2) (2021-10-15)
42
+
43
+ **Note:** Version bump only for package @thi.ng/strings
44
+
45
+
46
+
47
+
48
+
49
+ ## [3.0.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@3.0.0...@thi.ng/strings@3.0.1) (2021-10-13)
50
+
51
+ **Note:** Version bump only for package @thi.ng/strings
52
+
53
+
54
+
55
+
56
+
6
57
  # [3.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@2.1.7...@thi.ng/strings@3.0.0) (2021-10-12)
7
58
 
8
59
 
package/README.md CHANGED
@@ -133,15 +133,16 @@ ES module import:
133
133
 
134
134
  [Skypack documentation](https://docs.skypack.dev/)
135
135
 
136
- For NodeJS (v14.6+):
136
+ For Node.js REPL:
137
137
 
138
138
  ```text
139
- node --experimental-specifier-resolution=node --experimental-repl-await
139
+ # with flag only for < v16
140
+ node --experimental-repl-await
140
141
 
141
142
  > const strings = await import("@thi.ng/strings");
142
143
  ```
143
144
 
144
- Package sizes (gzipped, pre-treeshake): ESM: 4.12 KB
145
+ Package sizes (gzipped, pre-treeshake): ESM: 4.38 KB
145
146
 
146
147
  ## Dependencies
147
148
 
package/case.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { FnS, Stringer } from "./api";
1
+ import type { FnS, Stringer } from "./api.js";
2
2
  /**
3
3
  * Uppercase string formatter.
4
4
  *
package/center.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  /**
3
3
  * Returns stringer which pads given input with `ch` (default: space) on
4
4
  * both sides and returns fixed width string of given `lineWidth`.
package/center.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { memoizeJ } from "@thi.ng/memoize/memoizej";
2
- import { repeat } from "./repeat";
3
- import { truncate } from "./truncate";
2
+ import { repeat } from "./repeat.js";
3
+ import { truncate } from "./truncate.js";
4
4
  /**
5
5
  * Returns stringer which pads given input with `ch` (default: space) on
6
6
  * both sides and returns fixed width string of given `lineWidth`.
package/entities.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export declare const ENTITIES: Record<string, string>;
2
+ export declare const RE_ENTITIES: RegExp;
3
+ export declare const ENTITIES_REV: Record<string, string>;
4
+ export declare const RE_ENTITIES_REV: RegExp;
5
+ export declare const escapeEntities: (src: string) => string;
6
+ export declare const unescapeEntities: (src: string) => string;
7
+ //# sourceMappingURL=entities.d.ts.map
package/entities.js ADDED
@@ -0,0 +1,24 @@
1
+ export const ENTITIES = {
2
+ "&": "&amp;",
3
+ "<": "&lt;",
4
+ ">": "&gt;",
5
+ '"': "&quot;",
6
+ "'": "&apos;",
7
+ "—": "&mdash;",
8
+ "–": "&ndash;",
9
+ "…": "&hellip;",
10
+ "¢": "&cent;",
11
+ "€": "&euro;",
12
+ "£": "&pound;",
13
+ "§": "&sect;",
14
+ "©": "&copy;",
15
+ "®": "&reg;",
16
+ "™": "&trade;",
17
+ "\xa0": "&nbsp;",
18
+ };
19
+ export const RE_ENTITIES = new RegExp(`[${Object.keys(ENTITIES).join("")}]`, "g");
20
+ export const ENTITIES_REV = Object.entries(ENTITIES).reduce((acc, [k, v]) => ((acc[v] = k), acc), {});
21
+ export const RE_ENTITIES_REV = new RegExp(`(${Object.keys(ENTITIES_REV).join("|")})`, "g");
22
+ const $esc = (re, index) => (src) => src.replace(re, (x) => index[x]);
23
+ export const escapeEntities = $esc(RE_ENTITIES, ENTITIES);
24
+ export const unescapeEntities = $esc(RE_ENTITIES_REV, ENTITIES_REV);
package/escape.js CHANGED
@@ -1,4 +1,4 @@
1
- import { U16, U32 } from "./radix";
1
+ import { U16, U32 } from "./radix.js";
2
2
  export const ESCAPES = {
3
3
  0: "\0",
4
4
  b: "\b",
package/float.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  /**
3
3
  * Returns {@link Stringer} which formats numbers to given precision. If
4
4
  * `special` is true, then exceptional handling for:
package/float.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { memoizeJ } from "@thi.ng/memoize/memoizej";
2
- import { padLeft } from "./pad-left";
2
+ import { padLeft } from "./pad-left.js";
3
3
  /**
4
4
  * Returns {@link Stringer} which formats numbers to given precision. If
5
5
  * `special` is true, then exceptional handling for:
package/groups.js CHANGED
@@ -1,4 +1,4 @@
1
- import { charRange } from "./range";
1
+ import { charRange } from "./range.js";
2
2
  const defGroup = (...xs) => {
3
3
  const acc = {};
4
4
  for (let range of xs) {
package/hollerith.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  /**
3
3
  * Formats given value `x` as Fortran style Hollerith string.
4
4
  *
package/index.d.ts CHANGED
@@ -1,36 +1,37 @@
1
- export * from "./api";
2
- export * from "./ansi";
3
- export * from "./case";
4
- export * from "./center";
5
- export * from "./cursor";
6
- export * from "./escape";
7
- export * from "./float";
8
- export * from "./format";
9
- export * from "./groups";
10
- export * from "./hollerith";
11
- export * from "./initials";
12
- export * from "./int";
13
- export * from "./interpolate";
14
- export * from "./join";
15
- export * from "./pad-left";
16
- export * from "./pad-right";
17
- export * from "./parse";
18
- export * from "./percent";
19
- export * from "./radix";
20
- export * from "./range";
21
- export * from "./repeat";
22
- export * from "./ruler";
23
- export * from "./slugify";
24
- export * from "./splice";
25
- export * from "./split";
26
- export * from "./stringify";
27
- export * from "./tabs";
28
- export * from "./trim";
29
- export * from "./truncate";
30
- export * from "./truncate-left";
31
- export * from "./units";
32
- export * from "./uuid";
33
- export * from "./vector";
34
- export * from "./wrap";
35
- export * from "./word-wrap";
1
+ export * from "./api.js";
2
+ export * from "./ansi.js";
3
+ export * from "./case.js";
4
+ export * from "./center.js";
5
+ export * from "./cursor.js";
6
+ export * from "./entities.js";
7
+ export * from "./escape.js";
8
+ export * from "./float.js";
9
+ export * from "./format.js";
10
+ export * from "./groups.js";
11
+ export * from "./hollerith.js";
12
+ export * from "./initials.js";
13
+ export * from "./int.js";
14
+ export * from "./interpolate.js";
15
+ export * from "./join.js";
16
+ export * from "./pad-left.js";
17
+ export * from "./pad-right.js";
18
+ export * from "./parse.js";
19
+ export * from "./percent.js";
20
+ export * from "./radix.js";
21
+ export * from "./range.js";
22
+ export * from "./repeat.js";
23
+ export * from "./ruler.js";
24
+ export * from "./slugify.js";
25
+ export * from "./splice.js";
26
+ export * from "./split.js";
27
+ export * from "./stringify.js";
28
+ export * from "./tabs.js";
29
+ export * from "./trim.js";
30
+ export * from "./truncate.js";
31
+ export * from "./truncate-left.js";
32
+ export * from "./units.js";
33
+ export * from "./uuid.js";
34
+ export * from "./vector.js";
35
+ export * from "./wrap.js";
36
+ export * from "./word-wrap.js";
36
37
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1,35 +1,36 @@
1
- export * from "./api";
2
- export * from "./ansi";
3
- export * from "./case";
4
- export * from "./center";
5
- export * from "./cursor";
6
- export * from "./escape";
7
- export * from "./float";
8
- export * from "./format";
9
- export * from "./groups";
10
- export * from "./hollerith";
11
- export * from "./initials";
12
- export * from "./int";
13
- export * from "./interpolate";
14
- export * from "./join";
15
- export * from "./pad-left";
16
- export * from "./pad-right";
17
- export * from "./parse";
18
- export * from "./percent";
19
- export * from "./radix";
20
- export * from "./range";
21
- export * from "./repeat";
22
- export * from "./ruler";
23
- export * from "./slugify";
24
- export * from "./splice";
25
- export * from "./split";
26
- export * from "./stringify";
27
- export * from "./tabs";
28
- export * from "./trim";
29
- export * from "./truncate";
30
- export * from "./truncate-left";
31
- export * from "./units";
32
- export * from "./uuid";
33
- export * from "./vector";
34
- export * from "./wrap";
35
- export * from "./word-wrap";
1
+ export * from "./api.js";
2
+ export * from "./ansi.js";
3
+ export * from "./case.js";
4
+ export * from "./center.js";
5
+ export * from "./cursor.js";
6
+ export * from "./entities.js";
7
+ export * from "./escape.js";
8
+ export * from "./float.js";
9
+ export * from "./format.js";
10
+ export * from "./groups.js";
11
+ export * from "./hollerith.js";
12
+ export * from "./initials.js";
13
+ export * from "./int.js";
14
+ export * from "./interpolate.js";
15
+ export * from "./join.js";
16
+ export * from "./pad-left.js";
17
+ export * from "./pad-right.js";
18
+ export * from "./parse.js";
19
+ export * from "./percent.js";
20
+ export * from "./radix.js";
21
+ export * from "./range.js";
22
+ export * from "./repeat.js";
23
+ export * from "./ruler.js";
24
+ export * from "./slugify.js";
25
+ export * from "./splice.js";
26
+ export * from "./split.js";
27
+ export * from "./stringify.js";
28
+ export * from "./tabs.js";
29
+ export * from "./trim.js";
30
+ export * from "./truncate.js";
31
+ export * from "./truncate-left.js";
32
+ export * from "./units.js";
33
+ export * from "./uuid.js";
34
+ export * from "./vector.js";
35
+ export * from "./wrap.js";
36
+ export * from "./word-wrap.js";
package/int.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  export declare const int: Stringer<number>;
3
3
  export declare const intLocale: (locale?: string) => Stringer<number>;
4
4
  //# sourceMappingURL=int.d.ts.map
package/join.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  /**
3
3
  * Higher-order version of `Array.join()`. Takes separator string `sep`
4
4
  * and returns function which accepts an array and joins all elements w/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/strings",
3
- "version": "3.0.0",
3
+ "version": "3.1.2",
4
4
  "description": "Various string formatting & utility functions",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,13 +34,13 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.0.0",
38
- "@thi.ng/errors": "^2.0.0",
39
- "@thi.ng/hex": "^2.0.0",
40
- "@thi.ng/memoize": "^3.0.0"
37
+ "@thi.ng/api": "^8.0.6",
38
+ "@thi.ng/errors": "^2.0.6",
39
+ "@thi.ng/hex": "^2.0.6",
40
+ "@thi.ng/memoize": "^3.0.6"
41
41
  },
42
42
  "devDependencies": {
43
- "@thi.ng/testament": "^0.1.0"
43
+ "@thi.ng/testament": "^0.1.6"
44
44
  },
45
45
  "keywords": [
46
46
  "ansi",
@@ -69,6 +69,9 @@
69
69
  "publishConfig": {
70
70
  "access": "public"
71
71
  },
72
+ "engines": {
73
+ "node": ">=12.7"
74
+ },
72
75
  "files": [
73
76
  "*.js",
74
77
  "*.d.ts"
@@ -92,6 +95,9 @@
92
95
  "./cursor": {
93
96
  "import": "./cursor.js"
94
97
  },
98
+ "./entities": {
99
+ "import": "./entities.js"
100
+ },
95
101
  "./escape": {
96
102
  "import": "./escape.js"
97
103
  },
@@ -186,5 +192,5 @@
186
192
  "thi.ng": {
187
193
  "year": 2015
188
194
  },
189
- "gitHead": "9ac1344b38b565eb894306fbf72233b6c0b2d115"
195
+ "gitHead": "c17a556ad25f6882dfa8f806a1d9e8ed7ac7cd71"
190
196
  }
package/pad-left.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { memoizeJ } from "@thi.ng/memoize/memoizej";
2
- import { repeat } from "./repeat";
2
+ import { repeat } from "./repeat.js";
3
3
  /**
4
4
  * @param n - target length
5
5
  * @param ch - pad character(s)
package/pad-right.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { memoizeJ } from "@thi.ng/memoize/memoizej";
2
- import { repeat } from "./repeat";
2
+ import { repeat } from "./repeat.js";
3
3
  /**
4
4
  * @param n - target length
5
5
  * @param ch - pad character(s)
package/percent.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  /**
3
3
  * Returns {@link Stringer} which formats given fractions as percentage (e.g.
4
4
  * `0.1234 => 12.34%`).
package/radix.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  /**
3
3
  * Returns a {@link Stringer} which formats given numbers to `radix`, `len` and
4
4
  * with optional prefix (not included in `len`).
package/radix.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { U16 as $16, U24 as $24, U32 as $32, U64HL, U8 as $8, } from "@thi.ng/hex";
2
2
  import { memoizeJ } from "@thi.ng/memoize/memoizej";
3
- import { repeat } from "./repeat";
3
+ import { repeat } from "./repeat.js";
4
4
  /**
5
5
  * Returns a {@link Stringer} which formats given numbers to `radix`, `len` and
6
6
  * with optional prefix (not included in `len`).
package/ruler.js CHANGED
@@ -1,4 +1,4 @@
1
- import { repeat } from "./repeat";
1
+ import { repeat } from "./repeat.js";
2
2
  /**
3
3
  * Returns a ruler-like string of given `width`, using `a` character for major
4
4
  * ticks and `b` for minor ticks.
package/slugify.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  /**
3
3
  * Based on:
4
4
  * {@link https://medium.com/@matthagemann/the-ultimate-way-to-slugify-a-url-string-in-javascript-b8e4a0d849e1}
package/stringify.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  /**
3
3
  * Higher order version of `JSON.stringify()` with the option to treat strings
4
4
  * and numbers differently. If `all` is `false` (default), strings and numbers
package/tabs.js CHANGED
@@ -1,4 +1,4 @@
1
- import { repeat } from "./repeat";
1
+ import { repeat } from "./repeat.js";
2
2
  const nextTab = (x, tabSize) => Math.floor((x + tabSize) / tabSize) * tabSize;
3
3
  /**
4
4
  * Multi-line version of {@link tabsToSpacesLine}.
package/trim.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  /**
3
3
  * Higher order trim function (both sides) with support for user defined
4
4
  * trimmable characters (default: whitespace only).
@@ -1,3 +1,3 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  export declare const truncateLeft: (n: number, prefix?: string) => Stringer<string>;
3
3
  //# sourceMappingURL=truncate-left.d.ts.map
package/truncate.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  export declare const truncate: (n: number, suffix?: string) => Stringer<string>;
3
3
  /**
4
4
  * Alias for {@link truncate}
package/units.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  declare type UnitDefs = [number, string, number?][];
3
3
  export declare const units: (exp: UnitDefs, base: string, prec?: number) => Stringer<number>;
4
4
  export declare const bits: Stringer<number>;
package/vector.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  /**
3
3
  * Higher order formatter for n-D vectors, with each element formatted using
4
4
  * `prec` and using optional delimiter and pre/postfixes.
package/vector.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { memoizeJ } from "@thi.ng/memoize/memoizej";
2
- import { float } from "./float";
2
+ import { float } from "./float.js";
3
3
  /**
4
4
  * Higher order formatter for n-D vectors, with each element formatted using
5
5
  * `prec` and using optional delimiter and pre/postfixes.
package/word-wrap.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { IWordSplit, WordWrapOpts } from "./api";
1
+ import type { IWordSplit, WordWrapOpts } from "./api.js";
2
2
  /**
3
3
  * Internal representation of a single line (for word wrapping purposes). A thin
4
4
  * wrapper of individual word and the _logical_ line length (rather than the
package/word-wrap.js CHANGED
@@ -1,5 +1,5 @@
1
- import { lengthAnsi } from "./ansi";
2
- import { split } from "./split";
1
+ import { lengthAnsi } from "./ansi.js";
2
+ import { split } from "./split.js";
3
3
  /**
4
4
  * Internal representation of a single line (for word wrapping purposes). A thin
5
5
  * wrapper of individual word and the _logical_ line length (rather than the
@@ -8,9 +8,9 @@ import { split } from "./split";
8
8
  * @internal
9
9
  */
10
10
  class Line {
11
- n = 0;
12
- w = [];
13
11
  constructor(word, n) {
12
+ this.n = 0;
13
+ this.w = [];
14
14
  word != null && this.add(word, n);
15
15
  }
16
16
  add(word, n = word.length) {
package/wrap.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Stringer } from "./api";
1
+ import type { Stringer } from "./api.js";
2
2
  /**
3
3
  * Returns a {@link Stringer} which wrap inputs with given `pad` string on
4
4
  * both sides.