@leismore/lmos-nodejs-unicode-print-chars 0.0.0-stage β†’ 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Leismoreβ„’
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,144 @@
1
- # Temporary Holding Version
1
+ # lmos-nodejs-unicode-print-chars
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A class represents a string of printable characters in Unicode.
4
+
5
+ A robust Node.js utility to validate, sanitize, and ensure strings contain only **safe, printable Unicode characters**.
6
+
7
+ ## Motivation
8
+
9
+ In text processing, certain characters are invisible but active. Legacy control characters like `BEL` (ASCII 07) can trigger machine bells, while `DEL` (ASCII 7F) can alter text streams.
10
+
11
+ If an online form accepts user input and blindly processes it without validation, malicious or malformed inputs containing hidden control characters can disrupt your application, break JSON parsing, corrupt logs, or exploit text-rendering engines.
12
+
13
+ While modern frameworks offer basic protections, the safest practice is defense-in-depth: stopping unwanted characters at the very beginning of their journey.
14
+
15
+ This package provides a strict boundary for user data, ensuring that your strings consist entirely of valid, safe, and visible printable characters across the Unicode spectrum.
16
+
17
+ ## Installation
18
+
19
+ `npm install @leismore/lmos-nodejs-unicode-print-chars`
20
+
21
+ ## Test
22
+
23
+ `npm test`
24
+
25
+ ## Build
26
+
27
+ `npm run build`
28
+
29
+ ## Examples
30
+
31
+ ```typescript
32
+
33
+ import { PrintableCharsUni, PCUError } from '@leismore/lmos-nodejs-unicode-print-chars';
34
+
35
+ const STRING_VALID_EN = 'I know that I know nothing. πŸ›οΈ';
36
+ const STRING_VALID_ZH = 'ζˆ‘ε”―δΈ€ηŸ₯ι“ηš„ε°±ζ˜―ζˆ‘δΈ€ζ— ζ‰€ηŸ₯。';
37
+ const STRING_VALID_JP = '私はθ‡ͺεˆ†γŒδ½•γ‚‚ηŸ₯らγͺいということだけをηŸ₯っている。';
38
+
39
+ // Throws PCUError, if illegal characters
40
+ const pcuEN = new PrintableCharsUni(STRING_VALID_EN);
41
+ const pcuZH = new PrintableCharsUni(STRING_VALID_ZH);
42
+ const pcuJP = new PrintableCharsUni(STRING_VALID_JP);
43
+
44
+ /**
45
+ * Output:
46
+ * - I know that I know nothing. πŸ›οΈ
47
+ * - ζˆ‘ε”―δΈ€ηŸ₯ι“ηš„ε°±ζ˜―ζˆ‘δΈ€ζ— ζ‰€ηŸ₯。
48
+ * - 私はθ‡ͺεˆ†γŒδ½•γ‚‚ηŸ₯らγͺいということだけをηŸ₯っている。
49
+ */
50
+
51
+ console.log(String(pcuEN));
52
+ console.log(String(pcuZH));
53
+ console.log(String(pcuJP));
54
+
55
+ ```
56
+
57
+ ## API Reference
58
+
59
+ ### Exports
60
+
61
+ ```typescript
62
+ export { PCUError, PrintableCharsUni };
63
+ export type { PCUErrorErr };
64
+ ```
65
+
66
+ ### PCUError
67
+
68
+ **PCUError Class Properties**
69
+
70
+ * `error` : `PCUErrorErr`
71
+ * `previous`? : `Error`
72
+ * `timestamp` : `Date`
73
+
74
+ `PCUError` is the Error class for this package. All errors thrown by this library are instances of this class, allowing you to easily catch and handle them in your application.
75
+
76
+ `PCUError` extends the `LMError` class from [@leismore/lmos-nodejs-lmerror](https://www.npmjs.com/package/@leismore/lmos-nodejs-lmerror). For more details, please refer to the documentation of `@leismore/lmos-nodejs-lmerror`.
77
+
78
+ ### PCUErrorErr
79
+
80
+ ```typescript
81
+ type PCUErrorErr = {
82
+ readonly message: string, // Message for human. Only ASCII printable characters allowed.
83
+ readonly code: string // Code for machine. Only letter, number, and underscore allowed.
84
+ };
85
+ ```
86
+
87
+ ### PrintableCharsUni
88
+
89
+ ```typescript
90
+ class PrintableCharsUni {
91
+
92
+ /**
93
+ * @throws {PCUError}
94
+ * 2 invalid_string
95
+ */
96
+ constructor(chars: string)
97
+
98
+ public toString(): string
99
+
100
+ public static isValid(chars: string): boolean
101
+
102
+ /**
103
+ * @throws {PCUError}
104
+ * 3 not_string
105
+ */
106
+ public static removeInvalidChars(chars: string): string
107
+
108
+ }
109
+ ```
110
+
111
+ `PrintableCharsUni` class represents a string of printable characters in Unicode.
112
+
113
+ ## License
114
+
115
+ Β© [Leismoreβ„’](https://www.leismore.co) 2026
116
+
117
+ [MIT License](https://github.com/leismore/lmos-nodejs-unicode-print-chars/blob/main/LICENSE)
118
+
119
+ ## Donation
120
+
121
+ * [Leismoreβ„’](https://github.com/sponsors/leismore) on GitHub
122
+
123
+ Help us to pay our bills, so we can focus on developing and maintaining this project.
124
+
125
+ ## Authors
126
+
127
+ * [Kyle Chinn / Kai Qin / 秦凯](https://kyle.chinn.leismore.org) since 28 September 2026
128
+
129
+ ## Credits
130
+
131
+ * [@leismore/lmos-nodejs-lmerror](https://www.npmjs.com/package/@leismore/lmos-nodejs-lmerror)
132
+
133
+ ## References
134
+
135
+ * Unicode 18.0.0 <https://www.unicode.org/versions/Unicode18.0.0>
136
+
137
+
138
+
139
+
140
+ ------------------------------------------------------------------------------
141
+
142
+ Product of [Leismoreβ„’ OpenSource](https://lmos.leismore.org) Project
143
+
144
+ Supported by [Leismoreβ„’](https://www.leismore.co) (Australian Business Number: 25 935 862 619)
@@ -0,0 +1,5 @@
1
+ import { PCUError } from './lib/PCUError.js';
2
+ import type { PCUErrorErr } from './lib/PCUError.js';
3
+ import { PrintableCharsUni } from './lib/PrintableCharsUni.js';
4
+ export { PCUError, PrintableCharsUni };
5
+ export type { PCUErrorErr };
@@ -0,0 +1,3 @@
1
+ import { PCUError } from './lib/PCUError.js';
2
+ import { PrintableCharsUni } from './lib/PrintableCharsUni.js';
3
+ export { PCUError, PrintableCharsUni };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The Error class for this project.
3
+ *
4
+ * Code Message
5
+ * 1 unknown
6
+ * 2 invalid_string
7
+ * 3 not_string
8
+ */
9
+ import { LMError } from '@leismore/lmos-nodejs-lmerror';
10
+ import type { LMErrorErr as PCUErrorErr } from '@leismore/lmos-nodejs-lmerror';
11
+ declare class PCUError extends LMError {
12
+ /**
13
+ * @throws {Error}
14
+ * invalid_error
15
+ * invalid_error_message
16
+ * invalid_error_code
17
+ * invalid_previous
18
+ */
19
+ constructor(error: PCUErrorErr, previous?: Error);
20
+ }
21
+ export { PCUError };
22
+ export type { PCUErrorErr };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The Error class for this project.
3
+ *
4
+ * Code Message
5
+ * 1 unknown
6
+ * 2 invalid_string
7
+ * 3 not_string
8
+ */
9
+ import { LMError } from '@leismore/lmos-nodejs-lmerror';
10
+ class PCUError extends LMError {
11
+ /**
12
+ * @throws {Error}
13
+ * invalid_error
14
+ * invalid_error_message
15
+ * invalid_error_code
16
+ * invalid_previous
17
+ */
18
+ constructor(error, previous) {
19
+ super(error, undefined, previous);
20
+ this.name = 'PCUError';
21
+ }
22
+ }
23
+ export { PCUError };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * PrintableCharsUni class represents a string of printable characters in Unicode.
3
+ */
4
+ declare class PrintableCharsUni {
5
+ protected readonly chars: string;
6
+ /**
7
+ *
8
+ * @throws {PCUError}
9
+ * 2 invalid_string
10
+ */
11
+ constructor(chars: string);
12
+ toString(): string;
13
+ static isValid(chars: string): boolean;
14
+ /**
15
+ *
16
+ * @throws {PCUError}
17
+ * 3 not_string
18
+ */
19
+ static removeInvalidChars(chars: string): string;
20
+ }
21
+ export { PrintableCharsUni };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * PrintableCharsUni class represents a string of printable characters in Unicode.
3
+ */
4
+ import { PCUError } from './PCUError.js';
5
+ const regexValidString = /^[^\p{C}\p{Zl}\p{Zp}]+$/u;
6
+ const regexInvalidChars = /[\p{C}\p{Zl}\p{Zp}]/ug;
7
+ class PrintableCharsUni {
8
+ chars;
9
+ /**
10
+ *
11
+ * @throws {PCUError}
12
+ * 2 invalid_string
13
+ */
14
+ constructor(chars) {
15
+ if (!PrintableCharsUni.isValid(chars)) {
16
+ throw new PCUError({ code: '2', message: 'invalid_string' });
17
+ }
18
+ this.chars = chars;
19
+ }
20
+ toString() {
21
+ return this.chars;
22
+ }
23
+ /* Static Methods */
24
+ static isValid(chars) {
25
+ return (typeof chars === 'string' && regexValidString.test(chars));
26
+ }
27
+ /**
28
+ *
29
+ * @throws {PCUError}
30
+ * 3 not_string
31
+ */
32
+ static removeInvalidChars(chars) {
33
+ if (typeof chars !== 'string') {
34
+ throw new PCUError({ code: '3', message: 'not_string' });
35
+ }
36
+ return chars.replace(regexInvalidChars, '');
37
+ }
38
+ }
39
+ export { PrintableCharsUni };
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@leismore/lmos-nodejs-unicode-print-chars",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "A class represents a string of printable characters in Unicode.",
5
+ "keywords": [
6
+ "Unicode",
7
+ "Printable Characters",
8
+ "LMOS for Node.js",
9
+ "LMOS",
10
+ "Leismore OpenSource",
11
+ "Leismore",
12
+ "Node.js",
13
+ "NodeJS",
14
+ "Node"
15
+ ],
16
+ "homepage": "https://github.com/leismore/lmos-nodejs-unicode-print-chars#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/leismore/lmos-nodejs-unicode-print-chars/issues"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/leismore/lmos-nodejs-unicode-print-chars.git"
23
+ },
24
+ "funding": {
25
+ "type": "github",
26
+ "url": "https://github.com/sponsors/leismore"
27
+ },
28
+ "license": "MIT",
29
+ "author": {
30
+ "name": "Kyle Chinn",
31
+ "url": "https://kyle.chinn.leismore.org",
32
+ "email": "kyle.chinn@leismore.co"
33
+ },
34
+ "type": "module",
35
+ "types": "dist/src/index.d.ts",
36
+ "main": "dist/src/index.js",
37
+ "scripts": {
38
+ "test": "tsx test/test.ts",
39
+ "build": "tsc",
40
+ "start": "cd dist/src && node index.js",
41
+ "prepare": "npm run build",
42
+ "prepublishOnly": "npm run build && npm run test"
43
+ },
44
+ "devDependencies": {
45
+ "@leismore/lmos-nodejs-primitives": "^1.2.4",
46
+ "@types/node": "^24.19.0",
47
+ "tsx": "^4.23.15",
48
+ "typescript": "^7.0.2"
49
+ },
50
+ "allowScripts": {
51
+ "esbuild@0.28.2": true
52
+ },
53
+ "dependencies": {
54
+ "@leismore/lmos-nodejs-lmerror": "^3.0.4"
55
+ }
56
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions":
3
+ {
4
+ "lib": ["ES2024"],
5
+ "target": "ES2024",
6
+ "module": "nodenext",
7
+ "moduleResolution": "nodenext",
8
+ "strict": true,
9
+ "resolveJsonModule": true,
10
+ "declaration": true,
11
+ "allowJs": false,
12
+ "rootDir": ".",
13
+ "outDir": "dist",
14
+ "types": ["node"]
15
+ },
16
+ "include": ["src/**/*", "test/**/*"]
17
+ }