utfu 0.3.1 → 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/src/types.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export interface Mapping {
2
+ misrender: { chars: string; hex: string; regex: RegExp }
3
+ utf8: { chars: string; hex: string; regex: RegExp }
4
+ }
@@ -0,0 +1,21 @@
1
+ import { execSync } from 'child_process';
2
+ import { readFile } from 'fs/promises';
3
+ import { resolve } from 'path';
4
+ import { describe, it, expect } from 'vitest';
5
+
6
+ describe('dist/package.json postbuild', () => {
7
+ it('generates a minimal package.json with correct fields', async () => {
8
+ // Run the build so the postbuild script generates dist/package.json
9
+ execSync('npm run build --silent', { stdio: 'inherit' });
10
+
11
+ const pkgPath = resolve(process.cwd(), 'dist', 'package.json');
12
+ const raw = await readFile(pkgPath, 'utf8');
13
+ const pkg = JSON.parse(raw);
14
+
15
+ expect(pkg).toHaveProperty('main', './index.cjs');
16
+ expect(pkg).toHaveProperty('module', './index.js');
17
+ expect(pkg).toHaveProperty('types', './index.d.ts');
18
+ expect(pkg).toHaveProperty('exports');
19
+ expect(pkg.exports['.']).toEqual({ import: './index.js', require: './index.cjs' });
20
+ });
21
+ });
@@ -0,0 +1,26 @@
1
+ import { describe, test, expect } from 'vitest'
2
+ import { hex, htx, txt } from '../src/index'
3
+
4
+ describe('edge cases', () => {
5
+ test('functions throw when input is not a string', () => {
6
+ const badValues: any[] = [null, undefined, 123, {}, []]
7
+
8
+ for (const v of badValues) {
9
+ expect(() => (hex as any)(v)).toThrow('utfu requires a string to process')
10
+ expect(() => (htx as any)(v)).toThrow('utfu requires a string to process')
11
+ expect(() => (txt as any)(v)).toThrow('utfu requires a string to process')
12
+ }
13
+ })
14
+
15
+ test('ASCII-only strings are unchanged', () => {
16
+ const s = 'Hello, world! 12345'
17
+ expect(hex(s)).toBe(s)
18
+ expect(htx(s)).toBe(s)
19
+ expect(txt(s)).toBe(s)
20
+ })
21
+
22
+ test('multiple occurrences are all replaced', () => {
23
+ const s = '’ ’ ’'
24
+ expect(txt(s)).toBe('’ ’ ’')
25
+ })
26
+ })