@atproto/lex-data 0.1.2 → 0.1.4

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.
Files changed (72) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/blob.d.ts +2 -2
  3. package/dist/blob.d.ts.map +1 -1
  4. package/dist/blob.js +1 -1
  5. package/dist/blob.js.map +1 -1
  6. package/dist/lex-equals.d.ts +1 -1
  7. package/dist/lex-equals.d.ts.map +1 -1
  8. package/dist/lex-equals.js.map +1 -1
  9. package/dist/lex.d.ts +1 -1
  10. package/dist/lex.d.ts.map +1 -1
  11. package/dist/lex.js.map +1 -1
  12. package/dist/lib/nodejs-buffer.js.map +1 -1
  13. package/dist/uint8array-from-base64.d.ts +1 -1
  14. package/dist/uint8array-from-base64.d.ts.map +1 -1
  15. package/dist/uint8array-from-base64.js.map +1 -1
  16. package/dist/uint8array-to-base64.d.ts +1 -1
  17. package/dist/uint8array-to-base64.d.ts.map +1 -1
  18. package/dist/uint8array-to-base64.js.map +1 -1
  19. package/dist/uint8array.d.ts +1 -1
  20. package/dist/uint8array.d.ts.map +1 -1
  21. package/dist/uint8array.js.map +1 -1
  22. package/dist/utf8-from-base64.d.ts +1 -1
  23. package/dist/utf8-from-base64.d.ts.map +1 -1
  24. package/dist/utf8-from-base64.js.map +1 -1
  25. package/dist/utf8-to-base64.d.ts +1 -1
  26. package/dist/utf8-to-base64.d.ts.map +1 -1
  27. package/dist/utf8-to-base64.js.map +1 -1
  28. package/dist/utf8.d.ts +1 -1
  29. package/dist/utf8.d.ts.map +1 -1
  30. package/dist/utf8.js.map +1 -1
  31. package/package.json +4 -8
  32. package/src/blob.test.ts +0 -405
  33. package/src/blob.ts +0 -478
  34. package/src/cid-implementation.test.ts +0 -129
  35. package/src/cid.test.ts +0 -350
  36. package/src/cid.ts +0 -603
  37. package/src/core-js.d.ts +0 -2
  38. package/src/index.ts +0 -8
  39. package/src/lex-equals.test.ts +0 -183
  40. package/src/lex-equals.ts +0 -123
  41. package/src/lex-error.test.ts +0 -54
  42. package/src/lex-error.ts +0 -83
  43. package/src/lex.test.ts +0 -279
  44. package/src/lex.ts +0 -253
  45. package/src/lib/nodejs-buffer.ts +0 -46
  46. package/src/lib/util.test.ts +0 -49
  47. package/src/lib/util.ts +0 -7
  48. package/src/object.test.ts +0 -80
  49. package/src/object.ts +0 -83
  50. package/src/uint8array-base64.ts +0 -2
  51. package/src/uint8array-concat.test.ts +0 -197
  52. package/src/uint8array-concat.ts +0 -25
  53. package/src/uint8array-from-base64.test.ts +0 -130
  54. package/src/uint8array-from-base64.ts +0 -98
  55. package/src/uint8array-to-base64.test.ts +0 -170
  56. package/src/uint8array-to-base64.ts +0 -55
  57. package/src/uint8array.test.ts +0 -503
  58. package/src/uint8array.ts +0 -197
  59. package/src/utf8-from-base64.test.ts +0 -39
  60. package/src/utf8-from-base64.ts +0 -23
  61. package/src/utf8-from-bytes.test.ts +0 -43
  62. package/src/utf8-from-bytes.ts +0 -21
  63. package/src/utf8-grapheme-len.test.ts +0 -38
  64. package/src/utf8-grapheme-len.ts +0 -21
  65. package/src/utf8-len.test.ts +0 -21
  66. package/src/utf8-len.ts +0 -51
  67. package/src/utf8-to-base64.test.ts +0 -35
  68. package/src/utf8-to-base64.ts +0 -22
  69. package/src/utf8.ts +0 -128
  70. package/tsconfig.build.json +0 -12
  71. package/tsconfig.json +0 -7
  72. package/tsconfig.tests.json +0 -8
