Skip to content

Commit c4792e1

Browse files
authored
fix: text encoder / decoder exports
- feat: expose TextDecoder from text-decoder - fix: export TextEncoder from text-encoder - chore: add test for text encoder/decoder
1 parent c6337a9 commit c4792e1

File tree

7 files changed

+41
-3
lines changed

7 files changed

+41
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"browser": {
1515
"fs-extra": false,
1616
"./src/text-encoder.js": "./src/text-encoder.browser.js",
17+
"./src/text-decoder.js": "./src/text-decoder.browser.js",
1718
"./src/temp-dir.js": "./src/temp-dir.browser.js",
1819
"./src/path-join.js": "./src/path-join.browser.js"
1920
},

src/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const fetch = require('node-fetch')
55
const merge = require('merge-options').bind({ ignoreUndefined: true })
66
const { URL, URLSearchParams } = require('iso-url')
7-
const TextDecoder = require('./text-encoder')
7+
const TextDecoder = require('./text-decoder')
88
const AbortController = require('abort-controller')
99
const anySignal = require('any-signal')
1010

src/text-decoder.browser.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
module.exports = require('./globalthis').TextDecoder

src/text-decoder.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
'use strict'
2+
module.exports = require('util').TextDecoder

src/text-encoder.browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
'use strict'
22

3-
module.exports = require('./globalthis').TextDecoder
3+
module.exports = require('./globalthis').TextEncoder

src/text-encoder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
'use strict'
2-
module.exports = require('util').TextDecoder
2+
module.exports = require('util').TextEncoder

test/text-codec.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict'
2+
3+
/* eslint-env mocha */
4+
const { expect } = require('aegir/utils/chai')
5+
const TextEncoder = require('../src/text-encoder')
6+
const TextDecoder = require('../src/text-decoder')
7+
8+
describe('text encode/decode', () => {
9+
const data = Uint8Array.from([
10+
104,
11+
101,
12+
108,
13+
108,
14+
111,
15+
32,
16+
119,
17+
111,
18+
114,
19+
108,
20+
100
21+
])
22+
23+
it('can encode text', () => {
24+
const bytes = new TextEncoder().encode('hello world')
25+
expect(bytes).to.be.deep.equal(data)
26+
})
27+
28+
it('can decode text', () => {
29+
const text = new TextDecoder().decode(data)
30+
expect(text).to.be.equal('hello world')
31+
})
32+
})

0 commit comments

Comments
 (0)