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: 0 additions & 2 deletions .eslintrc.js

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Check

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run lint
run: npm run lint

- name: Run tests
run: npm run test

- name: Build
run: npm run build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,5 @@ dist

/build

/.expo
.claude/
.idea/
47 changes: 38 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
# @bacons/text-decoder
# @ably/text-decoder

> This is now in Expo SDK 52 https://docs.expo.dev/versions/v52.0.0/sdk/encoding/
A lightweight TextDecoder polyfill for React Native Hermes that only supports UTF-8.

In Expo SDK 51 (React Native 74), Hermes supports TextEncoder natively but not TextDecoder. This library provides a TextDecoder implementation for Hermes that only supports UTF-8 (all legacy encodings are removed for bundle size).
The implementation is a fork of [`text-encoding`](https://github.com/EvanBacon/text-decoder) without dependencies, built as a standalone library with both CommonJS and ES module support.

You can install it on the global with:
## Installation

```js
import "@bacons/text-decoder/install";
```bash
npm install @ably/text-decoder
```

Supports web, ios, android, server, and the upcoming Expo React Server environment for native platforms.
## Usage

The implementation is a fork of [`text-encoding`](https://github.com/inexorabletash/text-encoding/blob/3f330964c0e97e1ed344c2a3e963f4598610a7ad/lib/encoding.js#L1) with all legacy encodings, and TextEncoder removed.
```javascript
// ESM
import { TextDecoder } from '@ably/text-decoder';

The tests were ported over too to ensure everything works as described.
// CommonJS
const { TextDecoder } = require('@ably/text-decoder');

// Use the polyfill
const decoder = new TextDecoder('utf-8');
const text = decoder.decode(new Uint8Array([72, 101, 108, 108, 111])); // "Hello"
```

## Features

- ✅ Lightweight UTF-8 TextDecoder implementation
- ✅ Supports both CommonJS and ES modules
- ✅ Zero dependencies
- ✅ TypeScript type definitions included
- ✅ Tested with Vitest

## Development

```bash
# Install dependencies
npm install

# Run tests
npm test

# Build the library
npm run build
```
2 changes: 0 additions & 2 deletions babel.config.js

This file was deleted.

56 changes: 56 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import eslint from '@eslint/js';
import tseslint from '@typescript-eslint/eslint-plugin';
import tsparser from '@typescript-eslint/parser';

export default [
eslint.configs.recommended,
{
files: ['src/**/*.ts', 'src/**/*.tsx'],
ignores: ['**/__tests__/**', '**/*.test.ts', '**/*.spec.ts'],
languageOptions: {
parser: tsparser,
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
},
plugins: {
'@typescript-eslint': tseslint,
},
rules: {
...tseslint.configs.recommended.rules,
},
},
{
files: ['**/__tests__/**/*.ts', '**/*.test.ts', '**/*.spec.ts'],
languageOptions: {
parser: tsparser,
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
globals: {
describe: 'readonly',
it: 'readonly',
expect: 'readonly',
beforeEach: 'readonly',
afterEach: 'readonly',
beforeAll: 'readonly',
afterAll: 'readonly',
vi: 'readonly',
TextEncoder: 'readonly',
TextDecoder: 'readonly',
},
},
plugins: {
'@typescript-eslint': tseslint,
},
rules: {
...tseslint.configs.recommended.rules,
'@typescript-eslint/ban-ts-comment': 'off',
},
},
{
ignores: ['build/', 'node_modules/', '*.config.js'],
},
];
1 change: 0 additions & 1 deletion install.js

This file was deleted.

Loading