Skip to content

Commit

Permalink
Aegean/version/0.0.1 (#14)
Browse files Browse the repository at this point in the history
* add aegean numerals
  • Loading branch information
amerharb authored May 2, 2024
1 parent 075142c commit 7c40627
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/publish-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
PACKAGE_NAME="hieroglyphic"
elif [[ $TAG_NAME =~ ^roman\/v.* ]]; then
PACKAGE_NAME="roman"
elif [[ $TAG_NAME =~ ^aegean\/v.* ]]; then
PACKAGE_NAME="aegean"
else
echo "❌ tag name: $TAG_NAME doesn't point to any publishable package"
exit 1
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish-next.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
PACKAGE_NAME="hieroglyphic"
elif [[ $TAG_NAME =~ ^roman\/v.* ]]; then
PACKAGE_NAME="roman"
elif [[ $TAG_NAME =~ ^aegean\/v.* ]]; then
PACKAGE_NAME="aegean"
else
echo "❌ tag name: $TAG_NAME doesn't point to any publishable package"
exit 1
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
"packages/mayan",
"packages/hieroglyphic",
"packages/roman",
"packages/aegean",
"packages/numerals-client",
"packages/numerals-web"
],
"version": "0.4.0",
"version": "0.5.0",
"author": "Amer Harb",
"license": "ISC",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions packages/aegean/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Aegean Changelog
<!-- https://keepachangelog.com/en/1.0.0/ -->

## [0.0.1] 2024-05-02
### Added
- Initial project covert number into aegean numerals
12 changes: 12 additions & 0 deletions packages/aegean/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ISC License

Copyright 2024 Amer Harb numerals@amerharb.com

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,
provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30 changes: 30 additions & 0 deletions packages/aegean/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# @numerals/aegean

