Skip to content

Commit

Permalink
chore: add prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
pret-a-porter committed Nov 15, 2024
1 parent 611600a commit 1477259
Show file tree
Hide file tree
Showing 41 changed files with 330 additions and 285 deletions.
56 changes: 28 additions & 28 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@ name: CI Workflow
on:
push:
branches:
- '*' # Runs on all branches
- '*' # Runs on all branches
pull_request:
branches:
- '*' # Runs on pull requests to any branch
- '*' # Runs on pull requests to any branch

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the code
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Set up Node.js
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'

# Step 3: Install Yarn Berry
- name: Install Yarn Berry
run: yarn set version berry

# Step 4: Install dependencies
- name: Install dependencies
run: yarn install

# Step 5: Run the build script
- name: Build the project
run: yarn run build

# Step 6: Run tests
- name: Run tests
run: yarn run test
# Step 1: Checkout the code
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Set up Node.js
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'

# Step 3: Install Yarn Berry
- name: Install Yarn Berry
run: yarn set version berry

# Step 4: Install dependencies
- name: Install dependencies
run: yarn install

# Step 5: Run the build script
- name: Build the project
run: yarn run build

# Step 6: Run tests
- name: Run tests
run: yarn run test
2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ nodeLinker: node-modules

npmPublishAccess: public

npmPublishRegistry: "https://registry.npmjs.org"
npmPublishRegistry: 'https://registry.npmjs.org'

yarnPath: .yarn/releases/yarn-4.5.1.cjs
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

