punctilio 1.0.4 → 1.1.1
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 +25 -10
- package/dist/constants.d.ts +13 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +15 -1
- package/dist/constants.js.map +1 -1
- package/dist/dashes.d.ts +7 -51
- package/dist/dashes.d.ts.map +1 -1
- package/dist/dashes.js +66 -104
- package/dist/dashes.js.map +1 -1
- package/dist/index.d.ts +13 -38
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -3
- package/dist/index.js.map +1 -1
- package/dist/quotes.d.ts +4 -31
- package/dist/quotes.d.ts.map +1 -1
- package/dist/quotes.js +4 -13
- package/dist/quotes.js.map +1 -1
- package/dist/symbols.d.ts +16 -158
- package/dist/symbols.d.ts.map +1 -1
- package/dist/symbols.js +55 -189
- package/dist/symbols.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +3 -1
- package/dist/utils.js.map +1 -1
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export { niceQuotes } from "./quotes.js";
|
|
11
11
|
export { hyphenReplace, enDashNumberRange, enDashDateRange, minusReplace, months, numberRangeDisallowedPrefixes, } from "./dashes.js";
|
|
12
|
-
export { ellipsis, multiplication, mathSymbols, legalSymbols, arrows, degrees, fractions, primeMarks, collapseSpaces,
|
|
12
|
+
export { ellipsis, multiplication, mathSymbols, legalSymbols, arrows, degrees, fractions, primeMarks, collapseSpaces, superscriptOrdinal, punctuationLigatures, symbolTransform, } from "./symbols.js";
|
|
13
13
|
import { niceQuotes } from "./quotes.js";
|
|
14
14
|
import { hyphenReplace } from "./dashes.js";
|
|
15
|
-
import { symbolTransform, fractions as fractionsTransform, degrees as degreesTransform,
|
|
15
|
+
import { symbolTransform, fractions as fractionsTransform, degrees as degreesTransform, superscriptOrdinal as superscriptTransform, primeMarks, collapseSpaces as collapseSpacesTransform, punctuationLigatures as ligaturesTransform } from "./symbols.js";
|
|
16
16
|
import { assertSeparatorCountPreserved } from "./utils.js";
|
|
17
17
|
import { DEFAULT_SEPARATOR } from "./constants.js";
|
|
18
18
|
export { assertSeparatorCountPreserved, countSeparators } from "./utils.js";
|
|
@@ -50,10 +50,21 @@ export { DEFAULT_SEPARATOR } from "./constants.js";
|
|
|
50
50
|
* // → 'Add ½ cup'
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
|
+
const defaultOpts = {
|
|
54
|
+
symbols: true,
|
|
55
|
+
fractions: false,
|
|
56
|
+
degrees: false,
|
|
57
|
+
superscript: false,
|
|
58
|
+
ligatures: false,
|
|
59
|
+
collapseSpaces: true,
|
|
60
|
+
checkIdempotency: true,
|
|
61
|
+
punctuationStyle: "american",
|
|
62
|
+
dashStyle: "american",
|
|
63
|
+
};
|
|
53
64
|
export function transform(text, options = {}) {
|
|
54
65
|
const separator = options.separator ?? DEFAULT_SEPARATOR;
|
|
55
66
|
const original = text;
|
|
56
|
-
const { symbols
|
|
67
|
+
const { symbols, fractions, degrees, superscript, ligatures, collapseSpaces, checkIdempotency, ...separatorOpts } = { ...defaultOpts, ...options };
|
|
57
68
|
text = hyphenReplace(text, separatorOpts);
|
|
58
69
|
text = primeMarks(text, separatorOpts);
|
|
59
70
|
text = niceQuotes(text, separatorOpts);
|
|
@@ -76,6 +87,17 @@ export function transform(text, options = {}) {
|
|
|
76
87
|
text = collapseSpacesTransform(text);
|
|
77
88
|
}
|
|
78
89
|
assertSeparatorCountPreserved(original, text, separator, "transform");
|
|
90
|
+
if (checkIdempotency) {
|
|
91
|
+
const secondPass = transform(text, { ...options, checkIdempotency: false });
|
|
92
|
+
/* istanbul ignore if -- defensive check that should never trigger */
|
|
93
|
+
if (text !== secondPass) {
|
|
94
|
+
throw new Error(`Transform is not idempotent.\n` +
|
|
95
|
+
`First pass: ${JSON.stringify(text)}\n` +
|
|
96
|
+
`Second pass: ${JSON.stringify(secondPass)}\n` +
|
|
97
|
+
`This is a bug in punctilio. Please file an issue at https://github.com/alexander-turner/punctilio/issues\n` +
|
|
98
|
+
`Include the input text that caused this error.`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
79
101
|
return text;
|
|
80
102
|
}
|
|
81
103
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAA4C,MAAM,aAAa,CAAA;AAElF,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,MAAM,EACN,6BAA6B,GAG9B,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,QAAQ,EACR,cAAc,EACd,WAAW,EACX,YAAY,EACZ,MAAM,EACN,OAAO,EACP,SAAS,EACT,UAAU,EACV,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAA4C,MAAM,aAAa,CAAA;AAElF,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,MAAM,EACN,6BAA6B,GAG9B,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,QAAQ,EACR,cAAc,EACd,WAAW,EACX,YAAY,EACZ,MAAM,EACN,OAAO,EACP,SAAS,EACT,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,GAEhB,MAAM,cAAc,CAAA;AA0FrB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,SAAS,IAAI,kBAAkB,EAAE,OAAO,IAAI,gBAAgB,EAAE,kBA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CAAC,CAAA;IAC7C,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,IAAI,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAA;IACjC,CAAC;IAED,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC;IAED,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,GAAG,oBAAoB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;IAClD,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,IAAI,GAAG,kBAAkB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;IAChD,CAAC;IAED,IAAI,cAAc,EAAE,CAAC;QACnB,IAAI,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAA;IACtC,CAAC;IAED,6BAA6B,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,CAAC,CAAA;IAErE,IAAI,gBAAgB,EAAE,CAAC;QACrB,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,CAAA;QAC3E,qEAAqE;QACrE,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CACb,gCAAgC;gBAChC,gBAAgB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI;gBACxC,gBAAgB,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI;gBAC9C,4GAA4G;gBAC5G,gDAAgD,CACjD,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/dist/quotes.d.ts
CHANGED
|
@@ -1,40 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Smart quote transformation
|
|
3
|
-
*
|
|
4
|
-
* Converts straight quotes to typographically correct curly quotes,
|
|
5
|
-
* handling contractions, possessives, and nested quotes.
|
|
2
|
+
* Smart quote transformation: straight quotes → curly quotes.
|
|
6
3
|
*/
|
|
7
4
|
export type PunctuationStyle = "american" | "british" | "none";
|
|
8
5
|
export interface QuoteOptions {
|
|
9
|
-
/**
|
|
10
|
-
* A boundary marker character used when transforming text that spans
|
|
11
|
-
* multiple HTML elements. This character is treated as "transparent"
|
|
12
|
-
* in the regex patterns - it won't affect quote matching but allows
|
|
13
|
-
* the algorithm to work across element boundaries.
|
|
14
|
-
*
|
|
15
|
-
* Should be a character that doesn't appear in your text.
|
|
16
|
-
* Default: "\uE000" (Unicode Private Use Area)
|
|
17
|
-
*/
|
|
6
|
+
/** Boundary marker for HTML element boundaries. Default: "\uE000" */
|
|
18
7
|
separator?: string;
|
|
19
|
-
/**
|
|
20
|
-
* How to handle punctuation placement around quotation marks.
|
|
21
|
-
*
|
|
22
|
-
* - `"american"` (default): Periods and commas go inside quotes
|
|
23
|
-
* Example: "Hello." and "Hello,"
|
|
24
|
-
* - `"british"`: Periods and commas go outside quotes
|
|
25
|
-
* Example: "Hello". and "Hello",
|
|
26
|
-
* - `"none"`: Don't modify punctuation placement
|
|
27
|
-
*
|
|
28
|
-
* Default: "american"
|
|
29
|
-
*/
|
|
8
|
+
/** "american" (inside), "british" (outside), "none". Default: "american" */
|
|
30
9
|
punctuationStyle?: PunctuationStyle;
|
|
31
10
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Converts standard quotes to typographic smart quotes.
|
|
34
|
-
*
|
|
35
|
-
* @param text - The text to transform
|
|
36
|
-
* @param options - Configuration options
|
|
37
|
-
* @returns The text with smart quotes
|
|
38
|
-
*/
|
|
11
|
+
/** Convert straight quotes to smart quotes. */
|
|
39
12
|
export declare function niceQuotes(text: string, options?: QuoteOptions): string;
|
|
40
13
|
//# sourceMappingURL=quotes.d.ts.map
|
package/dist/quotes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quotes.d.ts","sourceRoot":"","sources":["../src/quotes.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"quotes.d.ts","sourceRoot":"","sources":["../src/quotes.ts"],"names":[],"mappings":"AAAA;;GAEG;AAaH,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,CAAA;AAE9D,MAAM,WAAW,YAAY;IAC3B,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,4EAA4E;IAC5E,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;CACpC;AA+ED,+CAA+C;AAC/C,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,MAAM,CAS3E"}
|
package/dist/quotes.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Smart quote transformation
|
|
3
|
-
*
|
|
4
|
-
* Converts straight quotes to typographically correct curly quotes,
|
|
5
|
-
* handling contractions, possessives, and nested quotes.
|
|
2
|
+
* Smart quote transformation: straight quotes → curly quotes.
|
|
6
3
|
*/
|
|
7
|
-
import { UNICODE_SYMBOLS, DEFAULT_SEPARATOR } from "./constants.js";
|
|
4
|
+
import { UNICODE_SYMBOLS, DEFAULT_SEPARATOR, LATIN_LETTERS } from "./constants.js";
|
|
8
5
|
const { EM_DASH, LEFT_DOUBLE_QUOTE, RIGHT_DOUBLE_QUOTE, LEFT_SINGLE_QUOTE, RIGHT_SINGLE_QUOTE, ELLIPSIS, } = UNICODE_SYMBOLS;
|
|
9
6
|
/** Convert straight single quotes to curly quotes and apostrophes */
|
|
10
7
|
function convertSingleQuotes(text, sep) {
|
|
@@ -12,7 +9,7 @@ function convertSingleQuotes(text, sep) {
|
|
|
12
9
|
const afterEndingSingle = `(?=${sep}?(?:s${sep}?)?(?:[${afterEndingSinglePatterns}]|$))`;
|
|
13
10
|
const endingSingle = `(?<=[^\\s${LEFT_DOUBLE_QUOTE}'])[']${afterEndingSingle}`;
|
|
14
11
|
text = text.replace(new RegExp(endingSingle, "gm"), RIGHT_SINGLE_QUOTE);
|
|
15
|
-
const contraction = `(?<=[
|
|
12
|
+
const contraction = `(?<=[${LATIN_LETTERS}])['${RIGHT_SINGLE_QUOTE}](?=${sep}?[${LATIN_LETTERS}])`;
|
|
16
13
|
text = text.replace(new RegExp(contraction, "gm"), RIGHT_SINGLE_QUOTE);
|
|
17
14
|
const apostropheWhitelist = `(?=n${RIGHT_SINGLE_QUOTE} )`;
|
|
18
15
|
const endQuoteNotContraction = `(?!${contraction})${RIGHT_SINGLE_QUOTE}${afterEndingSingle}`;
|
|
@@ -53,13 +50,7 @@ function applyPunctuationStyle(text, sep, style) {
|
|
|
53
50
|
}
|
|
54
51
|
return text;
|
|
55
52
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Converts standard quotes to typographic smart quotes.
|
|
58
|
-
*
|
|
59
|
-
* @param text - The text to transform
|
|
60
|
-
* @param options - Configuration options
|
|
61
|
-
* @returns The text with smart quotes
|
|
62
|
-
*/
|
|
53
|
+
/** Convert straight quotes to smart quotes. */
|
|
63
54
|
export function niceQuotes(text, options = {}) {
|
|
64
55
|
const sep = options.separator ?? DEFAULT_SEPARATOR;
|
|
65
56
|
const punctuationStyle = options.punctuationStyle ?? "american";
|
package/dist/quotes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quotes.js","sourceRoot":"","sources":["../src/quotes.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"quotes.js","sourceRoot":"","sources":["../src/quotes.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAElF,MAAM,EACJ,OAAO,EACP,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,QAAQ,GACT,GAAG,eAAe,CAAA;AAWnB,qEAAqE;AACrE,SAAS,mBAAmB,CAAC,IAAY,EAAE,GAAW;IACpD,MAAM,yBAA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-
*
|
|
4
|
-
* Handles ellipses, multiplication signs, mathematical symbols, and
|
|
5
|
-
* common character sequences that should use proper Unicode glyphs.
|
|
6
|
-
*
|
|
7
|
-
* @module symbols
|
|
2
|
+
* Symbol transformations: ellipses, multiplication, math symbols, arrows.
|
|
8
3
|
*/
|
|
9
4
|
export interface SymbolOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Boundary marker character for text spanning HTML elements.
|
|
12
|
-
* Default: "\uE000" (Unicode Private Use Area)
|
|
13
|
-
*/
|
|
5
|
+
/** Boundary marker for HTML element boundaries. Default: "\uE000" */
|
|
14
6
|
separator?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Whether to include arrow transformations (-> to →, etc.).
|
|
17
|
-
* Default: true
|
|
18
|
-
*/
|
|
7
|
+
/** Include arrow transforms (-> → →). Default: true */
|
|
19
8
|
includeArrows?: boolean;
|
|
20
9
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Converts three periods to a proper ellipsis character.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* ellipsis("Wait for it...")
|
|
27
|
-
* // → "Wait for it…"
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
10
|
+
/** Convert "..." to "…". */
|
|
30
11
|
export declare function ellipsis(text: string, options?: SymbolOptions): string;
|
|
31
|
-
/**
|
|
32
|
-
* Converts ASCII multiplication patterns to proper multiplication sign (×).
|
|
33
|
-
*
|
|
34
|
-
* Handles:
|
|
35
|
-
* - Dimensions: "5x5" → "5×5"
|
|
36
|
-
* - Trailing multiplier: "5x" → "5×" (when followed by word boundary)
|
|
37
|
-
* - Asterisk multiplication: "5*3" → "5×3" (when between numbers)
|
|
38
|
-
*/
|
|
12
|
+
/** Convert "5x5" to "5×5". Skips hex (0x5F). */
|
|
39
13
|
export declare function multiplication(text: string, options?: SymbolOptions): string;
|
|
40
|
-
/**
|
|
41
|
-
* Converts ASCII mathematical symbols to proper Unicode equivalents.
|
|
42
|
-
*/
|
|
14
|
+
/** Convert !=, <=, >=, +/-, ~= to Unicode equivalents. */
|
|
43
15
|
export declare function mathSymbols(text: string): string;
|
|
44
|
-
/**
|
|
45
|
-
* Converts ASCII representations of copyright, registered, and trademark
|
|
46
|
-
* symbols to proper Unicode characters.
|
|
47
|
-
*/
|
|
16
|
+
/** Convert (c), (r), (tm) to ©, ®, ™. */
|
|
48
17
|
export declare function legalSymbols(text: string): string;
|
|
49
|
-
/**
|
|
50
|
-
* Converts arrow character sequences to Unicode arrows.
|
|
51
|
-
*
|
|
52
|
-
* Handles:
|
|
53
|
-
* - "->" or "-->" → "→"
|
|
54
|
-
* - "<-" or "<--" → "←"
|
|
55
|
-
* - "<->" or "<-->" → "↔"
|
|
56
|
-
*
|
|
57
|
-
* Note: Only converts when surrounded by spaces or at word boundaries
|
|
58
|
-
* to avoid false matches in code or URLs.
|
|
59
|
-
*/
|
|
18
|
+
/** Convert -> and <-> to arrows. */
|
|
60
19
|
export declare function arrows(text: string, options?: SymbolOptions): string;
|
|
61
|
-
/**
|
|
62
|
-
* Adds degree symbol in temperature contexts.
|
|
63
|
-
*
|
|
64
|
-
* Handles:
|
|
65
|
-
* - "20 C" or "20C" → "20 °C" (Celsius)
|
|
66
|
-
* - "68 F" or "68F" → "68 °F" (Fahrenheit)
|
|
67
|
-
*
|
|
68
|
-
* Only matches when followed by C or F (case insensitive) to avoid
|
|
69
|
-
* false positives.
|
|
70
|
-
*/
|
|
20
|
+
/** Convert "20 C" or "20 F" to "20 °C" or "20 °F". Only matches uppercase C/F. */
|
|
71
21
|
export declare function degrees(text: string, options?: SymbolOptions): string;
|
|
72
|
-
/**
|
|
73
|
-
* Converts straight quotes after numbers to prime marks.
|
|
74
|
-
*
|
|
75
|
-
* Prime marks are used for:
|
|
76
|
-
* - Feet and inches: 5'10" → 5′10″
|
|
77
|
-
* - Arcminutes and arcseconds: 45° 30' 15" → 45° 30′ 15″
|
|
78
|
-
*
|
|
79
|
-
* This should be called BEFORE smart quote transformations to prevent
|
|
80
|
-
* quotes in measurements from being curled.
|
|
81
|
-
*/
|
|
22
|
+
/** Convert 5'10" to 5′10″ (prime marks). Call before smart quotes. */
|
|
82
23
|
export declare function primeMarks(text: string, options?: SymbolOptions): string;
|
|
83
|
-
/**
|
|
84
|
-
* Converts common fractions to Unicode fraction characters.
|
|
85
|
-
*
|
|
86
|
-
* Handles: 1/4, 1/2, 3/4, 1/3, 2/3, 1/5, 2/5, 3/5, 4/5,
|
|
87
|
-
* 1/6, 5/6, 1/8, 3/8, 5/8, 7/8
|
|
88
|
-
*
|
|
89
|
-
* Only converts when the fraction is surrounded by word boundaries
|
|
90
|
-
* to avoid breaking URLs, file paths, or dates.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```ts
|
|
94
|
-
* fractions("Add 1/2 cup of flour")
|
|
95
|
-
* // → "Add ½ cup of flour"
|
|
96
|
-
*
|
|
97
|
-
* fractions("About 3/4 complete")
|
|
98
|
-
* // → "About ¾ complete"
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
24
|
+
/** Convert 1/2, 1/4, etc. to ½, ¼, etc. */
|
|
101
25
|
export declare function fractions(text: string, options?: SymbolOptions): string;
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
* Handles ordinal numbers like:
|
|
106
|
-
* - "1st" → "1ˢᵗ"
|
|
107
|
-
* - "2nd" → "2ⁿᵈ"
|
|
108
|
-
* - "3rd" → "3ʳᵈ"
|
|
109
|
-
* - "4th" → "4ᵗʰ"
|
|
110
|
-
*
|
|
111
|
-
* Works with any number ending in appropriate suffixes (21st, 42nd, 103rd, etc.)
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```ts
|
|
115
|
-
* superscript("The 1st place winner")
|
|
116
|
-
* // → "The 1ˢᵗ place winner"
|
|
117
|
-
*
|
|
118
|
-
* superscript("Born on the 30th of June")
|
|
119
|
-
* // → "Born on the 30ᵗʰ of June"
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
export declare function superscript(text: string, options?: SymbolOptions): string;
|
|
123
|
-
/**
|
|
124
|
-
* Collapses multiple consecutive spaces (including non-breaking spaces) into a single space.
|
|
125
|
-
*
|
|
126
|
-
* When multiple spaces or non-breaking spaces appear in sequence, this function
|
|
127
|
-
* keeps only the first space character, preserving its type.
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* ```ts
|
|
131
|
-
* collapseSpaces("hello world")
|
|
132
|
-
* // → "hello world"
|
|
133
|
-
*
|
|
134
|
-
* collapseSpaces("foo\u00A0\u00A0bar") // two nbsp
|
|
135
|
-
* // → "foo\u00A0bar" // single nbsp
|
|
136
|
-
*
|
|
137
|
-
* collapseSpaces("a \u00A0b") // space followed by nbsp
|
|
138
|
-
* // → "a b" // keeps the first (regular space)
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
26
|
+
/** Convert 1st, 2nd, 3rd, 4th to superscript ordinals. */
|
|
27
|
+
export declare function superscriptOrdinal(text: string, options?: SymbolOptions): string;
|
|
28
|
+
/** Collapse multiple spaces to single space. */
|
|
141
29
|
export declare function collapseSpaces(text: string): string;
|
|
142
|
-
/**
|
|
143
|
-
* Converts repeated punctuation marks to Unicode ligature characters,
|
|
144
|
-
* squashing multiple marks to a single character.
|
|
145
|
-
*
|
|
146
|
-
* Handles:
|
|
147
|
-
* - "??" or "???" etc → "⁇" (squashed to double question mark ligature)
|
|
148
|
-
* - "?!" or "?!!" etc → "⁈" (question exclamation mark)
|
|
149
|
-
* - "!?" or "!??" etc → "⁉" (exclamation question mark)
|
|
150
|
-
* - "!!" or "!!!" etc → "!" (squashed to single exclamation)
|
|
151
|
-
*
|
|
152
|
-
* Note: These ligatures have poor font support, so this function is
|
|
153
|
-
* disabled by default.
|
|
154
|
-
*/
|
|
30
|
+
/** Convert ?? to ⁇, ?! to ⁈, !? to ⁉. Poor font support, disabled by default. */
|
|
155
31
|
export declare function punctuationLigatures(text: string, options?: SymbolOptions): string;
|
|
156
|
-
/**
|
|
157
|
-
* Applies all symbol transformations.
|
|
158
|
-
*
|
|
159
|
-
* Runs in order:
|
|
160
|
-
* 1. ellipsis
|
|
161
|
-
* 2. multiplication
|
|
162
|
-
* 3. mathSymbols
|
|
163
|
-
* 4. legalSymbols
|
|
164
|
-
* 5. arrows
|
|
165
|
-
*
|
|
166
|
-
* Note: `degrees` and `fractions` are not included by default as they
|
|
167
|
-
* may be too aggressive for some use cases. Call them explicitly if needed.
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```ts
|
|
171
|
-
* symbolTransform("Wait... 5x5 != 20 (c) 2024")
|
|
172
|
-
* // → "Wait… 5×5 ≠ 20 © 2024"
|
|
173
|
-
* ```
|
|
174
|
-
*/
|
|
32
|
+
/** Apply all symbol transforms. degrees/fractions excluded (too aggressive). */
|
|
175
33
|
export declare function symbolTransform(text: string, options?: SymbolOptions): string;
|
|
176
34
|
//# sourceMappingURL=symbols.d.ts.map
|
package/dist/symbols.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"symbols.d.ts","sourceRoot":"","sources":["../src/symbols.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"symbols.d.ts","sourceRoot":"","sources":["../src/symbols.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,MAAM,WAAW,aAAa;IAC5B,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,uDAAuD;IACvD,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AA8BD,4BAA4B;AAC5B,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAe1E;AAED,gDAAgD;AAChD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAmChF;AAED,0DAA0D;AAC1D,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAA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