@unicode-utils/core 0.12.0-beta.15

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.
@@ -0,0 +1,305 @@
1
+ //#region src/line-helpers.d.ts
2
+ /**
3
+ * Determines if a line is an End-of-File (EOF) marker.
4
+ *
5
+ * In Unicode data files, the EOF marker is typically represented
6
+ * as a line containing only "# EOF".
7
+ *
8
+ * @param {string} [line] - The line to check
9
+ * @returns {boolean} True if the line is an EOF marker, false otherwise
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * isEOFMarker("# EOF"); // true
14
+ * isEOFMarker("Some text"); // false
15
+ * isEOFMarker(); // false
16
+ * ```
17
+ */
18
+ declare function isEOFMarker(line?: string): boolean;
19
+ /**
20
+ * Determines if a line contains a hash boundary pattern.
21
+ *
22
+ * A hash boundary is a line containing a pattern like "# ###" (# followed by multiple #).
23
+ * These patterns are used in Unicode data files to separate different sections of content.
24
+ *
25
+ * @param {string} line - The line to check
26
+ * @returns {boolean} True if the line contains a hash boundary pattern, false otherwise
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * isHashBoundary("# #####"); // true
31
+ * isHashBoundary("# Some text"); // false
32
+ * isHashBoundary(""); // false
33
+ * ```
34
+ */
35
+ declare function isHashBoundary(line: string): boolean;
36
+ /**
37
+ * Determines if a line contains an equals boundary pattern.
38
+ *
39
+ * An equals boundary is a line containing a pattern like "# ===" (# followed by multiple =).
40
+ * These patterns are used in Unicode data files to separate different sections of content.
41
+ *
42
+ * @param {string} line - The line to check
43
+ * @returns {boolean} True if the line contains an equals boundary pattern, false otherwise
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * isEqualsBoundary("# ====="); // true
48
+ * isEqualsBoundary("# Some text"); // false
49
+ * isEqualsBoundary(""); // false
50
+ * ```
51
+ */
52
+ declare function isEqualsBoundary(line: string): boolean;
53
+ /**
54
+ * Determines if a line contains a dash boundary pattern.
55
+ *
56
+ * A dash boundary is a line containing a pattern like "# ---" (# followed by multiple -).
57
+ * These patterns are used in Unicode data files to separate different sections of content.
58
+ *
59
+ * @param {string} line - The line to check
60
+ * @returns {boolean} True if the line contains a dash boundary pattern, false otherwise
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * isDashBoundary("# -----"); // true
65
+ * isDashBoundary("# Some text"); // false
66
+ * isDashBoundary(""); // false
67
+ * ```
68
+ */
69
+ declare function isDashBoundary(line: string): boolean;
70
+ /**
71
+ * Determines if a line is any type of boundary line.
72
+ *
73
+ * A boundary line is any line that matches one of the boundary patterns:
74
+ * hash boundary, equals boundary, or dash boundary. These patterns are used
75
+ * in Unicode data files to separate different sections of content.
76
+ *
77
+ * @param {string} line - The line to check
78
+ * @returns {boolean} True if the line is a boundary line, false otherwise
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * isBoundaryLine("# #####"); // true (hash boundary)
83
+ * isBoundaryLine("# ====="); // true (equals boundary)
84
+ * isBoundaryLine("# -----"); // true (dash boundary)
85
+ * isBoundaryLine("# Some text"); // false
86
+ * isBoundaryLine(""); // false
87
+ * ```
88
+ */
89
+ declare function isBoundaryLine(line: string): boolean;
90
+ type BoundaryStyle = "#" | "=" | "-";
91
+ /**
92
+ * Extracts the style character from a boundary line.
93
+ *
94
+ * This function determines which type of boundary character is used in the line:
95
+ * '#', '=', or '-'. It checks the line against each boundary pattern and returns
96
+ * the corresponding character.
97
+ *
98
+ * @param {string} line - The boundary line to analyze
99
+ * @returns {BoundaryStyle} The boundary style character ('#', '=', or '-')
100
+ * @throws {Error} If the line is not a valid boundary line
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * getBoundaryLineStyle("# #####"); // returns "#"
105
+ * getBoundaryLineStyle("# ====="); // returns "="
106
+ * getBoundaryLineStyle("# -----"); // returns "-"
107
+ * ```
108
+ */
109
+ declare function getBoundaryLineStyle(line: string): BoundaryStyle;
110
+ /**
111
+ * Determines if a line is a comment line.
112
+ *
113
+ * A comment line is either a line that starts with "# " or
114
+ * a line that only contains "#" (possibly with whitespace).
115
+ *
116
+ * @param {string} line - The line to check
117
+ * @returns {boolean} True if the line is a comment line, false otherwise
118
+ */
119
+ declare function isCommentLine(line: string): boolean;
120
+ /**
121
+ * Removes the comment marker ('#') and any following whitespace from a line.
122
+ *
123
+ * This function is designed to extract the actual content from comment lines
124
+ * in Unicode data files by removing the leading '#' character and any whitespace
125
+ * that follows it.
126
+ *
127
+ * @param {string} line - The comment line to trim
128
+ * @returns {string} The content of the comment line without the comment marker
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * trimCommentLine("# Some comment"); // returns "Some comment"
133
+ * trimCommentLine("#\tTabbed comment"); // returns "Tabbed comment"
134
+ * trimCommentLine(""); // returns ""
135
+ * ```
136
+ */
137
+ declare function trimCommentLine(line: string): string;
138
+ /**
139
+ * Checks if a string line is empty after trimming whitespace.
140
+ *
141
+ * @param {string} line - The string to check for emptiness
142
+ * @returns {boolean} A boolean indicating whether the trimmed line is empty
143
+ */
144
+ declare function isEmptyLine(line: string): boolean;
145
+ /**
146
+ * Determines if a line contains data in a Unicode data file.
147
+ *
148
+ * A line is considered to contain data if it is neither a comment line
149
+ * (starting with '#') nor an empty line.
150
+ *
151
+ * @param {string} line - The line to check
152
+ * @returns {boolean} True if the line contains data, false otherwise
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * isLineWithData("U+0020;SPACE"); // true
157
+ * isLineWithData("# Comment line"); // false
158
+ * isLineWithData(""); // false
159
+ * ```
160
+ */
161
+ declare function isLineWithData(line: string): boolean;
162
+ /**
163
+ * Check if a given line from a Unicode data file is a 'missing' annotation.
164
+ *
165
+ * In Unicode data files, lines starting with '# @missing:' indicate
166
+ * a range of code points that are not assigned.
167
+ *
168
+ * @param {string} line - The line to check
169
+ * @returns {boolean} True if the line is a missing annotation, false otherwise
170
+ */
171
+ declare function isMissingAnnotation(line: string): boolean;
172
+ type SpecialTag = "none" | "script" | "code-point";
173
+ interface MissingAnnotation {
174
+ start: string;
175
+ end: string;
176
+ propertyName?: string;
177
+ defaultPropertyValue: string;
178
+ /**
179
+ * The special tag used in the Annotation.
180
+ *
181
+ * NOTE:
182
+ * - "none" no value is defined
183
+ * - "script" the value equal to the Script property value for this code point
184
+ * - "code-point" the string representation of the code point value
185
+ */
186
+ specialTag?: SpecialTag;
187
+ }
188
+ /**
189
+ * Parses a line into a MissingAnnotation object.
190
+ *
191
+ * This function attempts to extract information from a line that follows the
192
+ * format of a missing annotation in Unicode data files.
193
+ *
194
+ * The format being parsed is:
195
+ * `# @missing: START..END; DEFAULT_PROP_VALUE_OR_PROPERTY_NAME[; DEFAULT_PROPERTY_VALUE]`
196
+ *
197
+ * @param {string} line - The line to parse
198
+ * @returns {MissingAnnotation | null} A MissingAnnotation object if the line is a valid missing annotation, null otherwise
199
+ *
200
+ * @example
201
+ * ```ts
202
+ * parseMissingAnnotation("# @missing: 0000..007F; NA")
203
+ * // -> { start: "0000", end: "007F", defaultPropertyValue: "NA" }
204
+ *
205
+ * parseMissingAnnotation("# @missing: 0000..007F; Script; Unknown")
206
+ * // -> { start: "0000", end: "007F", propertyName: "Script", defaultPropertyValue: "Unknown" }
207
+ * ```
208
+ */
209
+ declare function parseMissingAnnotation(line: string): MissingAnnotation | null;
210
+ /**
211
+ * Attempts to infer the file name from the first line of a Unicode data file.
212
+ *
213
+ * This function extracts the file name from the first line of the content,
214
+ * assuming it's a comment line. It removes any leading '#' characters and whitespace.
215
+ *
216
+ * For example:
217
+ * - From a file with first line "# ArabicShaping-5.0.0.txt", it returns "ArabicShaping"
218
+ * - From a file with first line "# UnicodeData-5.0.0.txt", it returns "UnicodeData"
219
+ *
220
+ * @param {string} line - The first line of the file
221
+ * @returns {string | undefined} The inferred file name, or undefined if it can't be determined
222
+ */
223
+ declare function inferFileName(line: string): string | undefined;
224
+ /**
225
+ * Attempts to infer the version from the first line of a Unicode data file.
226
+ *
227
+ * This function extracts the version number from the first line of the content,
228
+ * assuming it's a comment line. It looks for a pattern like "Name-X.Y.Z.txt"
229
+ * and extracts the X.Y.Z part as the version.
230
+ *
231
+ * For example:
232
+ * - From a file with first line "# ArabicShaping-5.0.0.txt", it returns "5.0.0"
233
+ * - From a file with first line "# UnicodeData-14.0.0.txt", it returns "14.0.0"
234
+ *
235
+ * @param {string} line - The first line of the file
236
+ * @returns {string | undefined} The inferred version number, or undefined if it can't be determined
237
+ */
238
+ declare function inferVersion(line: string): string | undefined;
239
+ interface ParsedFileName {
240
+ fileName: string;
241
+ version: string | undefined;
242
+ }
243
+ /**
244
+ * Parses a line from a Unicode data file to extract the file name and version information.
245
+ *
246
+ * This function tries to extract file name and version information from a line that
247
+ * typically appears at the beginning of Unicode data files. It handles various formats:
248
+ * - "FileName-1.2.3.txt"
249
+ * - "FileName-1.2.3"
250
+ * - "FileName.txt"
251
+ *
252
+ * The function also properly handles comment markers at the beginning of the line.
253
+ *
254
+ * @param {string} line - The line to parse, typically the first line of a Unicode data file
255
+ * @returns {ParsedFileName | undefined} An object containing the file name and version if
256
+ * successfully parsed, or undefined if parsing fails
257
+ *
258
+ * @example
259
+ * ```ts
260
+ * parseFileNameLine("# UnicodeData-14.0.0.txt");
261
+ * // Returns { fileName: "UnicodeData", version: "14.0.0" }
262
+ *
263
+ * parseFileNameLine("# ArabicShaping.txt");
264
+ * // Returns { fileName: "ArabicShaping", version: undefined }
265
+ * ```
266
+ */
267
+ declare function parseFileNameLine(line: string): ParsedFileName | undefined;
268
+ /**
269
+ * Determines if a line represents a property definition in Unicode data files.
270
+ *
271
+ * In Unicode data files, properties are typically defined in comment lines that
272
+ * start with "# Property:" followed by the property name.
273
+ *
274
+ * @param {string} line - The line to check
275
+ * @returns {boolean} True if the line is a property definition, false otherwise
276
+ *
277
+ * @example
278
+ * ```ts
279
+ * isPropertyLine("# Property: Age"); // true
280
+ * isPropertyLine("# Some other comment"); // false
281
+ * isPropertyLine(""); // false
282
+ * ```
283
+ */
284
+ declare function isPropertyLine(line: string): boolean;
285
+ /**
286
+ * Extracts the property value from a property definition line in Unicode data files.
287
+ *
288
+ * This function parses a line that follows the format '# Property: [PropertyValue]'
289
+ * and returns the PropertyValue part. It is used internally by isPropertyLine
290
+ * to parse property definitions in Unicode data files.
291
+ *
292
+ * @param {string} line - The line to extract the property value from
293
+ * @returns {string | undefined} The extracted property value, or undefined if
294
+ * the line is not a valid property definition
295
+ *
296
+ * @example
297
+ * ```ts
298
+ * getPropertyValue("# Property: Age"); // returns "Age"
299
+ * getPropertyValue("# Property: "); // returns undefined
300
+ * getPropertyValue("# Not a property line"); // returns undefined
301
+ * ```
302
+ */
303
+ declare function getPropertyValue(line: string): string | undefined;
304
+ //#endregion
305
+ export { isMissingAnnotation as _, getBoundaryLineStyle as a, parseMissingAnnotation as b, inferVersion as c, isDashBoundary as d, isEOFMarker as f, isLineWithData as g, isHashBoundary as h, SpecialTag as i, isBoundaryLine as l, isEqualsBoundary as m, MissingAnnotation as n, getPropertyValue as o, isEmptyLine as p, ParsedFileName as r, inferFileName as s, BoundaryStyle as t, isCommentLine as u, isPropertyLine as v, trimCommentLine as x, parseFileNameLine as y };
@@ -0,0 +1,2 @@
1
+ import { _ as isMissingAnnotation, a as getBoundaryLineStyle, b as parseMissingAnnotation, c as inferVersion, d as isDashBoundary, f as isEOFMarker, g as isLineWithData, h as isHashBoundary, i as SpecialTag, l as isBoundaryLine, m as isEqualsBoundary, n as MissingAnnotation, o as getPropertyValue, p as isEmptyLine, r as ParsedFileName, s as inferFileName, t as BoundaryStyle, u as isCommentLine, v as isPropertyLine, x as trimCommentLine, y as parseFileNameLine } from "./line-helpers-DGsVuiW2.js";
2
+ export { BoundaryStyle, MissingAnnotation, ParsedFileName, SpecialTag, getBoundaryLineStyle, getPropertyValue, inferFileName, inferVersion, isBoundaryLine, isCommentLine, isDashBoundary, isEOFMarker, isEmptyLine, isEqualsBoundary, isHashBoundary, isLineWithData, isMissingAnnotation, isPropertyLine, parseFileNameLine, parseMissingAnnotation, trimCommentLine };
@@ -0,0 +1,3 @@
1
+ import { _ as trimCommentLine, a as isBoundaryLine, c as isEOFMarker, d as isHashBoundary, f as isLineWithData, g as parseMissingAnnotation, h as parseFileNameLine, i as inferVersion, l as isEmptyLine, m as isPropertyLine, n as getPropertyValue, o as isCommentLine, p as isMissingAnnotation, r as inferFileName, s as isDashBoundary, t as getBoundaryLineStyle, u as isEqualsBoundary } from "./line-helpers-CYDQ0FnQ.js";
2
+
3
+ export { getBoundaryLineStyle, getPropertyValue, inferFileName, inferVersion, isBoundaryLine, isCommentLine, isDashBoundary, isEOFMarker, isEmptyLine, isEqualsBoundary, isHashBoundary, isLineWithData, isMissingAnnotation, isPropertyLine, parseFileNameLine, parseMissingAnnotation, trimCommentLine };
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@unicode-utils/core",
3
+ "version": "0.12.0-beta.15",
4
+ "description": "Utilities for working with Unicode",
5
+ "type": "module",
6
+ "author": {
7
+ "name": "Lucas Nørgård",
8
+ "email": "lucasnrgaard@gmail.com",
9
+ "url": "https://luxass.dev"
10
+ },
11
+ "license": "MIT",
12
+ "homepage": "https://github.com/luxass/unicode-utils#readme",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/luxass/unicode-utils.git",
16
+ "directory": "packages/core"
17
+ },
18
+ "bugs": "https://github.com/luxass/unicode-utils/issues",
19
+ "keywords": [
20
+ "unicode",
21
+ "utils"
22
+ ],
23
+ "exports": {
24
+ ".": "./dist/index.js",
25
+ "./constants": "./dist/constants.js",
26
+ "./datafile": "./dist/datafile.js",
27
+ "./line-helpers": "./dist/line-helpers.js",
28
+ "./package.json": "./package.json"
29
+ },
30
+ "main": "./dist/index.js",
31
+ "module": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "files": [
37
+ "dist"
38
+ ],
39
+ "dependencies": {
40
+ "@luxass/utils": "2.7.2",
41
+ "defu": "6.1.4",
42
+ "@unicode-utils/metadata": "0.12.0-beta.15"
43
+ },
44
+ "devDependencies": {
45
+ "@luxass/eslint-config": "6.0.1",
46
+ "@types/node": "24.9.1",
47
+ "eslint": "9.38.0",
48
+ "eslint-plugin-format": "1.0.2",
49
+ "msw": "2.11.6",
50
+ "publint": "0.3.15",
51
+ "tsdown": "0.15.11",
52
+ "tsx": "4.20.6",
53
+ "typescript": "5.9.3",
54
+ "vitest-package-exports": "0.1.1",
55
+ "@unicode-utils-tooling/tsconfig": "1.0.0",
56
+ "@unicode-utils-tooling/tsdown-config": "1.0.0"
57
+ },
58
+ "scripts": {
59
+ "build": "tsdown --tsconfig=./tsconfig.build.json",
60
+ "dev": "tsdown --watch",
61
+ "test": "vitest --run",
62
+ "typecheck": "tsc --noEmit",
63
+ "lint": "eslint ."
64
+ }
65
+ }