utfu 0.3.0 → 0.4.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/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+ # top-most EditorConfig file
2
+ root = true
3
+
4
+ # Unix-style newlines with a newline ending every file
5
+ [*]
6
+ end_of_line = lf
7
+ insert_final_newline = true
8
+ charset = utf-8
9
+ indent_style = space
10
+ indent_size = 2
package/.eslintrc ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "parserOptions": {
3
+ "sourceType": "module",
4
+ "parser": "babel-eslint",
5
+ "allowImportExportEverywhere": true,
6
+ "ecmaVersion": 2017,
7
+ "ecmaFeatures": {
8
+ "jsx": true
9
+ }
10
+ },
11
+ "env": {
12
+ "commonjs": true,
13
+ "es6": true
14
+ },
15
+ "extends": ["plugin:security/recommended"],
16
+ "plugins": ["import", "node", "prettier", "promise", "security", "standard"],
17
+ "rules": {
18
+ "indent": ["off"],
19
+ "no-eval": ["error"],
20
+ "no-script-url": ["error"],
21
+ "linebreak-style": ["warn", "unix"],
22
+ "quotes": ["warn", "single"],
23
+ "semi": ["warn", "never"],
24
+ "no-undef": ["off"],
25
+ "require-jsdoc": [
26
+ "off",
27
+ {
28
+ "require": null,
29
+ "FunctionDeclaration": [true],
30
+ "MethodDefinition": [true],
31
+ "ClassDeclaration": [true],
32
+ "ArrowFunctionExpression": [true],
33
+ "FunctionExpression": [true]
34
+ }
35
+ ],
36
+ "valid-jsdoc": ["warn"],
37
+ "no-useless-escape": ["off"],
38
+ "key-spacing": ["off"],
39
+ "wrap-iife": ["error", "inside"],
40
+ "handle-callback-err": ["error"],
41
+ "callback-return": ["error"],
42
+ "no-mixed-requires": ["error"],
43
+ "no-unused-vars": [
44
+ "warn",
45
+ {
46
+ "argsIgnorePattern": "i|res|next|^err"
47
+ }
48
+ ],
49
+ "security/detect-non-literal-fs-filename": ["off"],
50
+ "security/detect-non-literal-regexp": ["off"],
51
+ "security/detect-non-literal-require": ["off"],
52
+ "security/detect-object-injection": ["off"],
53
+ "vue/html-self-closing": ["off"],
54
+ "vue/no-v-html": ["off"],
55
+ "vue/max-attributes-per-line": ["off"]
56
+ }
57
+ }
@@ -0,0 +1,28 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main, master]
6
+ pull_request:
7
+ branches: [main, master]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v6
14
+
15
+ - name: Setup pnpm
16
+ uses: pnpm/action-setup@v4
17
+
18
+ - name: Setup Node.js
19
+ uses: actions/setup-node@v6
20
+ with:
21
+ node-version: "20"
22
+ cache: "pnpm"
23
+
24
+ - name: Install dependencies
25
+ run: pnpm install --frozen-lockfile
26
+
27
+ - name: Run tests
28
+ run: pnpm test
package/.oxfmtrc.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "./node_modules/oxfmt/configuration_schema.json",
3
+ "ignorePatterns": [
4
+ "node_modules",
5
+ "dist"
6
+ ],
7
+ "arrowParens": "avoid",
8
+ "bracketSpacing": true,
9
+ "printWidth": 120,
10
+ "proseWrap": "preserve",
11
+ "semi": true,
12
+ "singleQuote": true,
13
+ "tabWidth": 2
14
+ }
package/.oxlintrc.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "$schema": "./node_modules/oxlint/configuration_schema.json",
3
+ "plugins": [
4
+ "unicorn",
5
+ "typescript",
6
+ "oxc"
7
+ ],
8
+ "categories": {},
9
+ "rules": {},
10
+ "settings": {
11
+ "jsdoc": {
12
+ "ignorePrivate": false,
13
+ "ignoreInternal": false,
14
+ "ignoreReplacesDocs": true,
15
+ "overrideReplacesDocs": true,
16
+ "augmentsExtendsReplacesDocs": false,
17
+ "implementsReplacesDocs": false,
18
+ "exemptDestructuredRootsFromChecks": false,
19
+ "tagNamePreference": {}
20
+ },
21
+ "vitest": {
22
+ "typecheck": false
23
+ }
24
+ },
25
+ "env": {
26
+ "builtin": true
27
+ },
28
+ "globals": {},
29
+ "ignorePatterns": [
30
+ "node_modules",
31
+ "dist"
32
+ ]
33
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "deepscan.enable": true,
3
+ "editor.defaultFormatter": "oxc.oxc-vscode",
4
+ "beans.mcp.showStartupNotification": false
5
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## Unreleased
6
+
7
+ ## [0.4.0] - 2026-02-21
8
+
9
+ - build: add postbuild script to write a minimal `dist/package.json` with
10
+ `main`/`module`/`types` and `exports` fields so the published package
11
+ points at the bundled ESM and CJS outputs.
12
+ - ci: generate `dist/package.json` via `scripts/write-dist-package.js` (ESM)
13
+ - test: add `tests/dist-package.test.ts` to verify `dist/package.json` is
14
+ created and contains the correct fields after the build
15
+ - fix: remove unsupported `u` flags from regex literals in `src/mappings.ts`
16
+ so TypeScript compiles with the current target.
@@ -0,0 +1,127 @@
1
+ # Contributor Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ - Demonstrating empathy and kindness toward other people
21
+ - Being respectful of differing opinions, viewpoints, and experiences
22
+ - Giving and gracefully accepting constructive feedback
23
+ - Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ - Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ - The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ - Trolling, insulting or derogatory comments, and personal or political attacks
33
+ - Public or private harassment
34
+ - Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ - Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at [hello@self.agency](mailto:hello@self.agency).
63
+ All complaints will be reviewed and investigated promptly and fairly.
64
+
65
+ All community leaders are obligated to respect the privacy and security of the
66
+ reporter of any incident.
67
+
68
+ ## Enforcement Guidelines
69
+
70
+ Community leaders will follow these Community Impact Guidelines in determining
71
+ the consequences for any action they deem in violation of this Code of Conduct:
72
+
73
+ ### 1. Correction
74
+
75
+ **Community Impact**: Use of inappropriate language or other behavior deemed
76
+ unprofessional or unwelcome in the community.
77
+
78
+ **Consequence**: A private, written warning from community leaders, providing
79
+ clarity around the nature of the violation and an explanation of why the
80
+ behavior was inappropriate. A public apology may be requested.
81
+
82
+ ### 2. Warning
83
+
84
+ **Community Impact**: A violation through a single incident or series
85
+ of actions.
86
+
87
+ **Consequence**: A warning with consequences for continued behavior. No
88
+ interaction with the people involved, including unsolicited interaction with
89
+ those enforcing the Code of Conduct, for a specified period of time. This
90
+ includes avoiding interactions in community spaces as well as external channels
91
+ like social media. Violating these terms may lead to a temporary or
92
+ permanent ban.
93
+
94
+ ### 3. Temporary Ban
95
+
96
+ **Community Impact**: A serious violation of community standards, including
97
+ sustained inappropriate behavior.
98
+
99
+ **Consequence**: A temporary ban from any sort of interaction or public
100
+ communication with the community for a specified period of time. No public or
101
+ private interaction with the people involved, including unsolicited interaction
102
+ with those enforcing the Code of Conduct, is allowed during this period.
103
+ Violating these terms may lead to a permanent ban.
104
+
105
+ ### 4. Permanent Ban
106
+
107
+ **Community Impact**: Demonstrating a pattern of violation of community
108
+ standards, including sustained inappropriate behavior, harassment of an
109
+ individual, or aggression toward or disparagement of classes of individuals.
110
+
111
+ **Consequence**: A permanent ban from any sort of public interaction within
112
+ the community.
113
+
114
+ ## Attribution
115
+
116
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
117
+ version 2.0, available at
118
+ [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html).
119
+
120
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
121
+ enforcement ladder](https://github.com/mozilla/diversity).
122
+
123
+ [homepage]: https://www.contributor-covenant.org
124
+
125
+ For answers to common questions about this code of conduct, see the FAQ at
126
+ [https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are available at
127
+ [https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations).
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2020, Daniel Sieradski
1
+ Copyright (c) 2026, Daniel Sieradski
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of
4
4
  this software and associated documentation files (the "Software"), to deal in
@@ -15,4 +15,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
15
  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
16
  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
17
  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # üŧ⨍û ➞ utfu
2
2
 
3
- [![npm](https://img.shields.io/npm/dt/utfu.svg)](https://www.npmjs.com/package/utfu) [![npm](https://img.shields.io/npm/v/utfu.svg)](https://www.npmjs.com/package/utfu) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Twitter: @selfagency_llc](https://img.shields.io/twitter/follow/selfagency_llc.svg?style=social)](https://twitter.com/selfagency_llc)
3
+ [![npm](https://img.shields.io/npm/v/utfu.svg)](https://www.npmjs.com/package/utfu) [![npm](https://img.shields.io/npm/dt/utfu.svg)](https://www.npmjs.com/package/utfu) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
4
 
5
5
  Replaces busted characters carried over from legacy text encodings with the proper UTF-8 characters.
6
6
 
@@ -24,7 +24,7 @@ Pass it to either method, `hex`, `htx`, or `txt`, and you'll hopefully get back:
24
24
  - `htx` substitutes the HTML escape sequence (ie., `€`)
25
25
  - `txt` substitutes the actual character (ie., `€`)
26
26
 
27
- - See substitution chart [here](https://www.i18nqa.com/debug/utf8-debug.html) for mappings, more or less
27
+ - See [substitution chart](https://www.i18nqa.com/debug/utf8-debug.html) for mappings, more or less
28
28
 
29
29
  ```javascript
30
30
  import { hex, htx, txt } from 'utfu'
@@ -47,13 +47,16 @@ const cleanTxt = txt(dirty)
47
47
  yarn test
48
48
  ```
49
49
 
50
+ ## CI
51
+
52
+ This repository includes a GitHub Actions workflow that runs the test suite on push and pull requests (see `.github/workflows/ci.yml`).
53
+
50
54
  ## Author
51
55
 
52
56
  👤 **Daniel Sieradski <hello@self.agency>**
53
57
 
54
58
  - Website: [self.agency](https://self.agency)
55
- - Twitter: [@selfagency_llc](https://twitter.com/selfagency_llc)
56
- - GitLab: [@selfagency](https://gitlab.com/selfagency)
59
+ - BlueSky: [@self.agency](https://bsky.app/profile/self.agency)
57
60
 
58
61
  ## Acknowledgements
59
62
 
package/package.json CHANGED
@@ -1,14 +1,8 @@
1
1
  {
2
2
  "name": "utfu",
3
+ "version": "0.4.0",
4
+ "private": false,
3
5
  "description": "Replaces busted characters carried over from legacy text encodings with the proper UTF-8 characters.",
4
- "version": "0.3.0",
5
- "license": "MIT",
6
- "files": [
7
- "dist-*/",
8
- "bin/"
9
- ],
10
- "pika": true,
11
- "sideEffects": false,
12
6
  "keywords": [
13
7
  "utf",
14
8
  "utf-8",
@@ -20,39 +14,26 @@
20
14
  "characters"
21
15
  ],
22
16
  "repository": "https://gitlab.com/selfagency/utfu.git",
23
- "dependencies": {
24
- "he": "^1.2.0",
25
- "windows-1252": "^1.0.0"
26
- },
17
+ "license": "MIT",
18
+ "author": "Daniel Sieradski <daniel@self.agency>",
19
+ "type": "module",
20
+ "types": "dist/index.d.ts",
27
21
  "devDependencies": {
28
- "@babel/core": "^7.9.0",
29
- "@babel/preset-env": "^7.9.6",
30
- "@pika/pack": "^0.5.0",
31
- "@pika/plugin-build-node": "^0.9.2",
32
- "@pika/plugin-build-types": "^0.9.2",
33
- "@pika/plugin-build-web": "^0.9.2",
34
- "@pika/plugin-bundle-node": "^0.9.2",
35
- "@pika/plugin-bundle-web": "^0.9.2",
36
- "@pika/plugin-standard-pkg": "^0.9.2",
37
- "babel-eslint": "^10.1.0",
38
- "babel-jest": "^25.4.0",
39
- "babel-loader": "^8.1.0",
40
- "eslint": "^6.8.0",
41
- "eslint-config-prettier": "^6.11.0",
42
- "eslint-plugin-import": "^2.20.2",
43
- "eslint-plugin-node": "^11.1.0",
44
- "eslint-plugin-prettier": "^3.1.3",
45
- "eslint-plugin-promise": "^4.2.1",
46
- "eslint-plugin-security": "^1.4.0",
47
- "eslint-plugin-standard": "^4.0.1",
48
- "jest": "^25.4.0",
49
- "pika-plugin-minify": "^0.1.0",
50
- "prettier": "^2.0.5",
51
- "typescript": "^3.8.3"
22
+ "@types/he": "^1.2.3",
23
+ "@types/node": "^25.3.0",
24
+ "esbuild": "^0.27.3",
25
+ "he": "^1.2.0",
26
+ "oxfmt": "^0.34.0",
27
+ "oxlint": "^1.49.0",
28
+ "oxlint-tsgolint": "^0.14.2",
29
+ "tsup": "8.5.1",
30
+ "typescript": "5.9.3",
31
+ "vitest": "4.0.18",
32
+ "windows-1252": "3.0.4"
52
33
  },
53
- "private": false,
54
- "esnext": "dist-src/index.js",
55
- "main": "dist-node/index.js",
56
- "module": "dist-web/index.js",
57
- "types": "dist-types/index.d.ts"
58
- }
34
+ "scripts": {
35
+ "build": "tsup src/index.ts --format cjs,esm --dts --out-dir dist",
36
+ "postbuild": "node ./scripts/write-dist-package.js",
37
+ "test": "vitest"
38
+ }
39
+ }
@@ -0,0 +1,2 @@
1
+ onlyBuiltDependencies:
2
+ - esbuild
@@ -0,0 +1,98 @@
1
+ import he from 'he';
2
+ import mappings from '../src/mappings.js';
3
+
4
+ async function fetchText(url: string): Promise<string> {
5
+ const res = await fetch(url);
6
+ if (!res.ok) throw new Error(`Fetch failed: ${res.status}`);
7
+ return res.text();
8
+ }
9
+
10
+ function normalize(s: unknown): string {
11
+ if (s == null) return '';
12
+ // decode HTML entities, normalize NBSP to space, collapse whitespace
13
+ let out = he.decode(String(s));
14
+ out = out.replace(/\u00A0/g, ' ');
15
+ out = out.replace(/\s+/g, ' ').trim();
16
+ return out;
17
+ }
18
+
19
+ function parseChartFromHtml(html: string) {
20
+ const rows: string[][] = [];
21
+ const trRe = /<tr[\s\S]*?<\/tr>/gi;
22
+ const tdRe = /<t[dh][^>]*>([\s\S]*?)<\/(?:t[dh])>/gi;
23
+
24
+ let tr: RegExpExecArray | null;
25
+ while ((tr = trRe.exec(html))) {
26
+ const trHtml = tr[0];
27
+ const cols: string[] = [];
28
+ let td: RegExpExecArray | null;
29
+ tdRe.lastIndex = 0;
30
+ while ((td = tdRe.exec(trHtml))) {
31
+ cols.push(normalize(td[1].replace(/<[^>]+>/g, ' ')));
32
+ }
33
+ if (cols.length) rows.push(cols);
34
+ }
35
+
36
+ // Build map: misrender (column 4) -> expected char (column 3)
37
+ // Build map keyed by Unicode code point (column 1: U+XXXX) -> { expected, mis }
38
+ const map = new Map();
39
+ for (const cols of rows) {
40
+ // defensive: expect at least 4 columns
41
+ if (cols.length >= 4) {
42
+ const code = cols[0]; // e.g. 'U+20AC'
43
+ const expected = cols[2];
44
+ const mis = cols[3];
45
+ if (code) map.set(code.toUpperCase(), { expected, mis });
46
+ }
47
+ }
48
+ return map;
49
+ }
50
+
51
+ async function main() {
52
+ const url = 'https://www.i18nqa.com/debug/utf8-debug.html';
53
+ console.log('Downloading chart from', url);
54
+ const html = await fetchText(url);
55
+
56
+ const chart = parseChartFromHtml(html);
57
+
58
+ const mismatches = [];
59
+
60
+ for (const entry of mappings) {
61
+ // derive Unicode code point from the utf8 char
62
+ const utfChar = entry.utf8.chars;
63
+ const cp = utfChar && utfChar.length ? utfChar.codePointAt(0) : null;
64
+ const cpStr = cp ? 'U+' + cp.toString(16).toUpperCase().padStart(4, '0') : null;
65
+ if (!cpStr || !chart.has(cpStr)) {
66
+ mismatches.push({ mis: entry.misrender.chars, expected: entry.utf8.chars, reason: 'codepoint-not-in-chart' });
67
+ continue;
68
+ }
69
+
70
+ const chartEntry = chart.get(cpStr);
71
+ const chartExpected = normalize(chartEntry.expected);
72
+ const ourExpected = normalize(entry.utf8.chars);
73
+ if (chartExpected !== ourExpected) {
74
+ mismatches.push({
75
+ mis: entry.misrender.chars,
76
+ expected: entry.utf8.chars,
77
+ found: chartExpected,
78
+ reason: 'char-mismatch',
79
+ });
80
+ }
81
+ }
82
+
83
+ if (mismatches.length === 0) {
84
+ console.log('All mappings match the i18nqa chart ✅');
85
+ process.exit(0);
86
+ }
87
+
88
+ console.log('Found mismatches:');
89
+ for (const mm of mismatches) {
90
+ console.log('-', mm);
91
+ }
92
+ process.exit(2);
93
+ }
94
+
95
+ main().catch(err => {
96
+ console.error(err);
97
+ process.exit(1);
98
+ });
@@ -0,0 +1,40 @@
1
+ import { mkdir, readFile, writeFile } from 'fs/promises';
2
+ import { dirname, resolve } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = dirname(__filename);
7
+
8
+ async function main() {
9
+ const rootPkgPath = resolve(__dirname, '..', 'package.json');
10
+ const outDir = resolve(__dirname, '..', 'dist');
11
+ const raw = await readFile(rootPkgPath, 'utf8');
12
+ const pkg = JSON.parse(raw);
13
+
14
+ const distPkg = {
15
+ name: pkg.name,
16
+ version: pkg.version,
17
+ description: pkg.description,
18
+ license: pkg.license,
19
+ author: pkg.author,
20
+ main: './index.cjs',
21
+ module: './index.js',
22
+ types: './index.d.ts',
23
+ files: ['./index.cjs', './index.js', './index.d.ts'],
24
+ exports: {
25
+ '.': {
26
+ import: './index.js',
27
+ require: './index.cjs'
28
+ }
29
+ }
30
+ };
31
+
32
+ await mkdir(outDir, { recursive: true });
33
+ await writeFile(resolve(outDir, 'package.json'), JSON.stringify(distPkg, null, 2) + '\n', 'utf8');
34
+ console.log('Wrote', resolve(outDir, 'package.json'));
35
+ }
36
+
37
+ main().catch((err) => {
38
+ console.error(err);
39
+ process.exitCode = 1;
40
+ });
package/src/index.ts ADDED
@@ -0,0 +1,35 @@
1
+ import * as he from 'he';
2
+ import * as win from 'windows-1252';
3
+
4
+ import mappings from './mappings.js';
5
+
6
+ type Mapping = {
7
+ misrender: { chars: string; hex: string; regex: RegExp };
8
+ utf8: { chars: string; hex: string; regex: RegExp };
9
+ };
10
+
11
+ const err = new Error('utfu requires a string to process');
12
+
13
+ const notStr = (str: unknown): str is string => typeof str !== 'string';
14
+
15
+ function runMap(str: string, m: 'hex' | 'chars', html = false): string {
16
+ if (notStr(str)) throw err;
17
+
18
+ // Re-encode/decode through windows-1252 to normalize mis-encoded bytes
19
+ str = win.decode(win.encode(str));
20
+
21
+ for (const map of mappings as Mapping[]) {
22
+ const replacement = html ? he.encode((map.utf8 as any)[m]) : (map.utf8 as any)[m];
23
+ str = str.replace(map.misrender.regex, replacement);
24
+ }
25
+
26
+ return str;
27
+ }
28
+
29
+ export const hex = (str: string): string => runMap(str, 'hex');
30
+
31
+ export const htx = (str: string): string => runMap(str, 'chars', true);
32
+
33
+ export const txt = (str: string): string => runMap(str, 'chars');
34
+
35
+ export default { hex, htx, txt };