[![Version](https://img.shields.io/badge/version-0.0.1-blue.svg)](https://github.com/amerharb/numerals/tree/aegean/version/0.0.1)
[![License: GPLv3](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
![Coverage](https://raw.githubusercontent.com/amerharb/numerals/aegean/version/0.0.1/packages/aegean/badges/coverage.svg)
![Github workflow](https://github.com/amerharb/numerals/actions/workflows/lint-test.yaml/badge.svg?branch=aegean/version/0.0.1)

**@numerals/aegean** is a package for converting number into aegean numeral.

`1000 -> 𐄢`

## How to use
npm:
```shell
npm i @numerals/aegean
```

yarn:
```shell
yarn add @numerals/aegean
```

Type Script:
```ts
import { convert } from '@numerals/aegean';
console.log(convert(1)); // 𐄇
console.log(convert(2)); // 𐄈
console.log(convert(10)); // 𐄐
console.log(convert(1000)); // 𐄢
```
1 change: 1 addition & 0 deletions packages/aegean/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.
Binary file added packages/aegean/doc/U10100.pdf
Binary file not shown.
14 changes: 14 additions & 0 deletions packages/aegean/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverage: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
testMatch: [
'**/?(*.)+(test.ts)',
],
coverageReporters: [
'json-summary',
],
};
38 changes: 38 additions & 0 deletions packages/aegean/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@numerals/aegean",
"version": "0.0.1",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"files": [
"dist/src/**/*.d.ts",
"dist/src/**/*.js",
"LICENSE",
"CHANGELOG.md",
"README.md"
],
"author": "Amer Harb",
"repository": {
"type": "git",
"url": "git+https://github.com/amerharb/numerals.git"
},
"homepage": "https://github.com/amerharb/numerals#readme",
"url": "https://github.com/amerharb/numerals/issues",
"email": "numerals@amerharb.com",
"keywords": [
"aegean-numerals",
"aegean-numbers"
],
"license": "ISC",
"scripts": {
"build": "rm -rf dist && tsc",
"start": "node dist/src/index.js",
"test": "jest",
"make-coverage-badge": "npx make-coverage-badge --report-path coverage/coverage-summary.json --output-path badges/coverage.svg",
"dev": "ts-node src/index.ts",
"lint": "npx eslint . --max-warnings 0",
"lint:fix": "npx eslint . --fix"
},
"bugs": {
"url": "https://github.com/amerharb/numerals/issues"
}
}
38 changes: 38 additions & 0 deletions packages/aegean/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Ag } from './numerals'

export function convert(source: number): string {
if (!Number.isFinite(source)) {
throw new Error('Source is not a finite number')
}
if (source < 0) {
throw new Error('Source is negative, only positive numbers are supported')
}
if (source == 0) {
throw new Error('Source is zero, only positive numbers are supported')
}
if (source % 1 !== 0) {
throw new Error('Source is not an integer, only integers are supported')
}
if (source > 99_999) {
throw new Error('Source is too big, only numbers up to 99,999 are supported')
}

let result = ''
let reminder = source
const arr = [
90_000, 80_000, 70_000, 60_000, 50_000, 40_000, 30_000, 20_000, 10_000,
9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000,
900, 800, 700, 600, 500, 400, 300, 200, 100,
90, 80, 70, 60, 50, 40, 30, 20, 10,
9, 8, 7, 6, 5, 4, 3, 2, 1
] as const

for (const n of arr) {
while (reminder >= n) {
result += Ag[n]
reminder -= n
}
}

return result
}
103 changes: 103 additions & 0 deletions packages/aegean/src/numerals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const numbers = [
String.fromCodePoint(0x10107), /** #0 𐄇 U+10107 aegean numeral 1 */
String.fromCodePoint(0x10108), /** #1 𐄈 U+10108 aegean numeral 2 */
String.fromCodePoint(0x10109), /** #2 𐄉 U+10109 aegean numeral 3 */
String.fromCodePoint(0x1010A), /** #3 𐄊 U+1010A aegean numeral 4 */
String.fromCodePoint(0x1010B), /** #4 𐄋 U+1010B aegean numeral 5 */
String.fromCodePoint(0x1010C), /** #5 𐄌 U+1010C aegean numeral 6 */
String.fromCodePoint(0x1010D), /** #6 𐄍 U+1010D aegean numeral 7 */
String.fromCodePoint(0x1010E), /** #7 𐄎 U+1010E aegean numeral 8 */
String.fromCodePoint(0x1010F), /** #8 𐄏 U+1010F aegean numeral 9 */

String.fromCodePoint(0x10110), /** #9 𐄐 U+10110 aegean numeral 10 */
String.fromCodePoint(0x10111), /** #10 𐄑 U+10111 aegean numeral 20 */
String.fromCodePoint(0x10112), /** #11 𐄒 U+10112 aegean numeral 30 */
String.fromCodePoint(0x10113), /** #12 𐄓 U+10113 aegean numeral 40 */
String.fromCodePoint(0x10114), /** #13 𐄔 U+10114 aegean numeral 50 */
String.fromCodePoint(0x10115), /** #14 𐄕 U+10115 aegean numeral 60 */
String.fromCodePoint(0x10116), /** #15 𐄖 U+10116 aegean numeral 70 */
String.fromCodePoint(0x10117), /** #16 𐄗 U+10117 aegean numeral 80 */
String.fromCodePoint(0x10118), /** #17 𐄘 U+10118 aegean numeral 90 */

String.fromCodePoint(0x10119), /** #18 𐄙 U+10119 aegean numeral 100 */
String.fromCodePoint(0x1011A), /** #19 𐄚 U+1011A aegean numeral 200 */
String.fromCodePoint(0x1011B), /** #20 𐄛 U+1011B aegean numeral 300 */
String.fromCodePoint(0x1011C), /** #21 𐄜 U+1011C aegean numeral 400 */
String.fromCodePoint(0x1011D), /** #22 𐄝 U+1011D aegean numeral 500 */
String.fromCodePoint(0x1011E), /** #23 𐄞 U+1011E aegean numeral 600 */
String.fromCodePoint(0x1011F), /** #24 𐄟 U+1011F aegean numeral 700 */
String.fromCodePoint(0x10120), /** #25 𐄠 U+10120 aegean numeral 800 */
String.fromCodePoint(0x10121), /** #26 𐄡 U+10121 aegean numeral 900 */

String.fromCodePoint(0x10122), /** #27 𐄢 U+10122 aegean numeral 1000 */
String.fromCodePoint(0x10123), /** #28 𐄣 U+10123 aegean numeral 2000 */
String.fromCodePoint(0x10124), /** #29 𐄤 U+10124 aegean numeral 3000 */
String.fromCodePoint(0x10125), /** #30 𐄥 U+10125 aegean numeral 4000 */
String.fromCodePoint(0x10126), /** #31 𐄦 U+10126 aegean numeral 5000 */
String.fromCodePoint(0x10127), /** #32 𐄧 U+10127 aegean numeral 6000 */
String.fromCodePoint(0x10128), /** #33 𐄨 U+10128 aegean numeral 7000 */
String.fromCodePoint(0x10129), /** #34 𐄩 U+10129 aegean numeral 8000 */
String.fromCodePoint(0x1012A), /** #35 𐄪 U+1012A aegean numeral 9000 */

String.fromCodePoint(0x1012B), /** #36 𐄫 U+1012B aegean numeral 10,000 */
String.fromCodePoint(0x1012C), /** #37 𐄬 U+1012C aegean numeral 20,000 */
String.fromCodePoint(0x1012D), /** #38 𐄭 U+1012D aegean numeral 30,000 */
String.fromCodePoint(0x1012E), /** #39 𐄮 U+1012E aegean numeral 40,000 */
String.fromCodePoint(0x1012F), /** #40 𐄯 U+1012F aegean numeral 50,000 */
String.fromCodePoint(0x10130), /** #41 𐄰 U+10130 aegean numeral 60,000 */
String.fromCodePoint(0x10131), /** #42 𐄱 U+10131 aegean numeral 70,000 */
String.fromCodePoint(0x10132), /** #43 𐄲 U+10132 aegean numeral 80,000 */
String.fromCodePoint(0x10133), /** #44 𐄳 U+10133 aegean numeral 90,000 */
] as const

export const Ag = {
1: numbers[0],
2: numbers[1],
3: numbers[2],
4: numbers[3],
5: numbers[4],
6: numbers[5],
7: numbers[6],
8: numbers[7],
9: numbers[8],

10: numbers[9],
20: numbers[10],
30: numbers[11],
40: numbers[12],
50: numbers[13],
60: numbers[14],
70: numbers[15],
80: numbers[16],
90: numbers[17],

100: numbers[18],
200: numbers[19],
300: numbers[20],
400: numbers[21],
500: numbers[22],
600: numbers[23],
700: numbers[24],
800: numbers[25],
900: numbers[26],

1000: numbers[27],
2000: numbers[28],
3000: numbers[29],
4000: numbers[30],
5000: numbers[31],
6000: numbers[32],
7000: numbers[33],
8000: numbers[34],
9000: numbers[35],

10_000: numbers[36],
20_000: numbers[37],
30_000: numbers[38],
40_000: numbers[39],
50_000: numbers[40],
60_000: numbers[41],
70_000: numbers[42],
80_000: numbers[43],
90_000: numbers[44],
}
55 changes: 55 additions & 0 deletions packages/aegean/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { convert } from '../src'
import { Ag } from '../src/numerals'
import { describe, expect, it } from '@jest/globals'

describe('convert()', () => {
it('convert 1 into 𐄇', () => {
const actual = convert(1)
expect(actual).toEqual(Ag[1])
})
it('convert 2 into 𐄈', () => {
const actual = convert(2)
expect(actual).toEqual(Ag[2])
})
it('convert 10 into 𐄐', () => {
const actual = convert(10)
expect(actual).toEqual(Ag[10])
})
it('convert 11 into 𐄐𐄇', () => {
const actual = convert(11)
expect(actual).toEqual(Ag[10] + Ag[1])
})
it('convert 100 into 𐄙', () => {
const actual = convert(100)
expect(actual).toEqual(Ag[100])
})
it('convert 101 into 𐄙𐄇', () => {
const actual = convert(101)
expect(actual).toEqual(Ag[100] + Ag[1])
})
it('convert 1000 into 𐄢', () => {
const actual = convert(1000)
expect(actual).toEqual(Ag[1000])
})
it.each([NaN, Infinity, -Infinity])
('throw Error for non number [%s]', (it) => {
const actual = () => convert(it)
expect(actual).toThrowError('Source is not a finite number')
})
it('throw Error for zero', () => {
const actual = () => convert(0)
expect(actual).toThrowError('Source is zero, only positive numbers are supported')
})
it('throw Error for negative number', () => {
const actual = () => convert(-1)
expect(actual).toThrowError('Source is negative, only positive numbers are supported')
})
it('throw Error for float number', () => {
const actual = () => convert(1.1)
expect(actual).toThrowError('Source is not an integer, only integers are supported')
})
it('throw Error for number greater than 99,999', () => {
const actual = () => convert(100_000)
expect(actual).toThrowError('Source is too big, only numbers up to 99,999 are supported')
})
})
6 changes: 6 additions & 0 deletions packages/aegean/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
}
}
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,12 @@ __metadata:
languageName: node
linkType: hard

"@numerals/aegean@workspace:packages/aegean":
version: 0.0.0-use.local
resolution: "@numerals/aegean@workspace:packages/aegean"
languageName: unknown
linkType: soft

"@numerals/eastern-arabic@npm:0.0.2":
version: 0.0.2
resolution: "@numerals/eastern-arabic@npm:0.0.2"
Expand Down

0 comments on commit 7c40627

Please sign in to comment.