Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
run: npm run test:es --if-present
- name: Test CommonJS
run: npm run test:cjs --if-present
- name: Test React Native
run: npm run test:react-native --if-present
validate-types:
name: Check type use
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
This package provides [TextEncoder][] and [TextDecoder][] [Encoding Standard][]
APIs in a universal package. In the browsers it just exposes existing globals,
in nodejs it exposes globals in newer node versions and ones from `util` module
in older versions.
in older versions, and in the React Native environments it exposes these from
the [@zxing/text-encoding](https://www.npmjs.com/package/@zxing/text-encoding)
polyfill (installed as an optional dependency).

Package also works as ES module and CommonJS module.

Expand Down
27 changes: 24 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
],
"type": "module",
"browser": "./src/lib.browser.js",
"react-native": "./src/lib.react-native.js",
"main": "./src/lib.cjs",
"module": "./src/lib.js",
"types": "./src/lib.d.ts",
Expand All @@ -21,19 +22,39 @@
"scripts": {
"test:node": "mocha test/test-*.spec.cjs",
"test:browser": "playwright-test test/test-*.cjs",
"test:es": "mocha test/test-*.spec.js",
"test:react-native": "jest test/test-lib.react-native.spec.js",
"test:es": "mocha test/test-lib.spec.js",
"test:cjs": "npm run test:node && npm run test:browser",
"test:types:ts": "npm test --prefix test/ts-use",
"test:types:esm": "npm test --prefix test/esm-use",
"test:types:cjs": "npm test --prefix test/cjs-use",
"test:types": "npm run test:types:ts && npm run test:types:esm && npm run test:types:cjs",
"test": "npm run test:es && npm run test:cjs && npm run test:types"
"test": "npm run test:es && npm run test:cjs && npm run test:react-native && npm run test:types"
},
"license": "MIT",
"author": "Irakli Gozalishvili <[email protected]>",
"homepage": "https://github.com/gozala/web-encoding",
"devDependencies": {
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.64.0",
"mocha": "8.2.1",
"playwright-test": "1.2.0"
"playwright-test": "1.2.0",
"react-native": "^0.63.4"
},
"optionalDependencies": {
"@zxing/text-encoding": "0.9.0"
},
"jest": {
"preset": "react-native",
"transform": {
"\\.js$": [
"babel-jest",
{
"presets": [
"module:metro-react-native-babel-preset"
]
}
]
}
}
}
5 changes: 5 additions & 0 deletions src/lib.react-native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict"

const textEncoding = require("@zxing/text-encoding")
exports.TextEncoder = textEncoding.TextEncoder
exports.TextDecoder = textEncoding.TextDecoder
28 changes: 28 additions & 0 deletions test/test-lib.react-native.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { TextEncoder, TextDecoder } from "../src/lib.react-native.js"
import assert from "assert"

describe("text encode/decode", () => {
const data = Uint8Array.from([
104,
101,
108,
108,
111,
32,
119,
111,
114,
108,
100,
])

it("can encode text", () => {
const bytes = new TextEncoder().encode("hello world")
assert.deepStrictEqual(bytes, data)
})

it("can decode text", () => {
const text = new TextDecoder().decode(data)
assert.equal(text, "hello world")
})
})
Loading