@algorithm.ts/base64 3.1.0 → 4.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/CHANGELOG.md +102 -140
- package/README.md +36 -44
- package/lib/cjs/index.cjs +16 -14
- package/lib/esm/index.mjs +16 -14
- package/lib/types/index.d.ts +3 -3
- package/package.json +4 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,301 +1,263 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
# 3.1.0 (2023-05-13)
|
|
3
|
+
All notable changes to this project will be documented in this file. See
|
|
4
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
7
5
|
|
|
6
|
+
## [3.1.1](https://github.com/guanghechen/algorithm.ts/compare/@algorithm.ts/base64@3.1.0...@algorithm.ts/base64@3.1.1) (2023-06-10)
|
|
8
7
|
|
|
9
8
|
### Performance Improvements
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
- ⬆️ upgrade dependencies
|
|
11
|
+
([c555512](https://github.com/guanghechen/algorithm.ts/commit/c55551269eda0f98e75fca3fb862ce122b1a4889))
|
|
12
|
+
|
|
13
|
+
# 3.1.0 (2023-05-13)
|
|
12
14
|
|
|
15
|
+
### Performance Improvements
|
|
13
16
|
|
|
17
|
+
- ⬆️ upgrade dependencies
|
|
18
|
+
([1ebc2c1](https://github.com/guanghechen/algorithm.ts/commit/1ebc2c167dcc4024d9552aacf5838e1ffc73e58f))
|
|
14
19
|
|
|
15
20
|
# 3.0.0 (2023-04-02)
|
|
16
21
|
|
|
17
|
-
|
|
18
22
|
### Performance Improvements
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
- 🔧 add missing devDependencies
|
|
25
|
+
([69f6da4](https://github.com/guanghechen/algorithm.ts/commit/69f6da43cf1ecebac9f6bf8a7d8ffaced7f9de4c))
|
|
26
|
+
- 🔧 don't pack src/ folder into tarball file
|
|
27
|
+
([2dc61ad](https://github.com/guanghechen/algorithm.ts/commit/2dc61ad8c031cfc1ecf4f63c405d3e23eff1d9c9))
|
|
28
|
+
- 🔖 publish v3.0.0
|
|
29
|
+
([9bb1f35](https://github.com/guanghechen/algorithm.ts/commit/9bb1f3515444890907c8e811b989f17073f39591))
|
|
30
|
+
- ⬆️ upgrade devDependencies
|
|
31
|
+
([e88a181](https://github.com/guanghechen/algorithm.ts/commit/e88a181201ea675715be11d165b0c49c0f9224b8))
|
|
26
32
|
|
|
27
33
|
# 3.0.0-alpha.8 (2023-03-11)
|
|
28
34
|
|
|
29
|
-
|
|
30
35
|
### Performance Improvements
|
|
31
36
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
- 🔖 publish v3.0.0-alpha.8
|
|
38
|
+
([104385f](https://github.com/guanghechen/algorithm.ts/commit/104385f40c0be99b843e3342e85b618761047b69))
|
|
39
|
+
- 🔧 update package entry
|
|
40
|
+
([fd4445a](https://github.com/guanghechen/algorithm.ts/commit/fd4445a0197b21b1d6cc157c543c1f59116c2cc5))
|
|
41
|
+
- ⬆️ upgrade devDependencies
|
|
42
|
+
([4aac0d0](https://github.com/guanghechen/algorithm.ts/commit/4aac0d0267b4050689e95902d081302131417ec5))
|
|
37
43
|
|
|
38
44
|
# 3.0.0-alpha.7 (2023-01-09)
|
|
39
45
|
|
|
40
|
-
|
|
41
46
|
### Performance Improvements
|
|
42
47
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
- 🔖 publish v3.0.0-alpha.7
|
|
49
|
+
([336c4da](https://github.com/guanghechen/algorithm.ts/commit/336c4da3b92a49804c60d0a6dfb783b14712ce0a))
|
|
46
50
|
|
|
47
51
|
# 3.0.0-alpha.6 (2023-01-07)
|
|
48
52
|
|
|
49
|
-
|
|
50
53
|
### Performance Improvements
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
- 🔖 publish v3.0.0-alpha.6
|
|
56
|
+
([1758289](https://github.com/guanghechen/algorithm.ts/commit/1758289e40e4d8786800b21aeed3525a572e89fe))
|
|
57
|
+
- 🔧 set engine node>=16.0.0
|
|
58
|
+
([76e08d7](https://github.com/guanghechen/algorithm.ts/commit/76e08d7a410d437f83a84002c97892204c1fd5ca))
|
|
56
59
|
|
|
57
60
|
# 3.0.0-alpha.5 (2023-01-07)
|
|
58
61
|
|
|
59
|
-
|
|
60
62
|
### Performance Improvements
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
- 🔖 publish v3.0.0-alpha.5
|
|
65
|
+
([6c10d3c](https://github.com/guanghechen/algorithm.ts/commit/6c10d3c77bf342c7284a27e0fe07ce26fbdba05b))
|
|
66
|
+
- 🔧 set engine node>=16.15.1
|
|
67
|
+
([464c990](https://github.com/guanghechen/algorithm.ts/commit/464c99062aeec99258c1a1e475570b549f63addb))
|
|
66
68
|
|
|
67
69
|
# 3.0.0-alpha.4 (2023-01-07)
|
|
68
70
|
|
|
69
|
-
|
|
70
71
|
### Performance Improvements
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
- 🔖 publish v3.0.0-alpha.4
|
|
74
|
+
([969d685](https://github.com/guanghechen/algorithm.ts/commit/969d68502c3c35690ed7aee86dde2fe60cddddfc))
|
|
75
|
+
- 🔧 update npm entries
|
|
76
|
+
([950e3ec](https://github.com/guanghechen/algorithm.ts/commit/950e3ec1d0c9ec3a53de613b9048b3442697404d))
|
|
76
77
|
|
|
77
78
|
# 3.0.0-alpha.3 (2023-01-04)
|
|
78
79
|
|
|
79
|
-
|
|
80
80
|
### Performance Improvements
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
- 🔖 publish v3.0.0-alpha.3
|
|
83
|
+
([d50b472](https://github.com/guanghechen/algorithm.ts/commit/d50b4725bde1b43474f490a29672db5aa1482ae3))
|
|
84
|
+
- 🔧 support dual esm/commonjs packages
|
|
85
|
+
([0f91fbf](https://github.com/guanghechen/algorithm.ts/commit/0f91fbf7c22d7778175ee833afdcf05df5dd34ba))
|
|
86
86
|
|
|
87
87
|
# 3.0.0-alpha.2 (2023-01-02)
|
|
88
88
|
|
|
89
|
-
|
|
90
89
|
### Performance Improvements
|
|
91
90
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
- 🔖 publish v3.0.0-alpha.2
|
|
92
|
+
([3d718fb](https://github.com/guanghechen/algorithm.ts/commit/3d718fba94605e2fd60a3056b502e2e1376ca0ed))
|
|
93
|
+
- ⬆️ upgrade dependencies
|
|
94
|
+
([2672a11](https://github.com/guanghechen/algorithm.ts/commit/2672a119246358d4589ae36bcabd044d395b6136))
|
|
96
95
|
|
|
97
96
|
# 3.0.0-alpha.1 (2022-11-13)
|
|
98
97
|
|
|
99
|
-
|
|
100
98
|
### Performance Improvements
|
|
101
99
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
- 🔖 publish v3.0.0-alpha.1
|
|
101
|
+
([8f9a0d0](https://github.com/guanghechen/algorithm.ts/commit/8f9a0d0dfee15efc08c4165848123b118c13ce81))
|
|
105
102
|
|
|
106
103
|
# 3.0.0-alpha.0 (2022-09-12)
|
|
107
104
|
|
|
108
|
-
|
|
109
105
|
### Features
|
|
110
106
|
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
- ✨ refactor base64
|
|
108
|
+
([1059ed6](https://github.com/guanghechen/algorithm.ts/commit/1059ed64895529d0a5c37b6caa3e22ce854f9ef5))
|
|
113
109
|
|
|
114
110
|
### Performance Improvements
|
|
115
111
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
- 🔖 publish v3.0.0-alpha.0
|
|
113
|
+
([7562a90](https://github.com/guanghechen/algorithm.ts/commit/7562a908843d63b6b1bf92e7aa2104e7b294eaa0))
|
|
119
114
|
|
|
120
115
|
## 2.0.14 (2022-08-27)
|
|
121
116
|
|
|
122
|
-
|
|
123
117
|
### Performance Improvements
|
|
124
118
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
119
|
+
- 🔖 publish v2.0.14
|
|
120
|
+
([53a2462](https://github.com/guanghechen/algorithm.ts/commit/53a24624195c9f09422c9769c552f9066bc22c70))
|
|
121
|
+
- 🔧 update build configs
|
|
122
|
+
([266538b](https://github.com/guanghechen/algorithm.ts/commit/266538bb6736e85c2439b706f11865425b570563))
|
|
123
|
+
- 📝 update repo link
|
|
124
|
+
([f0210ca](https://github.com/guanghechen/algorithm.ts/commit/f0210ca93780ed4109c90d4d337604a6b998b01b))
|
|
130
125
|
|
|
131
126
|
## 2.0.13 (2022-06-26)
|
|
132
127
|
|
|
133
|
-
|
|
134
128
|
### Performance Improvements
|
|
135
129
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
130
|
+
- 🔖 publish v2.0.13
|
|
131
|
+
([ebd6447](https://github.com/guanghechen/algorithm.ts/commit/ebd6447586d9958adaff5218e91768eda82b5bec))
|
|
139
132
|
|
|
140
133
|
## 2.0.12 (2022-06-07)
|
|
141
134
|
|
|
142
|
-
|
|
143
135
|
### Performance Improvements
|
|
144
136
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
137
|
+
- 🔖 publish v2.0.12
|
|
138
|
+
([cfc415a](https://github.com/guanghechen/algorithm.ts/commit/cfc415a6e56d76dcf795421d92dd81ac2a39a5fc))
|
|
148
139
|
|
|
149
140
|
## 2.0.11 (2022-04-19)
|
|
150
141
|
|
|
151
|
-
|
|
152
142
|
### Performance Improvements
|
|
153
143
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
144
|
+
- 🔖 publish v2.0.11
|
|
145
|
+
([42feafd](https://github.com/guanghechen/algorithm.ts/commit/42feafd0303f51767aa7e498f6de84d9478c1dca))
|
|
157
146
|
|
|
158
147
|
## 2.0.10 (2022-04-12)
|
|
159
148
|
|
|
160
|
-
|
|
161
149
|
### Performance Improvements
|
|
162
150
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
151
|
+
- 🔖 publish v2.0.10
|
|
152
|
+
([65694a5](https://github.com/guanghechen/algorithm.ts/commit/65694a5108c220d1edff9be57a12bf8c8403e14d))
|
|
166
153
|
|
|
167
154
|
## 2.0.9 (2022-04-10)
|
|
168
155
|
|
|
169
|
-
|
|
170
156
|
### Performance Improvements
|
|
171
157
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
158
|
+
- 🔖 publish v2.0.9
|
|
159
|
+
([1bdac64](https://github.com/guanghechen/algorithm.ts/commit/1bdac6453d21e3cfeca2e65413e01aa720a34d38))
|
|
175
160
|
|
|
176
161
|
## 2.0.8 (2022-04-10)
|
|
177
162
|
|
|
178
|
-
|
|
179
163
|
### Performance Improvements
|
|
180
164
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
165
|
+
- 🔖 publish v2.0.8
|
|
166
|
+
([7d92191](https://github.com/guanghechen/algorithm.ts/commit/7d921919d03570e772a847763100eb1a58d10d2d))
|
|
184
167
|
|
|
185
168
|
## 2.0.8-alpha.0 (2022-04-05)
|
|
186
169
|
|
|
187
|
-
|
|
188
170
|
### Performance Improvements
|
|
189
171
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
172
|
+
- 🔖 publish v2.0.8-alpha.0
|
|
173
|
+
([24a301c](https://github.com/guanghechen/algorithm.ts/commit/24a301c145ad9f6c0e50494de39456c42bb02f29))
|
|
193
174
|
|
|
194
175
|
## 2.0.7 (2022-04-03)
|
|
195
176
|
|
|
196
|
-
|
|
197
177
|
### Performance Improvements
|
|
198
178
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
179
|
+
- 🔖 publish v2.0.7
|
|
180
|
+
([814bc48](https://github.com/guanghechen/algorithm.ts/commit/814bc48415c5bbea555e0807b8a862cf348df5c1))
|
|
202
181
|
|
|
203
182
|
## 2.0.7-alpha.1 (2022-04-03)
|
|
204
183
|
|
|
205
|
-
|
|
206
184
|
### Performance Improvements
|
|
207
185
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
186
|
+
- 🔖 publish v2.0.7-alpha.1
|
|
187
|
+
([fd487f4](https://github.com/guanghechen/algorithm.ts/commit/fd487f425bd3b8273a414ead8b697010fe1a3a83))
|
|
211
188
|
|
|
212
189
|
## 2.0.7-alpha.0 (2022-03-27)
|
|
213
190
|
|
|
214
|
-
|
|
215
191
|
### Performance Improvements
|
|
216
192
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
193
|
+
- 🔖 publish v2.0.7-alpha.0
|
|
194
|
+
([8a89b2b](https://github.com/guanghechen/algorithm.ts/commit/8a89b2b68855a8eee6b244188792bd294e56045f))
|
|
220
195
|
|
|
221
196
|
## 2.0.6 (2022-03-26)
|
|
222
197
|
|
|
223
|
-
|
|
224
198
|
### Performance Improvements
|
|
225
199
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
200
|
+
- 🔖 publish v2.0.6
|
|
201
|
+
([27a96ca](https://github.com/guanghechen/algorithm.ts/commit/27a96ca7e37b440880b5fd3be8bd1bd08939104e))
|
|
229
202
|
|
|
230
203
|
## 2.0.5 (2022-03-23)
|
|
231
204
|
|
|
232
|
-
|
|
233
205
|
### Performance Improvements
|
|
234
206
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
207
|
+
- 🔖 publish v2.0.5
|
|
208
|
+
([b6f49a9](https://github.com/guanghechen/algorithm.ts/commit/b6f49a92024b9062f89a47277f692069e3abd9ec))
|
|
238
209
|
|
|
239
210
|
## 2.0.4 (2022-03-20)
|
|
240
211
|
|
|
241
|
-
|
|
242
212
|
### Performance Improvements
|
|
243
213
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
214
|
+
- 🔖 publish v2.0.4
|
|
215
|
+
([1f37699](https://github.com/guanghechen/algorithm.ts/commit/1f37699b24bbf498fa820a44056c5f7b291308ee))
|
|
247
216
|
|
|
248
217
|
## 2.0.3 (2022-02-24)
|
|
249
218
|
|
|
250
|
-
|
|
251
219
|
### Performance Improvements
|
|
252
220
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
221
|
+
- 🔖 publish v2.0.3
|
|
222
|
+
([bfd7ee8](https://github.com/guanghechen/algorithm.ts/commit/bfd7ee8420771cc02f7ef53833ba17780192cc88))
|
|
256
223
|
|
|
257
224
|
## 2.0.2 (2022-02-24)
|
|
258
225
|
|
|
259
|
-
|
|
260
226
|
### Performance Improvements
|
|
261
227
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
228
|
+
- 🔖 publish v2.0.2
|
|
229
|
+
([386ea6e](https://github.com/guanghechen/algorithm.ts/commit/386ea6eef0154a42689f03c4943c526a1234db45))
|
|
265
230
|
|
|
266
231
|
## 2.0.1 (2022-02-22)
|
|
267
232
|
|
|
268
|
-
|
|
269
233
|
### Performance Improvements
|
|
270
234
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
235
|
+
- 🔖 publish v2.0.1
|
|
236
|
+
([cac97b1](https://github.com/guanghechen/algorithm.ts/commit/cac97b1cbdc95e0c0914b24ea4e4d25e40bb15c5))
|
|
237
|
+
- 📝 update package descriptions
|
|
238
|
+
([a2455ed](https://github.com/guanghechen/algorithm.ts/commit/a2455edb5dbf5e7662e85e04733b86b8d5e30a5b))
|
|
275
239
|
|
|
276
240
|
# 2.0.0 (2022-02-06)
|
|
277
241
|
|
|
278
|
-
|
|
279
242
|
### Performance Improvements
|
|
280
243
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
244
|
+
- 🔖 publish v2.0.0
|
|
245
|
+
([832e998](https://github.com/guanghechen/algorithm.ts/commit/832e998c72a5e2de64cdca52655e2f0456a17ba2))
|
|
284
246
|
|
|
285
247
|
# 2.0.0-alpha.0 (2022-02-05)
|
|
286
248
|
|
|
287
|
-
|
|
288
249
|
### Performance Improvements
|
|
289
250
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
251
|
+
- 🔖 publish v2.0.0-alpha.0
|
|
252
|
+
([f48a558](https://github.com/guanghechen/algorithm.ts/commit/f48a558ad6decd6c5eee4b9a999ac085c9e19a22))
|
|
293
253
|
|
|
294
254
|
## 1.0.24 (2022-01-22)
|
|
295
255
|
|
|
296
|
-
|
|
297
256
|
### Performance Improvements
|
|
298
257
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
258
|
+
- :sparkles: feat:implement '@algorithm.ts/base64'
|
|
259
|
+
([5aef00b](https://github.com/guanghechen/algorithm.ts/commit/5aef00b59f57e2a15dec110b5af2ab320373d85c))
|
|
260
|
+
- 🔖 publish v1.0.24
|
|
261
|
+
([be5ff5e](https://github.com/guanghechen/algorithm.ts/commit/be5ff5ef055a514bd2f9113b541e9f49ad6008b4))
|
|
262
|
+
- 📝 update READMEs
|
|
263
|
+
([89d28d1](https://github.com/guanghechen/algorithm.ts/commit/89d28d1bbf2b7db1f87dbfde8d079a82925a5847))
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<header>
|
|
2
2
|
<h1 align="center">
|
|
3
|
-
<a href="https://github.com/guanghechen/algorithm.ts/tree/@algorithm.ts/base64@
|
|
3
|
+
<a href="https://github.com/guanghechen/algorithm.ts/tree/@algorithm.ts/base64@4.0.0/packages/base64/#readme">@algorithm.ts/base64</a>
|
|
4
4
|
</h1>
|
|
5
5
|
<div align="center">
|
|
6
6
|
<a href="https://www.npmjs.com/package/@algorithm.ts/base64">
|
|
@@ -49,30 +49,26 @@
|
|
|
49
49
|
</header>
|
|
50
50
|
<br/>
|
|
51
51
|
|
|
52
|
-
|
|
53
52
|
A typescript implementation of the **base64** encoding. Unlike traditional implementations, this
|
|
54
53
|
project uses `Uint8Array` to represent byte streams.
|
|
55
54
|
|
|
56
|
-
|
|
57
55
|
## Install
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
- npm
|
|
60
58
|
|
|
61
59
|
```bash
|
|
62
60
|
npm install --save @algorithm.ts/base64
|
|
63
61
|
```
|
|
64
62
|
|
|
65
|
-
|
|
63
|
+
- yarn
|
|
66
64
|
|
|
67
65
|
```bash
|
|
68
66
|
yarn add @algorithm.ts/base64
|
|
69
67
|
```
|
|
70
68
|
|
|
71
|
-
|
|
72
69
|
## Usage
|
|
73
70
|
|
|
74
|
-
|
|
75
|
-
* `encode`: Encode a Uint8Array into base64 encoded string.
|
|
71
|
+
- `encode`: Encode a Uint8Array into base64 encoded string.
|
|
76
72
|
|
|
77
73
|
```typescript
|
|
78
74
|
// node env: import { TextEncoder } from 'util'
|
|
@@ -87,23 +83,23 @@ project uses `Uint8Array` to represent byte streams.
|
|
|
87
83
|
encode(getBytes('Hello, world!')) // => 'SGVsbG8sIHdvcmxkIQ=='
|
|
88
84
|
```
|
|
89
85
|
|
|
90
|
-
|
|
86
|
+
- `decode`: Decode a base64 encoded string to Uint8Array
|
|
91
87
|
|
|
92
88
|
```typescript
|
|
93
89
|
import { decode } from '@algorithm.ts/base64'
|
|
94
90
|
|
|
95
|
-
const data: Uint8Array = decode('SGVsbG8sIHdvcmxkIQ==')
|
|
91
|
+
const data: Uint8Array = decode('SGVsbG8sIHdvcmxkIQ==')
|
|
96
92
|
const textDecoder = new TextDecoder()
|
|
97
93
|
textDecoder.decode(data) // => 'Hello, world!'
|
|
98
94
|
```
|
|
99
95
|
|
|
100
|
-
|
|
96
|
+
- `validate`: Check if a string is base64 encoded.
|
|
101
97
|
|
|
102
98
|
```typescript
|
|
103
99
|
validate('SGVsbG8sIHdvcmxkIQ==') // => true
|
|
104
100
|
```
|
|
105
101
|
|
|
106
|
-
|
|
102
|
+
- Custom code map.
|
|
107
103
|
|
|
108
104
|
```typescript
|
|
109
105
|
// node env: import { TextEncoder } from 'util'
|
|
@@ -121,37 +117,33 @@ project uses `Uint8Array` to represent byte streams.
|
|
|
121
117
|
base64.encode(getBytes('Hello, world!')) // => RFUraF7rHGcublwjHP==
|
|
122
118
|
```
|
|
123
119
|
|
|
124
|
-
|
|
125
120
|
## Related
|
|
126
121
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
Index | Binary
|
|
130
|
-
|
|
131
|
-
0
|
|
132
|
-
1
|
|
133
|
-
2
|
|
134
|
-
3
|
|
135
|
-
4
|
|
136
|
-
5
|
|
137
|
-
6
|
|
138
|
-
7
|
|
139
|
-
8
|
|
140
|
-
9
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
[homepage]: https://github.com/guanghechen/algorithm.ts/tree/@algorithm.ts/base64@3.1.0/packages/base64#readme
|
|
122
|
+
- BASE64 Table
|
|
123
|
+
|
|
124
|
+
| Index | Binary | Char | Index | Binary | Char | Index | Binary | Char | Index | Binary | Char |
|
|
125
|
+
| :---: | :----: | :--: | :---: | :----: | :--: | :---: | :----: | :--: | :---: | :----: | :--- |
|
|
126
|
+
| 0 | 000000 | A | 16 | 010000 | Q | 32 | 100000 | g | 48 | 110000 | w |
|
|
127
|
+
| 1 | 000001 | B | 17 | 010001 | R | 33 | 100001 | h | 49 | 110001 | x |
|
|
128
|
+
| 2 | 000010 | C | 18 | 010010 | S | 34 | 100010 | i | 50 | 110010 | y |
|
|
129
|
+
| 3 | 000011 | D | 19 | 010011 | T | 35 | 100011 | j | 51 | 110011 | z |
|
|
130
|
+
| 4 | 000100 | E | 20 | 010100 | U | 36 | 100100 | k | 52 | 110100 | 0 |
|
|
131
|
+
| 5 | 000101 | F | 21 | 010101 | V | 37 | 100101 | l | 53 | 110101 | 1 |
|
|
132
|
+
| 6 | 000110 | G | 22 | 010110 | W | 38 | 100110 | m | 54 | 110110 | 2 |
|
|
133
|
+
| 7 | 000111 | H | 23 | 010111 | X | 39 | 100111 | n | 55 | 110111 | 3 |
|
|
134
|
+
| 8 | 001000 | I | 24 | 011000 | Y | 40 | 101000 | o | 56 | 111000 | 4 |
|
|
135
|
+
| 9 | 001001 | J | 25 | 011001 | Z | 41 | 101001 | p | 57 | 111001 | 5 |
|
|
136
|
+
| 10 | 001010 | K | 26 | 011010 | a | 42 | 101010 | q | 58 | 111010 | 6 |
|
|
137
|
+
| 11 | 001011 | L | 27 | 011011 | b | 43 | 101011 | r | 59 | 111011 | 7 |
|
|
138
|
+
| 12 | 001100 | M | 28 | 011100 | c | 44 | 101100 | s | 60 | 111100 | 8 |
|
|
139
|
+
| 13 | 001101 | N | 29 | 011101 | d | 45 | 101101 | t | 61 | 111101 | 9 |
|
|
140
|
+
| 14 | 001110 | O | 30 | 011110 | e | 46 | 101110 | u | 62 | 111110 | + |
|
|
141
|
+
| 15 | 001111 | P | 31 | 011111 | f | 47 | 101111 | v | 63 | 111111 | / |
|
|
142
|
+
|
|
143
|
+
- [Base64 | Wikipedia](https://en.wikipedia.org/wiki/Base64)
|
|
144
|
+
- [base-64 | github](https://github.com/mathiasbynens/base64)
|
|
145
|
+
- [`atob()` | MDN](https://developer.mozilla.org/en-US/docs/Web/API/atob)
|
|
146
|
+
- [`btoa()` | MDN](https://developer.mozilla.org/en-US/docs/Web/API/btoa)
|
|
147
|
+
|
|
148
|
+
[homepage]:
|
|
149
|
+
https://github.com/guanghechen/algorithm.ts/tree/@algorithm.ts/base64@4.0.0/packages/base64#readme
|
package/lib/cjs/index.cjs
CHANGED
|
@@ -2,23 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const SANITIZE_REGEX = /([*^$\\])/g;
|
|
6
|
+
const DEFAULT_CODES = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
7
|
+
const DEFAULT_CODE_PADDING = '=';
|
|
6
8
|
class Base64 {
|
|
7
9
|
CODE_LIST;
|
|
8
10
|
CODE_REFLECT;
|
|
9
11
|
CODE_PADDING;
|
|
10
12
|
VALIDATE_REGEX;
|
|
11
13
|
constructor(props = {}) {
|
|
12
|
-
const CODES = props.CODES?.length === 64
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.
|
|
14
|
+
const CODES = props.CODES?.length === 64 ? props.CODES : DEFAULT_CODES;
|
|
15
|
+
const CODE_PADDING = props.CODE_PADDING?.length === 1 ? props.CODE_PADDING : DEFAULT_CODE_PADDING;
|
|
16
|
+
const CODE_LIST = CODES.split('');
|
|
17
|
+
const CODE_REFLECT = { [CODE_PADDING]: 0 };
|
|
18
|
+
for (const [idx, v] of CODE_LIST.entries())
|
|
19
|
+
CODE_REFLECT[v] = idx;
|
|
20
|
+
const VALIDATE_REGEX = new RegExp(`^[${CODES.replace(SANITIZE_REGEX, '\\$1')}]+${CODE_PADDING.replace(SANITIZE_REGEX, '\\$1')}{0,2}$`);
|
|
21
|
+
this.CODE_LIST = CODE_LIST;
|
|
22
|
+
this.CODE_REFLECT = CODE_REFLECT;
|
|
21
23
|
this.CODE_PADDING = CODE_PADDING;
|
|
24
|
+
this.VALIDATE_REGEX = VALIDATE_REGEX;
|
|
22
25
|
}
|
|
23
26
|
encode(data) {
|
|
24
27
|
let result = '';
|
|
@@ -41,19 +44,17 @@ class Base64 {
|
|
|
41
44
|
return result;
|
|
42
45
|
}
|
|
43
46
|
decode(text) {
|
|
44
|
-
if (text.length <= 0 || !this.validate(text))
|
|
47
|
+
if (text.length <= 0 || !this.validate(text))
|
|
45
48
|
throw new TypeError('Invalid base64 string.');
|
|
46
|
-
}
|
|
47
49
|
let countOfPadding = 0;
|
|
48
50
|
const { CODE_PADDING } = this;
|
|
49
51
|
for (let i = text.length - 1; i >= 0 && text[i] === CODE_PADDING; --i)
|
|
50
52
|
countOfPadding += 1;
|
|
51
53
|
const _size = (text.length >> 2) * 3 - countOfPadding;
|
|
52
54
|
const result = new Uint8Array(_size);
|
|
53
|
-
const _end = ((text.length - countOfPadding) >> 2) << 2;
|
|
54
55
|
let i = 0;
|
|
55
56
|
let j = 0;
|
|
56
|
-
for (; i < _end; i += 4, j += 3) {
|
|
57
|
+
for (const _end = ((text.length - countOfPadding) >> 2) << 2; i < _end; i += 4, j += 3) {
|
|
57
58
|
const v = this._decodeUint(text, i);
|
|
58
59
|
result[j] = v >> 16;
|
|
59
60
|
result[j + 1] = (v >> 8) & 0xff;
|
|
@@ -108,3 +109,4 @@ exports.decode = decode;
|
|
|
108
109
|
exports.default = index;
|
|
109
110
|
exports.encode = encode;
|
|
110
111
|
exports.validate = validate;
|
|
112
|
+
//# sourceMappingURL=index.cjs.map
|
package/lib/esm/index.mjs
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
const
|
|
1
|
+
const SANITIZE_REGEX = /([*^$\\])/g;
|
|
2
|
+
const DEFAULT_CODES = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
3
|
+
const DEFAULT_CODE_PADDING = '=';
|
|
2
4
|
class Base64 {
|
|
3
5
|
CODE_LIST;
|
|
4
6
|
CODE_REFLECT;
|
|
5
7
|
CODE_PADDING;
|
|
6
8
|
VALIDATE_REGEX;
|
|
7
9
|
constructor(props = {}) {
|
|
8
|
-
const CODES = props.CODES?.length === 64
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.
|
|
10
|
+
const CODES = props.CODES?.length === 64 ? props.CODES : DEFAULT_CODES;
|
|
11
|
+
const CODE_PADDING = props.CODE_PADDING?.length === 1 ? props.CODE_PADDING : DEFAULT_CODE_PADDING;
|
|
12
|
+
const CODE_LIST = CODES.split('');
|
|
13
|
+
const CODE_REFLECT = { [CODE_PADDING]: 0 };
|
|
14
|
+
for (const [idx, v] of CODE_LIST.entries())
|
|
15
|
+
CODE_REFLECT[v] = idx;
|
|
16
|
+
const VALIDATE_REGEX = new RegExp(`^[${CODES.replace(SANITIZE_REGEX, '\\$1')}]+${CODE_PADDING.replace(SANITIZE_REGEX, '\\$1')}{0,2}$`);
|
|
17
|
+
this.CODE_LIST = CODE_LIST;
|
|
18
|
+
this.CODE_REFLECT = CODE_REFLECT;
|
|
17
19
|
this.CODE_PADDING = CODE_PADDING;
|
|
20
|
+
this.VALIDATE_REGEX = VALIDATE_REGEX;
|
|
18
21
|
}
|
|
19
22
|
encode(data) {
|
|
20
23
|
let result = '';
|
|
@@ -37,19 +40,17 @@ class Base64 {
|
|
|
37
40
|
return result;
|
|
38
41
|
}
|
|
39
42
|
decode(text) {
|
|
40
|
-
if (text.length <= 0 || !this.validate(text))
|
|
43
|
+
if (text.length <= 0 || !this.validate(text))
|
|
41
44
|
throw new TypeError('Invalid base64 string.');
|
|
42
|
-
}
|
|
43
45
|
let countOfPadding = 0;
|
|
44
46
|
const { CODE_PADDING } = this;
|
|
45
47
|
for (let i = text.length - 1; i >= 0 && text[i] === CODE_PADDING; --i)
|
|
46
48
|
countOfPadding += 1;
|
|
47
49
|
const _size = (text.length >> 2) * 3 - countOfPadding;
|
|
48
50
|
const result = new Uint8Array(_size);
|
|
49
|
-
const _end = ((text.length - countOfPadding) >> 2) << 2;
|
|
50
51
|
let i = 0;
|
|
51
52
|
let j = 0;
|
|
52
|
-
for (; i < _end; i += 4, j += 3) {
|
|
53
|
+
for (const _end = ((text.length - countOfPadding) >> 2) << 2; i < _end; i += 4, j += 3) {
|
|
53
54
|
const v = this._decodeUint(text, i);
|
|
54
55
|
result[j] = v >> 16;
|
|
55
56
|
result[j + 1] = (v >> 8) & 0xff;
|
|
@@ -100,3 +101,4 @@ const validate = base64.validate.bind(base64);
|
|
|
100
101
|
var index = { encode, decode, validate };
|
|
101
102
|
|
|
102
103
|
export { Base64, decode, index as default, encode, validate };
|
|
104
|
+
//# sourceMappingURL=index.mjs.map
|
package/lib/types/index.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ interface IBase64Props {
|
|
|
2
2
|
/**
|
|
3
3
|
* @default 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
|
4
4
|
*/
|
|
5
|
-
CODES?: string;
|
|
5
|
+
readonly CODES?: string;
|
|
6
6
|
/**
|
|
7
7
|
* @default '=''
|
|
8
8
|
*/
|
|
9
|
-
CODE_PADDING?: string;
|
|
9
|
+
readonly CODE_PADDING?: string;
|
|
10
10
|
}
|
|
11
11
|
declare class Base64 {
|
|
12
12
|
protected readonly CODE_LIST: string[];
|
|
@@ -30,4 +30,4 @@ declare const _default: {
|
|
|
30
30
|
validate: (text: string) => boolean;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
export { Base64, IBase64Props, decode, _default as default, encode, validate };
|
|
33
|
+
export { Base64, type IBase64Props, decode, _default as default, encode, validate };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algorithm.ts/base64",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "A Base64 encoding implementation.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "guanghechen",
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/guanghechen/algorithm.ts/tree/
|
|
11
|
+
"url": "https://github.com/guanghechen/algorithm.ts/tree/@algorithm.ts/base64@4.0.0-alpha.0",
|
|
12
12
|
"directory": "packages/base64"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://github.com/guanghechen/algorithm.ts/tree/
|
|
14
|
+
"homepage": "https://github.com/guanghechen/algorithm.ts/tree/@algorithm.ts/base64@4.0.0-alpha.0/packages/base64#readme",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"algorithm",
|
|
17
17
|
"base64"
|
|
@@ -27,9 +27,6 @@
|
|
|
27
27
|
"main": "./lib/cjs/index.cjs",
|
|
28
28
|
"module": "./lib/esm/index.mjs",
|
|
29
29
|
"license": "MIT",
|
|
30
|
-
"engines": {
|
|
31
|
-
"node": ">= 16.0.0"
|
|
32
|
-
},
|
|
33
30
|
"files": [
|
|
34
31
|
"lib/",
|
|
35
32
|
"!lib/**/*.map",
|
|
@@ -38,16 +35,5 @@
|
|
|
38
35
|
"LICENSE",
|
|
39
36
|
"README.md"
|
|
40
37
|
],
|
|
41
|
-
"
|
|
42
|
-
"build": "rimraf lib/ && cross-env NODE_ENV=production rollup -c ../../rollup.config.mjs",
|
|
43
|
-
"prepublishOnly": "yarn build",
|
|
44
|
-
"test": "cross-env TS_NODE_FILES=true NODE_OPTIONS=--experimental-vm-modules jest --config ../../jest.config.mjs --rootDir ."
|
|
45
|
-
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"cross-env": "^7.0.3",
|
|
48
|
-
"jest": "^29.5.0",
|
|
49
|
-
"rimraf": "^5.0.0",
|
|
50
|
-
"rollup": "^3.21.6"
|
|
51
|
-
},
|
|
52
|
-
"gitHead": "c2d4f73cd5143f56c334bf9736df5d61b0e5dec9"
|
|
38
|
+
"gitHead": "6a88f4a7ccb2ea5416185b562482255d752c4528"
|
|
53
39
|
}
|