[![types included](https://badgen.net/npm/types/@eo-locale/core?icon=typescript)](https://www.npmjs.com/package/@eo-locale/core)

* 💪Runs in all browsers and Node.js
* ☎Can be used not only in React.Component but also in Vanilla JS
* 📦Really tiny size. Calculated by [size-limit](https://github.com/ai/size-limit) and [bundlephopia](https://bundlephobia.com/result?p=eo-locale@latest).
* 📚Message format is strictly implemented by [ICU standards](http://userguide.icu-project.org/formatparse/messages)
* 🎓Support for 150+ languages
* 🎉Support HTML in message. Support React Elements as variables
* 🎢Locale data in [nested JSON format](https://github.com/ibitcy/eo-locale/releases/tag/7.4.0) are supported
* 👫Simple. Only four components and one hook
* ⚙️TypeScript types out of the box. Library has written on TypeScript
* 🎄Optimized for [tree shaking](https://webpack.js.org/guides/tree-shaking/)
- 💪Runs in all browsers and Node.js
- ☎Can be used not only in React.Component but also in Vanilla JS
- 📦Really tiny size. Calculated by [size-limit](https://github.com/ai/size-limit) and [bundlephopia](https://bundlephobia.com/result?p=eo-locale@latest).
- 📚Message format is strictly implemented by [ICU standards](http://userguide.icu-project.org/formatparse/messages)
- 🎓Support for 150+ languages
- 🎉Support HTML in message. Support React Elements as variables
- 🎢Locale data in [nested JSON format](https://github.com/ibitcy/eo-locale/releases/tag/7.4.0) are supported
- 👫Simple. Only four components and one hook
- ⚙️TypeScript types out of the box. Library has written on TypeScript
- 🎄Optimized for [tree shaking](https://webpack.js.org/guides/tree-shaking/)

# [Official website](https://eo-locale.netlify.app/)

Expand All @@ -42,14 +42,13 @@ Today each dependency drags more dependencies and increases your project’s bun

To show you the problem that **eo-locale** is trying to solve, we have performed a simple benchmark (using [bundlephobia.com](https://bundlephobia.com)) against popular React localization libraries:

| Name | Bundle size | Bundle size (gzip)|
| ---- | ----------- | ----------------- |
| **eo-locale** | [![](https://badgen.net/bundlephobia/min/@eo-locale/react@latest?color=6ead0a&label=)](https://bundlephobia.com/result?p=@eo-locale/react@latest) | [![](https://badgen.net/bundlephobia/minzip/@eo-locale/react@latest?color=6ead0a&label=)](https://bundlephobia.com/result?p=@eo-locale/react@latest) |
| react-intl | [![](https://badgen.net/bundlephobia/min/react-intl?color=red&label=)](https://bundlephobia.com/result?p=react-intl) | [![](https://badgen.net/bundlephobia/minzip/react-intl?color=red&label=)](https://bundlephobia.com/result?p=react-intl) |
| react-i18next | [![](https://badgen.net/bundlephobia/min/react-i18next?color=red&label=)](https://bundlephobia.com/result?p=react-i18next) | [![](https://badgen.net/bundlephobia/minzip/react-i18next?color=red&label=)](https://bundlephobia.com/result?p=react-i18next) |
| react-intl-universal | [![](https://badgen.net/bundlephobia/min/react-intl-universal?color=red&label=)](https://bundlephobia.com/result?p=react-intl-universal) | [![](https://badgen.net/bundlephobia/minzip/react-intl-universal?color=red&label=)](https://bundlephobia.com/result?p=react-intl-universal) |
| @lingui/react | [![](https://badgen.net/bundlephobia/min/@lingui/react?color=red&label=)](https://bundlephobia.com/result?p=@lingui/react) | [![](https://badgen.net/bundlephobia/minzip/@lingui/react?color=red&label=)](https://bundlephobia.com/result?p=@lingui/react) |

| Name | Bundle size | Bundle size (gzip) |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| **eo-locale** | [![](https://badgen.net/bundlephobia/min/@eo-locale/react@latest?color=6ead0a&label=)](https://bundlephobia.com/result?p=@eo-locale/react@latest) | [![](https://badgen.net/bundlephobia/minzip/@eo-locale/react@latest?color=6ead0a&label=)](https://bundlephobia.com/result?p=@eo-locale/react@latest) |
| react-intl | [![](https://badgen.net/bundlephobia/min/react-intl?color=red&label=)](https://bundlephobia.com/result?p=react-intl) | [![](https://badgen.net/bundlephobia/minzip/react-intl?color=red&label=)](https://bundlephobia.com/result?p=react-intl) |
| react-i18next | [![](https://badgen.net/bundlephobia/min/react-i18next?color=red&label=)](https://bundlephobia.com/result?p=react-i18next) | [![](https://badgen.net/bundlephobia/minzip/react-i18next?color=red&label=)](https://bundlephobia.com/result?p=react-i18next) |
| react-intl-universal | [![](https://badgen.net/bundlephobia/min/react-intl-universal?color=red&label=)](https://bundlephobia.com/result?p=react-intl-universal) | [![](https://badgen.net/bundlephobia/minzip/react-intl-universal?color=red&label=)](https://bundlephobia.com/result?p=react-intl-universal) |
| @lingui/react | [![](https://badgen.net/bundlephobia/min/@lingui/react?color=red&label=)](https://bundlephobia.com/result?p=@lingui/react) | [![](https://badgen.net/bundlephobia/minzip/@lingui/react?color=red&label=)](https://bundlephobia.com/result?p=@lingui/react) |

# Projects using eo-locale

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
],
"scripts": {
"build": "yarn workspaces foreach --all run build",
"prettier:fix": "prettier . --write",
"test": "yarn workspaces foreach --all run test"
},
"devDependencies": {
"@types/jest": "^29.5.14",
"jest": "^29.7.0",
"node-notifier": "^10.0.1",
"prettier": "3.3.3",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"tsup": "^8.3.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/nested_json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const locales: Locale[] = [
page2: {
hello: 'Hello react-intl-universal!',
},
'page.3': 'Hello value with dotted key!'
'page.3': 'Hello value with dotted key!',
},
},
];
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/__tests__/select_other.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ const locales: Locale[] = [
{
language: 'en',
messages: {
hello: '{gender, select, male {hello man} female {hello woman} other {hello}}',
hello:
'{gender, select, male {hello man} female {hello woman} other {hello}}',
minute: '{count, plural,one {min {count}} other {min {count}}}',
},
},
{
language: 'ar',
messages: {
hello: '{gender, select, male {hello man} female {hello woman} other {hello}}',
hello:
'{gender, select, male {hello man} female {hello woman} other {hello}}',
minute: '{count, plural,one {min {count}} other {min {count}}}',
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './models';
export * from './parser';
export * from './translator';
export * from './parser/parser';
3 changes: 3 additions & 0 deletions packages/core/src/models/FormatMessageOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface FormatMessageOptions extends Record<string, any> {
defaultMessage?: string;
}
4 changes: 4 additions & 0 deletions packages/core/src/models/Locale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Locale {
language: string;
messages: object;
}
1 change: 1 addition & 0 deletions packages/core/src/models/Message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Message = string | number;
16 changes: 4 additions & 12 deletions packages/core/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
export type Message = string | number;

export interface Locale {
language: string;
messages: object;
}

export interface FormatMessageOptions extends Record<string, any> {
defaultMessage?: string;
}

export { TranslationError } from './TranslationError';
export * from './FormatMessageOptions';
export * from './Locale';
export * from './Message';
export * from './TranslationError';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { TokenType, Token, TokenStream } from '../token_stream';

describe('Read plural options', () => {
it('Should return plural token', () => {
const stream = new TokenStream('{count, plural, one {One, item} other {{count} ite,ms}}');
const stream = new TokenStream(
'{count, plural, one {One, item} other {{count} ite,ms}}',
);
const options: Record<string, Token[]> = {};

options.one = [
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/parser/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './parser';
18 changes: 10 additions & 8 deletions packages/core/src/parser/input_stream.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
export class InputStream {
public index = 0;
public done = false;
public value = '';
index = 0;
done = false;
value = '';

public constructor(private readonly input: string) {
constructor(private readonly input: string) {
this.value = this.input.charAt(0);
}

public next(): string {
next(): string {
if (++this.index >= this.input.length) {
this.done = true;
}

return this.value = this.input.charAt(this.index);
return (this.value = this.input.charAt(this.index));
}

public croak() {
throw new Error(`[${this.input}]. Unexpected character "${this.value}" on position ${this.index}.`);
croak() {
throw new Error(
`[${this.input}]. Unexpected character "${this.value}" on position ${this.index}.`,
);
}
}
12 changes: 10 additions & 2 deletions packages/core/src/parser/parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { TokenType, Token, TokenStream } from './token_stream';

export function getTranslationParts(language: string, message: string, params: Record<string, any>): any[] {
export function getTranslationParts(
language: string,
message: string,
params: Record<string, any>,
): any[] {
const tokenStream = new TokenStream(message);
let result: any[] = [];

Expand All @@ -23,7 +27,11 @@ export function getTranslationParts(language: string, message: string, params: R
}

try {
result.concat(options[new Intl.PluralRules(language).select(params[value])].map(applyToken));
result.concat(
options[new Intl.PluralRules(language).select(params[value])].map(
applyToken,
),
);
} catch (err) {
result.concat(options['other'].map(applyToken));
}
Expand Down
Loading

0 comments on commit 1477259

Please sign in to comment.