linegauge 0.5.2 → 0.5.4

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 (2) hide show
  1. package/README.md +17 -12
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -8,7 +8,8 @@
8
8
  </p>
9
9
 
10
10
  <p align="center">
11
- Docs: <a href="https://linegauge.interlace.tools">https://linegauge.interlace.tools</a>
11
+ Docs: <a href="https://linegauge.interlace.tools">https://linegauge.interlace.tools</a><br />
12
+ Migrating from: <a href="https://linegauge.interlace.tools/docs/coming-from/string-width">string-width</a> · <a href="https://linegauge.interlace.tools/docs/coming-from/wrap-ansi">wrap-ansi</a> · <a href="https://linegauge.interlace.tools/docs/coming-from/strip-ansi">strip-ansi</a> · <a href="https://linegauge.interlace.tools/docs/coming-from/slice-ansi">slice-ansi</a>
12
13
  </p>
13
14
 
14
15
  **Measuring, wrapping, truncating and slicing styled terminal text — without the edge
@@ -89,10 +90,11 @@ The incumbent is the specification. `width` runs against `string-width`, `wrap`
89
90
 
90
91
  | | |
91
92
  | :-- | :-- |
92
- | `width(text, { countAnsiEscapeCodes })` | terminal columns the text occupies |
93
+ | `width(text, { ambiguousIsNarrow, countAnsiEscapeCodes })` | terminal columns the text occupies |
93
94
  | `wrap(text, columns, options)` | fold to a width, styles preserved across rows |
94
95
  | `truncate(text, columns, { position, ellipsis })` | cut to a budget, ellipsis counted inside it |
95
96
  | `slice(text, start, end)` | the columns `[start, end)`, self-contained |
97
+ | `strip(text)` | the text with its escape sequences removed (`linegauge/strip`) |
96
98
  | `widest(lines)` | the width of the widest line of any iterable |
97
99
  | `lineCount(text, columns)` | rows the text occupies at that width |
98
100
  | `measure(text)` | columns of plain text, no escape scan |
@@ -102,18 +104,21 @@ with whatever a template produced.
102
104
 
103
105
  ## Design notes
104
106
 
105
- **Ambiguous-width characters count narrow**, which is what a terminal does unless told it is
106
- rendering an East Asian locale. `string-width` makes that an option; nothing above this has
107
- ever needed the other answer, so it is not one here.
107
+ **Ambiguous-width characters count narrow by default**, which is what a terminal does unless
108
+ it is rendering with a CJK font. `width(text, { ambiguousIsNarrow: false })` counts them two
109
+ columns wide for that context — string-width's option, under its name and with its default.
110
+ Nothing can detect which a terminal is doing, so it is the caller's decision.
108
111
 
109
112
  **Not a terminal emulator.** Semicolon-delimited SGR, colon-delimited extended colour and
110
113
  OSC 8 hyperlinks are understood. Every other complete CSI or OSC command is carried through
111
114
  as an opaque zero-width unit, and anything that only looks like an introducer stays plain
112
115
  text.
113
116
 
114
- **Still at the Design→Build gate:** an exported `strip`, and the ASCII fast path — a byte
115
- scan when the string has no non-ASCII code unit, so the segmenter is reached only when it
116
- earns its cost.
117
+ **`strip` is exported**, from the root and as the `linegauge/strip` subpath whose default
118
+ export is the strip-ansi drop-in. `width` measures what it leaves.
119
+
120
+ **An ASCII fast path.** A string of printable ASCII is measured by a scan of its code units,
121
+ so the segmenter is reached only when it earns its cost.
117
122
 
118
123
  ## Plugins
119
124
 
@@ -147,9 +152,9 @@ The two things that genuinely vary are already handled without a registry:
147
152
  to pass; nothing here reads `process`. That is a parameter, not a plugin.
148
153
 
149
154
  The family's plugin contract records this refusal next to the other layers' keys (R5a), so
150
- "no key" is one of the contract's answers rather than a hole in it. If a real second answer
151
- ever arrives — an ambiguous-width policy some terminal actually needs — it lands as an option
152
- with a differential test behind it, because the graders have to see it.
155
+ "no key" is one of the contract's answers rather than a hole in it. The one real second
156
+ answer so far — the ambiguous-width policy a CJK terminal needs — landed that way: as
157
+ `ambiguousIsNarrow`, an option with tests behind it, not a registration.
153
158
 
154
159
  ## Benchmarks
155
160
 
@@ -169,7 +174,7 @@ its own suite — which this package passes. The runner reports that as a failur
169
174
  to the incumbent an unexpected pass means a stale annotation; it is counted here as the
170
175
  pass it is, and marked rather than left to look like the ones beside it.
171
176
 
172
- Weight, installed and tree-inclusive: **85,762 bytes** against **194,329** for the incumbents it replaces — a ratio of **0.4413**.
177
+ Weight, installed and tree-inclusive: **86,464 bytes** against **194,329** for the incumbents it replaces — a ratio of **0.4449**.
173
178
  ## Where it sits
174
179
 
175
180
  Plugins register under the `widths` key, against the one schema the whole family shares.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linegauge",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "A printer's line gauge \u2014 the steel rule marked in picas and points. Measuring, wrapping, truncating and slicing styled terminal text without the edge fraying \u2014 grapheme-correct over Intl.Segmenter. Drop-in paths for string-width, wrap-ansi, strip-ansi and slice-ansi. Zero dependencies.",
5
5
  "license": "MIT",
6
6
  "type": "module",