@@ -1,170 +0,0 @@
1
- import 'core-js/es/typed-array/from-base64.js'
2
- import 'core-js/es/typed-array/to-base64.js'
3
- import { assert, describe, expect, it } from 'vitest'
4
- import {
5
- toBase64Native,
6
- toBase64Node,
7
- toBase64Ponyfill,
8
- } from './uint8array-to-base64.js'
9
-
10
- for (const toBase64 of [
11
- toBase64Native,
12
- toBase64Node,
13
- toBase64Ponyfill,
14
- ] as const) {
15
- // Tests should run in NodeJS where implementations are either available or
16
- // polyfilled (see core-js imports above).
17
- assert(toBase64, 'toBase64 implementation should not be null')
18
-
19
- describe(toBase64, () => {
20
- describe('basic encoding', () => {
21
- it('encodes empty Uint8Array', () => {
22
- const encoded = toBase64(new Uint8Array(0))
23
- expect(typeof encoded).toBe('string')
24
- expect(encoded).toBe('')
25
- })
26
-
27
- it('encodes 10MB', () => {
28
- const bytes = Buffer.allocUnsafe(10_000_000).fill('🐩')
29
- const encoded = toBase64(bytes)
30
- expect(typeof encoded).toBe('string')
31
- // Verify by decoding back
32
- const decoded = Buffer.from(encoded, 'base64')
33
- expect(decoded.equals(bytes)).toBe(true)
34
- })
35
- })
36
-
37
- describe('base64 alphabet (default)', () => {
38
- for (const string of [
39
- '',
40
- '\0\0',
41
- '\0\0\0',
42
- '\0\0\0\0',
43
- '__',
44
- 'é',
45
- 'àç',
46
- '\0éàç',
47
- '```\x1b',
48
- 'aaa',
49
- 'Hello, World!',
50
- '😀😃😄😁😆😅😂🤣😊😇',
51
- '👩‍💻👨‍💻👩‍🔬👨‍🔬👩‍🚀👨‍🚀',
52
- '🌍🌎🌏🌐🪐🌟✨⚡🔥💧',
53
- ] as const) {
54
- const buffer = Buffer.from(string, 'utf8')
55
- const expected = buffer.toString('base64').replace(/=+$/, '')
56
-
57
- it(`encodes ${JSON.stringify(string)} as ${JSON.stringify(expected)}`, () => {
58
- const encoded = toBase64(buffer)
59
- expect(encoded).toBe(expected)
60
- })
61
- }
62
- })
63
-
64
- describe('base64url alphabet', () => {
65
- for (const string of [
66
- '',
67
- '\0\0',
68
- '\0\0\0',
69
- '\0\0\0\0',
70
- '__',
71
- 'é',
72
- 'àç',
73
- '\0éàç',
74
- '```\x1b',
75
- 'aaa',
76
- 'Hello, World!',
77
- '😀😃😄😁😆😅😂🤣😊😇',
78
- '👩‍💻👨‍💻👩‍🔬👨‍🔬👩‍🚀👨‍🚀',
79
- '🌍🌎🌏🌐🪐🌟✨⚡🔥💧',
80
- ] as const) {
81
- const buffer = Buffer.from(string, 'utf8')
82
- const expected = buffer.toString('base64url')
83
-
84
- it(`encodes ${JSON.stringify(string)} as ${JSON.stringify(expected)}`, () => {
85
- const encoded = toBase64(buffer, 'base64url')
86
- expect(encoded).toBe(expected)
87
- })
88
- }
89
- })
90
-
91
- describe('base64 vs base64url character differences', () => {
92
- // Test data that produces + and / in standard base64
93
- // These should become - and _ in base64url
94
- it('uses + and / for base64 alphabet', () => {
95
- // 0xfb, 0xff, 0xbf produces "+/+/" in base64
96
- const bytes = new Uint8Array([0xfb, 0xff, 0xbf])
97
- const encoded = toBase64(bytes)
98
- expect(encoded).toContain('+')
99
- expect(encoded).toContain('/')
100
- expect(encoded).not.toContain('-')
101
- expect(encoded).not.toContain('_')
102
- })
103
-
104
- it('uses - and _ for base64url alphabet', () => {
105
- // Same bytes should use - and _ in base64url
106
- const bytes = new Uint8Array([0xfb, 0xff, 0xbf])
107
- const encoded = toBase64(bytes, 'base64url')
108
- expect(encoded).toContain('-')
109
- expect(encoded).toContain('_')
110
- expect(encoded).not.toContain('+')
111
- expect(encoded).not.toContain('/')
112
- })
113
- })
114
-
115
- describe('padding behavior', () => {
116
- it('omits padding by default for 1-byte input', () => {
117
- // 1 byte -> 2 base64 chars + 2 padding
118
- const bytes = new Uint8Array([0x4d]) // 'M' -> 'TQ=='
119
- const encoded = toBase64(bytes)
120
- expect(encoded).toBe('TQ')
121
- expect(encoded).not.toContain('=')
122
- })
123
-
124
- it('omits padding by default for 2-byte input', () => {
125
- // 2 bytes -> 3 base64 chars + 1 padding
126
- const bytes = new Uint8Array([0x4d, 0x61]) // 'Ma' -> 'TWE='
127
- const encoded = toBase64(bytes)
128
- expect(encoded).toBe('TWE')
129
- expect(encoded).not.toContain('=')
130
- })
131
-
132
- it('no padding needed for 3-byte input', () => {
133
- // 3 bytes -> 4 base64 chars, no padding needed
134
- const bytes = new Uint8Array([0x4d, 0x61, 0x6e]) // 'Man' -> 'TWFu'
135
- const encoded = toBase64(bytes)
136
- expect(encoded).toBe('TWFu')
137
- })
138
-
139
- it('includes double padding when omitPadding: false for 1-byte input', () => {
140
- const bytes = new Uint8Array([0x4d]) // 'M' -> 'TQ=='
141
- const encoded = toBase64(bytes)
142
- expect(encoded).toBe('TQ')
143
- })
144
-
145
- it('includes single padding when omitPadding: false for 2-byte input', () => {
146
- const bytes = new Uint8Array([0x4d, 0x61]) // 'Ma' -> 'TWE='
147
- const encoded = toBase64(bytes)
148
- expect(encoded).toBe('TWE')
149
- })
150
- })
151
-
152
- describe('Uint8Array subarray handling', () => {
153
- it('correctly encodes a subarray', () => {
154
- const fullArray = new Uint8Array([0x00, 0x4d, 0x61, 0x6e, 0x00])
155
- const subarray = fullArray.subarray(1, 4) // 'Man'
156
- const encoded = toBase64(subarray)
157
- expect(encoded).toBe('TWFu')
158
- })
159
-
160
- it('correctly encodes a subarray with offset', () => {
161
- const buffer = new ArrayBuffer(10)
162
- const fullView = new Uint8Array(buffer)
163
- fullView.set([0x00, 0x00, 0x4d, 0x61, 0x6e, 0x00, 0x00])
164
- const subarray = new Uint8Array(buffer, 2, 3) // 'Man' at offset 2
165
- const encoded = toBase64(subarray)
166
- expect(encoded).toBe('TWFu')
167
- })
168
- })
169
- })
170
- }
@@ -1,55 +0,0 @@
1
- import { toString } from 'uint8arrays/to-string'
2
- import { NodeJSBuffer } from './lib/nodejs-buffer.js'
3
- import { Base64Alphabet } from './uint8array-base64.js'
4
-
5
- const Buffer = NodeJSBuffer
6
-
7
- declare global {
8
- interface Uint8Array {
9
- /**
10
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64 Uint8Array.prototype.toBase64()}
11
- */
12
- toBase64?: (options?: {
13
- /** @default 'base64' */
14
- alphabet?: 'base64' | 'base64url'
15
- omitPadding?: boolean
16
- }) => string
17
- }
18
- }
19
-
20
- export const toBase64Native =
21
- typeof Uint8Array.prototype.toBase64 === 'function'
22
- ? function toBase64Native(
23
- bytes: Uint8Array,
24
- alphabet: Base64Alphabet = 'base64',
25
- ): string {
26
- return bytes.toBase64!({ alphabet, omitPadding: true })
27
- }
28
- : /* v8 ignore next -- @preserve */ null
29
-
30
- export const toBase64Node = Buffer
31
- ? function toBase64Node(
32
- bytes: Uint8Array,
33
- alphabet: Base64Alphabet = 'base64',
34
- ): string {
35
- const buffer = bytes instanceof Buffer ? bytes : Buffer.from(bytes)
36
- const b64 = buffer.toString(alphabet)
37
-
38
- // @NOTE We strip padding for strict compatibility with
39
- // uint8arrays.toString behavior. Tests failing because of the presence of
40
- // padding are not really synonymous with an actual error and we might
41
- // (should?) actually want to keep the padding at some point.
42
- return b64.charCodeAt(b64.length - 1) === /* '=' */ 0x3d
43
- ? b64.charCodeAt(b64.length - 2) === /* '=' */ 0x3d
44
- ? b64.slice(0, -2) // '=='
45
- : b64.slice(0, -1) // '='
46
- : b64
47
- }
48
- : /* v8 ignore next -- @preserve */ null
49
-
50
- export function toBase64Ponyfill(
51
- bytes: Uint8Array,
52
- alphabet: Base64Alphabet = 'base64',
53
- ): string {
54
- return toString(bytes, alphabet)
55
- }