@atproto/lex-data 0.0.5 → 0.0.7
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/CHANGELOG.md +20 -0
- package/dist/blob.d.ts +39 -5
- package/dist/blob.d.ts.map +1 -1
- package/dist/blob.js +45 -16
- package/dist/blob.js.map +1 -1
- package/dist/cid.d.ts +83 -14
- package/dist/cid.d.ts.map +1 -1
- package/dist/cid.js +94 -35
- package/dist/cid.js.map +1 -1
- package/dist/lex-equals.js +1 -1
- package/dist/lex-equals.js.map +1 -1
- package/dist/uint8array-from-base64.d.ts.map +1 -1
- package/dist/uint8array-from-base64.js +1 -1
- package/dist/uint8array-from-base64.js.map +1 -1
- package/dist/uint8array-to-base64.d.ts.map +1 -1
- package/dist/uint8array-to-base64.js +2 -2
- package/dist/uint8array-to-base64.js.map +1 -1
- package/dist/utf8-from-base64.d.ts +4 -0
- package/dist/utf8-from-base64.d.ts.map +1 -0
- package/dist/utf8-from-base64.js +18 -0
- package/dist/utf8-from-base64.js.map +1 -0
- package/dist/utf8-to-base64.d.ts +4 -0
- package/dist/utf8-to-base64.d.ts.map +1 -0
- package/dist/utf8-to-base64.js +20 -0
- package/dist/utf8-to-base64.js.map +1 -0
- package/dist/utf8.d.ts +3 -0
- package/dist/utf8.d.ts.map +1 -1
- package/dist/utf8.js +16 -3
- package/dist/utf8.js.map +1 -1
- package/package.json +1 -1
- package/src/blob.test.ts +150 -25
- package/src/blob.ts +111 -27
- package/src/cid.test.ts +50 -33
- package/src/cid.ts +200 -35
- package/src/lex-equals.ts +2 -2
- package/src/uint8array-from-base64.ts +1 -1
- package/src/uint8array-to-base64.test.ts +2 -2
- package/src/uint8array-to-base64.ts +2 -2
- package/src/utf8-from-base64.test.ts +39 -0
- package/src/utf8-from-base64.ts +23 -0
- package/src/utf8-grapheme-len.test.ts +2 -2
- package/src/utf8-len.test.ts +2 -2
- package/src/utf8-to-base64.test.ts +35 -0
- package/src/utf8-to-base64.ts +22 -0
- package/src/utf8.ts +23 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
import { graphemeLenNative, graphemeLenPonyfill } from './utf8-grapheme-len.js'
|
|
3
3
|
|
|
4
|
-
describe(
|
|
4
|
+
describe(graphemeLenNative!, () => {
|
|
5
5
|
it('computes grapheme length', () => {
|
|
6
6
|
expect(graphemeLenNative!('a')).toBe(1)
|
|
7
7
|
expect(graphemeLenNative!('~')).toBe(1)
|
|
@@ -19,7 +19,7 @@ describe('graphemeLenSegmenter', () => {
|
|
|
19
19
|
})
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
describe(
|
|
22
|
+
describe(graphemeLenPonyfill, () => {
|
|
23
23
|
it('computes grapheme length', () => {
|
|
24
24
|
expect(graphemeLenPonyfill('a')).toBe(1)
|
|
25
25
|
expect(graphemeLenPonyfill('~')).toBe(1)
|
package/src/utf8-len.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
import { utf8LenCompute, utf8LenNode } from './utf8-len.js'
|
|
3
3
|
|
|
4
|
-
describe(
|
|
4
|
+
describe(utf8LenNode!, () => {
|
|
5
5
|
it('computes utf8 string length', () => {
|
|
6
6
|
expect(utf8LenNode!('a')).toBe(1)
|
|
7
7
|
expect(utf8LenNode!('~')).toBe(1)
|
|
@@ -16,7 +16,7 @@ describe('utf8LenNode', () => {
|
|
|
16
16
|
})
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
-
describe(
|
|
19
|
+
describe(utf8LenCompute, () => {
|
|
20
20
|
it('computes utf8 string length', () => {
|
|
21
21
|
expect(utf8LenCompute('a')).toBe(1)
|
|
22
22
|
expect(utf8LenCompute('~')).toBe(1)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { assert, describe, expect, it } from 'vitest'
|
|
2
|
+
import { utf8ToBase64Node, utf8ToBase64Ponyfill } from './utf8-to-base64.js'
|
|
3
|
+
|
|
4
|
+
const strings = [
|
|
5
|
+
'Hello, World!',
|
|
6
|
+
'¡Hola, Mundo!',
|
|
7
|
+
'こんにちは世界',
|
|
8
|
+
'😀👩💻🌍',
|
|
9
|
+
'',
|
|
10
|
+
'𓀀𓁐𓂀𓃰𓄿𓅱𓆑𓇋𓈖𓉔𓊃𓋴𓌳𓍿𓎛𓏏',
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
for (const utf8ToBase64 of [utf8ToBase64Node, utf8ToBase64Ponyfill] as const) {
|
|
14
|
+
assert(utf8ToBase64, 'implementation should not be null')
|
|
15
|
+
|
|
16
|
+
describe(utf8ToBase64, () => {
|
|
17
|
+
it('encodes utf8 string to base64', () => {
|
|
18
|
+
for (const text of strings) {
|
|
19
|
+
const b64 = Buffer.from(text, 'utf8')
|
|
20
|
+
.toString('base64')
|
|
21
|
+
.replaceAll('=', '') // utf8ToBase64 omits padding
|
|
22
|
+
const encoded = utf8ToBase64(text, 'base64')
|
|
23
|
+
expect(encoded).toBe(b64)
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('encodes utf8 string to base64url', () => {
|
|
28
|
+
for (const text of strings) {
|
|
29
|
+
const b64u = Buffer.from(text, 'utf8').toString('base64url')
|
|
30
|
+
const encoded = utf8ToBase64(text, 'base64url')
|
|
31
|
+
expect(encoded).toBe(b64u)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { toString } from 'uint8arrays/to-string'
|
|
2
|
+
import { NodeJSBuffer } from './lib/nodejs-buffer.js'
|
|
3
|
+
import { Base64Alphabet } from './uint8array-base64.js'
|
|
4
|
+
import { toBase64Node } from './uint8array-to-base64.js'
|
|
5
|
+
|
|
6
|
+
const Buffer = NodeJSBuffer
|
|
7
|
+
|
|
8
|
+
export const utf8ToBase64Node = Buffer
|
|
9
|
+
? function utf8ToBase64Node(text: string, alphabet?: Base64Alphabet): string {
|
|
10
|
+
const buffer = Buffer.from(text, 'utf8')
|
|
11
|
+
return toBase64Node!(buffer, alphabet)
|
|
12
|
+
}
|
|
13
|
+
: /* v8 ignore next -- @preserve */ null
|
|
14
|
+
|
|
15
|
+
const textEncoder = /*#__PURE__*/ new TextEncoder()
|
|
16
|
+
export function utf8ToBase64Ponyfill(
|
|
17
|
+
text: string,
|
|
18
|
+
alphabet?: Base64Alphabet,
|
|
19
|
+
): string {
|
|
20
|
+
const bytes = textEncoder.encode(text)
|
|
21
|
+
return toString(bytes, alphabet)
|
|
22
|
+
}
|
package/src/utf8.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
import { Base64Alphabet } from './uint8array.js'
|
|
2
|
+
import {
|
|
3
|
+
utf8FromBase64Node,
|
|
4
|
+
utf8FromBase64Ponyfill,
|
|
5
|
+
} from './utf8-from-base64.js'
|
|
1
6
|
import { graphemeLenNative, graphemeLenPonyfill } from './utf8-grapheme-len.js'
|
|
2
7
|
import { utf8LenCompute, utf8LenNode } from './utf8-len.js'
|
|
8
|
+
import { utf8ToBase64Node, utf8ToBase64Ponyfill } from './utf8-to-base64.js'
|
|
3
9
|
|
|
4
10
|
export const graphemeLen: (str: string) => number =
|
|
5
|
-
graphemeLenNative ??
|
|
11
|
+
/* v8 ignore next -- @preserve */ graphemeLenNative ??
|
|
12
|
+
/* v8 ignore next -- @preserve */ graphemeLenPonyfill
|
|
6
13
|
|
|
14
|
+
/* v8 ignore next -- @preserve */
|
|
7
15
|
if (graphemeLen === graphemeLenPonyfill) {
|
|
8
16
|
/*#__PURE__*/
|
|
9
17
|
console.warn(
|
|
@@ -11,4 +19,17 @@ if (graphemeLen === graphemeLenPonyfill) {
|
|
|
11
19
|
)
|
|
12
20
|
}
|
|
13
21
|
|
|
14
|
-
export const utf8Len: (string: string) => number =
|
|
22
|
+
export const utf8Len: (string: string) => number =
|
|
23
|
+
/* v8 ignore next -- @preserve */ utf8LenNode ??
|
|
24
|
+
/* v8 ignore next -- @preserve */ utf8LenCompute
|
|
25
|
+
|
|
26
|
+
export const utf8ToBase64: (str: string, alphabet?: Base64Alphabet) => string =
|
|
27
|
+
/* v8 ignore next -- @preserve */ utf8ToBase64Node ??
|
|
28
|
+
/* v8 ignore next -- @preserve */ utf8ToBase64Ponyfill
|
|
29
|
+
|
|
30
|
+
export const utf8FromBase64: (
|
|
31
|
+
b64: string,
|
|
32
|
+
alphabet?: Base64Alphabet,
|
|
33
|
+
) => string =
|
|
34
|
+
/* v8 ignore next -- @preserve */ utf8FromBase64Node ??
|
|
35
|
+
/* v8 ignore next -- @preserve */ utf8FromBase64Ponyfill
|