Skip to content

Commit

Permalink
refactor OnScreenKeyboard (#14)
Browse files Browse the repository at this point in the history
## [0.3.0]  2024-01-17
### Added
- return array of letters of a script
  • Loading branch information
amerharb authored Jan 17, 2024
1 parent 9ca8a0d commit 2dd2bef
Show file tree
Hide file tree
Showing 51 changed files with 872 additions and 726 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ module.exports = {
plugins: [
'@typescript-eslint',
],
extends: [
'plugin:@next/next/recommended',
],
ignorePatterns: '*.js',
overrides: [
{
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-next.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
always-auth: true
cache: yarn

- run: yarn workspace $PACKAGE_NAME install --frozen-lockfile
- run: yarn workspace $PACKAGE_NAME install --immutable

- name: publish abjad-convert @next to npm
if: ${{ env.PACKAGE_NAME == 'abjad-convert' }}
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ This is a monorepo for the Abjad Convert project.

### Abjad Client
example of a client for the abjad convert package

### Abjad Web
[README](https://github.com/amerharb/abjad/blob/main/packages/abjad-web/README.md)
2 changes: 2 additions & 0 deletions packages/abjad-convert/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!-- https://keepachangelog.com/en/1.0.0/ -->

## [0.3.0] 2024-01-17
### Added
- return array of letters of a script

## [0.2.1] 2024-01-13
### Fixed
Expand Down
118 changes: 118 additions & 0 deletions packages/abjad-convert/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Abjad-convert Contributing

## Adding new script
Pull requests are welcome. For adding new script. let's say that we want to add a new script "Foo"
- Step #1: create a feature branch from `main` named `abjad-convert/version/0.[x].0` where `x` is the next minor of current version number.
- Step #2: create a new branch that will the previous feature branch when creating the PR.
- Step #3: create a new folder named `foo` in `src`.
- Step #4: add pdf documentation for the script we want to add from www.unicode.org. for example for Ugaritic the file is `U10380.pdf`. this file will be used as a reference
- Step #5: add a new file named `letters.ts` in `foo` folder this file will export
- - `letters` an array of letters written using unicode values with jsdoc each line will contain
the value of the letter using UTF-16 BE using escape \u followed by 4 hex digits.
notice that UTF16BE value is not always the same as the unicode value.
for example for letter Alpa in Ugaritic the unicode value is `0x10380` but the UTF16BE encode value is `0xD800DF80`
follow the value with jsdoc that contain array index, letter itself, unicode value, and the name of the letter.
for example for ugaritic looks like this:

```ts
const letters = [
'\uD800\uDF80', /** #0 𐎀 U+10380 UGARITIC LETTER ALPA */
'\uD800\uDF81', /** #1 𐎁 U+10381 UGARITIC LETTER BETA */
//...
];
```

- - 'Fo' an alias object called `Fo` short of Foo. this will give an alias for all letters mentioned in the letters array.

for example for ugaritic looks like this:
```ts
const Ug = {
Alpa: letters[0], // 𐎀
Beta: letters[1], // 𐎁
//...
};
```

- - `foo` an instance of `Script` class, which will be exported

for example for ugaritic looks like this:
```ts
export const ugaritic = new Script(
Abjad.Ugaritic, // enum value of the script
false, // true if the script is right to left
letters, // array of letters
Ug, // alias object of letters
)
```

- Step #6: Add the script to the enum `Abjad` in `src/types.ts` file.
at this point we have finished adding the script, but it is an island script. Meaning that it can't be converted to or from any other script.

- Step #7: To make it convertable we need at least to have one from and one to converter to another script.
the preferred way is to add a converter to and from Arabic script, as it is currently act as a de facto hub script for all abjad scripts.
The algorithm for converting will look first for 1-step converter (direct converter) the one that convert from the source to the target, in case there isn't any it will look for 2-steps approach where it can find a middle script,
after that it won't look for 3 or more steps, it will basically throw an error.
That is why Arabic is used as preferred hub, so if all script add converter to Arabic and Arabic add converter to all other scripts then all conversion is possible.
However, there is a plan in the future to add IPA to be a canonical hub script.

- - Adding to Arabic: Add file to `foo` folder with name `toArabic.ts` that include a class called FooToArabicConverter that implements `IConverter` interface.
it should look like this:
```ts
import { IConverter } from '../../types';
import { Fo } from './letters'
import { Ar } from '../arabic/letters'
import { IConverter } from '../../IConverter'
import { Abjad } from '../../types'

export class FooToArabicConverter implements IConverter {
public readonly from = Abjad.Foo
public readonly to = Abjad.Arabic
public convert(fooText: string): string {
// convert logic here
// return (araic text)
}
}
```
- - Add toArabic converter to `converterFactory.ts`
- - - import the new converter in alphabetical order
```ts
//...
import { FooToArabicConverter } from './foo/toArabic'
//...
```
- - - add the converter to converters array in alphabetical order
```ts
const converters: IConverter[] = [
//...
new TifinaghToArabicConverter(),
//...
];
```
- - Add toFoo converter to `arabic` folder with name `toFoo.ts` that include a class called ArabicToFooConverter that implements `IConverter` interface.
it should look like this:
```ts
import {Ar} from './letters'
import {Fo} from '../foo/letters'
import {IConverter} from '../../IConverter'
import {Abjad} from '../../types'

export class ArabicToFooConverter implements IConverter {
public readonly from = Abjad.Arabic
public readonly to = Abjad.Foo
public convert(arabicText: string): string {
// convert logic here
// return (foo text)
}
}
```
- - Add toFoo converter to `converterFactory.ts`

- Step #8 add unit test to`test/index.test.ts`.

- Step #9: update for new version
- - update `CHANGELOG.md` with the new version number and the changes.
- Step #10 update
- - `README.md` links and badges.
- - version in `package.json` file.
- - run yarn to update `yarn.lock` files
- - run test to update coverage badges
111 changes: 4 additions & 107 deletions packages/abjad-convert/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Abjad Convert
[![Version](https://img.shields.io/badge/version-0.2.1-blue.svg)](https://github.com/amerharb/abjad/tree/version/0.2.1)
[![Version](https://img.shields.io/badge/version-0.3.0-blue.svg)](https://github.com/amerharb/abjad/tree/version/0.3.0)
[![License: GPLv3](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
![Coverage](https://raw.githubusercontent.com/amerharb/abjad/abjad-convert/version/0.2.1/packages/abjad-convert/badges/coverage.svg)
![Github workflow](https://github.com/amerharb/abjad/actions/workflows/lint-test.yaml/badge.svg?branch=abjad-convert/version/0.2.1)
![Coverage](https://raw.githubusercontent.com/amerharb/abjad/abjad-convert/version/0.3.0/packages/abjad-convert/badges/coverage.svg)
![Github workflow](https://github.com/amerharb/abjad/actions/workflows/lint-test.yaml/badge.svg?branch=abjad-convert/version/0.3.0)

**abjad-convert** is a package for converting Abjad alphabets phonetically.

Expand All @@ -24,7 +24,7 @@ yarn:
yarn add abjad-convert
```

Java Script:
Type Script:
```js
import { convert, Abjad } from 'abjad-convert';

Expand All @@ -45,106 +45,3 @@ console.log(tifinaghWord); // ⵎⵔⵃⴱⴰ
const ugariticWord = convert(arabicWord, Abjad.Arabic, Abjad.Ugaritic);
console.log(ugariticWord); // 𐎎𐎗𐎈𐎁𐎀
```
## Contributing
### Adding new script
Pull requests are welcome. For adding new script. let's say that we want to add a new script "Foo"
- Step #1: create a feature branch from `main` named `abjad-convert/version/0.[x].0` where `x` is the next minor of current version number.
- Step #2: create a new branch that will the previous feature branch when creating the PR.
- Step #3: create a new folder named `foo` in `src`.
- Step #4: add pdf documentation for the script we want to add from www.unicode.org. for example for Ugaritic the file is `U10380.pdf`. this file will be used as a reference
- Step #5: add a new file named `letters.ts` in `foo` folder this file will export
- - `letters` an array of letters written using unicode values with jsdoc each line will contain
the value of the letter using UTF-16 BE using escape \u followed by 4 hex digits.
notice that UTF16BE value is not always the same as the unicode value.
for example for letter Alpa in Ugaritic the unicode value is `0x10380` but the UTF16BE encode value is `0xD800DF80`
follow the value with jsdoc that contain array index, letter itself, unicode value, and the name of the letter.
for example for ugaritic looks like this:

```ts
export const letters = [
'\uD800\uDF80', /** #0 𐎀 U+10380 UGARITIC LETTER ALPA */
'\uD800\uDF81', /** #1 𐎁 U+10381 UGARITIC LETTER BETA */
//...
];
```
- - 'Fo' an alias object called `Fo` short of Foo. this will give an alias for all letters mentioned in the letters array.

for example for ugaritic looks like this:
```ts
export const Ug = {
Alpa: letters[0], // 𐎀
Beta: letters[1], // 𐎁
//...
};
```

- Step #6: Add the script to the enum `Abjad` in `src/types.ts` file.
at this point we have finished adding the script, but it is an island script. Meaning that it can't be converted to or from any other script.

- Step #7: To make it convertable we need at least to have one from and one to converter to another script.
the preferred way is to add a converter to and from Arabic script, as it is currently act as a de facto hub script for all abjad scripts.
The algorithm for converting will look first for 1-step converter (direct converter) the one that convert from the source to the target, in case there isn't any it will look for 2-steps approach where it can find a middle script,
after that it won't look for 3 or more steps, it will basically throw an error.
That is why Arabic is used as preferred hub, so if all script add converter to Arabic and Arabic add converter to all other scripts then all conversion is possible.
However, there is a plan in the future to add IPA to be a canonical hub script.

- - Adding to Arabic: Add file to `foo` folder with name `toArabic.ts` that include a class called FooToArabicConverter that implements `IConverter` interface.
it should look like this:
```ts
import { IConverter } from '../types';
import { Fo } from './letters'
import { Ar } from '../arabic/letters'
import { IConverter } from '../IConverter'
import { Abjad } from '../types'

export class FooToArabicConverter implements IConverter {
public readonly from = Abjad.Foo
public readonly to = Abjad.Arabic
public convert(fooText: string): string {
// convert logic here
// return (araic text)
}
}
```
- - Add toArabic converter to `converterFactory.ts`
- - - import the new converter in alphabetical order
```ts
//...
import { FooToArabicConverter } from './foo/toArabic'
//...
```
- - - add the converter to converters array in alphabetical order
```ts
const converters: IConverter[] = [
//...
new TifinaghToArabicConverter(),
//...
];
```
- - Add toFoo converter to `arabic` folder with name `toFoo.ts` that include a class called ArabicToFooConverter that implements `IConverter` interface.
it should look like this:
```ts
import {Ar} from './letters'
import {Fo} from '../foo/letters'
import {IConverter} from '../IConverter'
import {Abjad} from '../types'

export class ArabicToFooConverter implements IConverter {
public readonly from = Abjad.Arabic
public readonly to = Abjad.Foo
public convert(arabicText: string): string {
// convert logic here
// return (foo text)
}
}
```
- - Add toFoo converter to `converterFactory.ts`

- Step #8 add unit test to`test/index.test.ts`.

- Step #9: update for new version
- - update `CHANGELOG.md` with the new version number and the changes.
- - Step #10 update `README.md` links and badges.
- - Update version in `package.json` file.
- - run yarn to update yarn.lock files
- - run test to update coverage badges
2 changes: 1 addition & 1 deletion packages/abjad-convert/badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/abjad-convert/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "abjad-convert",
"version": "0.3.0",
"version": "0.3.0-next.1",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"files": [
Expand Down
59 changes: 0 additions & 59 deletions packages/abjad-convert/src/arabic/toImperialAramaic.ts

This file was deleted.

Loading

0 comments on commit 2dd2bef

Please sign in to comment.