Skip to content

Commit

Permalink
Kaktovik/versoin/0.0.1 (#22)
Browse files Browse the repository at this point in the history
Add Kaktovik numeral package
  • Loading branch information
amerharb authored Oct 9, 2024
1 parent f85b117 commit c469e06
Show file tree
Hide file tree
Showing 32 changed files with 346 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
PACKAGE_NAME="thai"
elif [[ $TAG_NAME =~ ^hanifi-rohingya\/v.* ]]; then
PACKAGE_NAME="hanifi-rohingya"
elif [[ $TAG_NAME =~ ^kaktovik\/v.* ]]; then
PACKAGE_NAME="kaktovik"
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 @@ -30,6 +30,8 @@ jobs:
PACKAGE_NAME="thai"
elif [[ $TAG_NAME =~ ^hanifi-rohingya\/v.* ]]; then
PACKAGE_NAME="hanifi-rohingya"
elif [[ $TAG_NAME =~ ^kaktovik\/v.* ]]; then
PACKAGE_NAME="kaktovik"
else
echo "❌ tag name: $TAG_NAME doesn't point to any publishable package"
exit 1
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
<!-- https://keepachangelog.com/en/1.0.0/ -->

## [0.8.0] 2024-10-09
### Added
- Add Kaktovik numeral package

## [0.7.0] 2024-05-16
### Added
- Add Hanifi Rohingya numeral package
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ This is a monorepo for the Numerals project.
### thai ๐๑๒๓๔๕๖๗๘๙
[README](https://github.com/amerharb/numerals/blob/main/packages/thai/README.md)

### hanifi-rohingya
### hanifi-rohingya 𐴱 𐴲 𐴳 𐴴 𐴵
[README](https://github.com/amerharb/numerals/blob/main/packages/hanifi-rohingya/README.md)

### kaktovik 𝋀 𝋁 𝋂 𝋃
[README](https://github.com/amerharb/numerals/blob/main/packages/kaktovik/README.md)

### numerals-client
Example of a client for npm package

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
"packages/aegean",
"packages/thai",
"packages/hanifi-rohingya",
"packages/kaktovik",
"packages/numerals-client",
"packages/numerals-web"
],
"version": "0.7.0",
"version": "0.8.0",
"author": "Amer Harb",
"license": "ISC",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions packages/aegean/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ Try it: [numerals.amerharb.com](https://numerals.amerharb.com)
- [@numerals/roman](https://www.npmjs.com/package/@numerals/roman)
- [@numerals/thai](https://www.npmjs.com/package/@numerals/thai)
- [@numerals/hanifi-rohingya](https://www.npmjs.com/package/@numerals/hanifi-rohingya)
- [@numerals/kaktovik](https://www.npmjs.com/package/@numerals/kaktovik)
1 change: 1 addition & 0 deletions packages/eastern-arabic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ Try it: [numerals.amerharb.com](https://numerals.amerharb.com)
- [@numerals/aegean](https://www.npmjs.com/package/@numerals/aegean)
- [@numerals/thai](https://www.npmjs.com/package/@numerals/thai)
- [@numerals/hanifi-rohingya](https://www.npmjs.com/package/@numerals/hanifi-rohingya)
- [@numerals/kaktovik](https://www.npmjs.com/package/@numerals/kaktovik)
1 change: 1 addition & 0 deletions packages/hanifi-rohingya/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ Try it: [numerals.amerharb.com](https://numerals.amerharb.com)
- [@numerals/roman](https://www.npmjs.com/package/@numerals/roman)
- [@numerals/aegean](https://www.npmjs.com/package/@numerals/aegean)
- [@numerals/thai](https://www.npmjs.com/package/@numerals/thai)
- [@numerals/kaktovik](https://www.npmjs.com/package/@numerals/kaktovik)
1 change: 1 addition & 0 deletions packages/hieroglyphic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ Try it: [numerals.amerharb.com](https://numerals.amerharb.com)
- [@numerals/aegean](https://www.npmjs.com/package/@numerals/aegean)
- [@numerals/thai](https://www.npmjs.com/package/@numerals/thai)
- [@numerals/hanifi-rohingya](https://www.npmjs.com/package/@numerals/hanifi-rohingya)
- [@numerals/kaktovik](https://www.npmjs.com/package/@numerals/kaktovik)
6 changes: 6 additions & 0 deletions packages/kaktovik/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Kaktovik Changelog
<!-- https://keepachangelog.com/en/1.0.0/ -->

## [0.0.1] 2024-10-06
### Added
- Initial project covert number into Kaktovik numerals
12 changes: 12 additions & 0 deletions packages/kaktovik/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.
43 changes: 43 additions & 0 deletions packages/kaktovik/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# @numerals/kaktovik

[![Version](https://img.shields.io/badge/version-0.0.1-blue.svg)](https://github.com/amerharb/numerals/tree/kaktovik/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/kaktovik/version/0.0.1/packages/kaktovik/badges/coverage.svg)
![Github workflow](https://github.com/amerharb/numerals/actions/workflows/lint-test.yaml/badge.svg?branch=kaktovik/version/0.0.1)

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

`19 -> 𝋓`

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

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

Type Script:
```js
import { convert } from '@numerals/kaktovik';
console.log(convert(0)); // 𝋀
console.log(convert(1)); // 𝋁
console.log(convert(10)); // 𝋊
console.log(convert(19)); // 𝋓
console.log(convert(20)); // 𝋁𝋀
```

## Demo
Try it: [numerals.amerharb.com](https://numerals.amerharb.com)

## Other Numerals packages
- [@numerals/eastern-arabic](https://www.npmjs.com/package/@numerals/eastern-arabic)
- [@numerals/mayan](https://www.npmjs.com/package/@numerals/mayan)
- [@numerals/hieroglyphic](https://www.npmjs.com/package/@numerals/hieroglyphic)
- [@numerals/roman](https://www.npmjs.com/package/@numerals/roman)
- [@numerals/aegean](https://www.npmjs.com/package/@numerals/aegean)
- [@numerals/thai](https://www.npmjs.com/package/@numerals/thai)
- [@numerals/hanifi-rohingya](https://www.npmjs.com/package/@numerals/hanifi-rohingya)
1 change: 1 addition & 0 deletions packages/kaktovik/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/kaktovik/doc/U1D2C0.pdf
Binary file not shown.
14 changes: 14 additions & 0 deletions packages/kaktovik/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/kaktovik/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@numerals/kaktovik",
"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": [
"kaktovik-numerals",
"kaktovik-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"
}
}
47 changes: 47 additions & 0 deletions packages/kaktovik/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Ka } from './numerals'

const map = new Map<string, string>(
[
['0', Ka['0']],
['1', Ka['1']],
['2', Ka['2']],
['3', Ka['3']],
['4', Ka['4']],
['5', Ka['5']],
['6', Ka['6']],
['7', Ka['7']],
['8', Ka['8']],
['9', Ka['9']],
['a', Ka['10']],
['b', Ka['11']],
['c', Ka['12']],
['d', Ka['13']],
['e', Ka['14']],
['f', Ka['15']],
['g', Ka['16']],
['h', Ka['17']],
['i', Ka['18']],
['j', Ka['19']],
['.', '.'],
['-', '-'],
]
)

export function convert(source: number): string {
if (!Number.isFinite(source)) {
throw new Error('Source is not a finite number')
}

const base20 = source.toString(20)
const sourceString = base20.toString()
let result = ''
for (const letter of sourceString) {
const u = map.get(letter) ?? throwNoNumeralFor(letter)
result += u
}
return result
}

function throwNoNumeralFor(letter: string): never {
throw new Error(`No numeral for "${letter}"`)
}
45 changes: 45 additions & 0 deletions packages/kaktovik/src/numerals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const numbers = [
String.fromCodePoint(0x1D2C0), /** #0 U+1D2C0 Kaktovik numeral 0 */
String.fromCodePoint(0x1D2C1), /** #1 U+1D2C1 Kaktovik numeral 1 */
String.fromCodePoint(0x1D2C2), /** #2 U+1D2C2 Kaktovik numeral 2 */
String.fromCodePoint(0x1D2C3), /** #3 U+1D2C3 Kaktovik numeral 3 */
String.fromCodePoint(0x1D2C4), /** #4 U+1D2C4 Kaktovik numeral 4 */
String.fromCodePoint(0x1D2C5), /** #5 U+1D2C5 Kaktovik numeral 5 */
String.fromCodePoint(0x1D2C6), /** #6 U+1D2C6 Kaktovik numeral 6 */
String.fromCodePoint(0x1D2C7), /** #7 U+1D2C7 Kaktovik numeral 7 */
String.fromCodePoint(0x1D2C8), /** #8 U+1D2C8 Kaktovik numeral 8 */
String.fromCodePoint(0x1D2C9), /** #9 U+1D2C9 Kaktovik numeral 9 */
String.fromCodePoint(0x1D2CA), /** #10 U+1D2CA Kaktovik numeral 10 */
String.fromCodePoint(0x1D2CB), /** #11 U+1D2CB Kaktovik numeral 11 */
String.fromCodePoint(0x1D2CC), /** #12 U+1D2CC Kaktovik numeral 12 */
String.fromCodePoint(0x1D2CD), /** #13 U+1D2CD Kaktovik numeral 13 */
String.fromCodePoint(0x1D2CE), /** #14 U+1D2CE Kaktovik numeral 14 */
String.fromCodePoint(0x1D2CF), /** #15 U+1D2CF Kaktovik numeral 15 */
String.fromCodePoint(0x1D2D0), /** #16 U+1D2D0 Kaktovik numeral 16 */
String.fromCodePoint(0x1D2D1), /** #17 U+1D2D1 Kaktovik numeral 17 */
String.fromCodePoint(0x1D2D2), /** #18 U+1D2D2 Kaktovik numeral 18 */
String.fromCodePoint(0x1D2D3), /** #19 U+1D2D3 Kaktovik numeral 19 */
] as const

export const Ka = {
'0': numbers[0],
'1': numbers[1],
'2': numbers[2],
'3': numbers[3],
'4': numbers[4],
'5': numbers[5],
'6': numbers[6],
'7': numbers[7],
'8': numbers[8],
'9': numbers[9],
'10': numbers[10],
'11': numbers[11],
'12': numbers[12],
'13': numbers[13],
'14': numbers[14],
'15': numbers[15],
'16': numbers[16],
'17': numbers[17],
'18': numbers[18],
'19': numbers[19],
}
51 changes: 51 additions & 0 deletions packages/kaktovik/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { convert } from '../src'
import { Ka } from '../src/numerals'
import { describe, expect, it } from '@jest/globals'

describe('convert()', () => {
it(`convert 0 into ${Ka[0]}`, () => {
const actual = convert(0)
expect(actual).toEqual(Ka['0'])
})
it(`convert 1 into ${Ka[1]}`, () => {
const actual = convert(1)
expect(actual).toEqual(Ka['1'])
})
it(`convert 10 into ${Ka[10]}`, () => {
const actual = convert(10)
expect(actual).toEqual(Ka['10'])
})
it(`convert 19 into ${Ka[19]}`, () => {
const actual = convert(19)
expect(actual).toEqual(Ka['19'])
})
it(`convert 20 into ${Ka[1]}${Ka[0]}`, () => {
const actual = convert(20)
expect(actual).toEqual(`${Ka['1']}${Ka['0']}`)
})
it(`convert 21 into ${Ka['1']}${Ka['1']}`, () => {
const actual = convert(21)
expect(actual).toEqual(`${Ka['1']}${Ka['1']}`)
})
it(`convert 39 into ${Ka['1']}${Ka['19']}`, () => {
const actual = convert(39)
expect(actual).toEqual(`${Ka['1']}${Ka['19']}`)
})
it(`convert 40 into ${Ka['2']}${Ka['0']}`, () => {
const actual = convert(40)
expect(actual).toEqual(`${Ka['2']}${Ka['0']}`)
})
it(`convert 1.1 into ${Ka['1']}.${Ka['2']}`, () => {
const actual = convert(1.1)
expect(actual).toEqual(`${Ka['1']}.${Ka['2']}`)
})
it(`convert -1 into -${Ka['1']}`, () => {
const actual = convert(-1)
expect(actual).toEqual(`-${Ka['1']}`)
})
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')
})
})
6 changes: 6 additions & 0 deletions packages/kaktovik/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
}
}
1 change: 1 addition & 0 deletions packages/mayan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ Try it: [numerals.amerharb.com](https://numerals.amerharb.com)
- [@numerals/aegean](https://www.npmjs.com/package/@numerals/aegean)
- [@numerals/thai](https://www.npmjs.com/package/@numerals/thai)
- [@numerals/hanifi-rohingya](https://www.npmjs.com/package/@numerals/hanifi-rohingya)
- [@numerals/kaktovik](https://www.npmjs.com/package/@numerals/kaktovik)
3 changes: 2 additions & 1 deletion packages/numerals-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "numerals-client",
"private": true,
"version": "0.7.0",
"version": "0.8.0",
"main": "dist/index.js",
"scripts": {
"build": "rm -rf dist && npx tsc",
Expand All @@ -16,6 +16,7 @@
"@numerals/eastern-arabic": "0.0.2",
"@numerals/hanifi-rohingya": "0.0.1",
"@numerals/hieroglyphic": "0.0.2",
"@numerals/kaktovik": "0.0.1-next.0",
"@numerals/mayan": "0.0.1",
"@numerals/roman": "0.0.2",
"@numerals/thai": "0.0.2"
Expand Down
6 changes: 6 additions & 0 deletions packages/numerals-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { convert as ro } from '@numerals/roman'
import { convert as ag } from '@numerals/aegean'
import { convert as th } from '@numerals/thai'
import { convert as hr } from '@numerals/hanifi-rohingya'
import { convert as ka } from '@numerals/kaktovik'

log('@numerals/eastern-arabic')
log(calmConvert(ar, 123))
Expand Down Expand Up @@ -48,6 +49,11 @@ log(calmConvert(hr, 123.456))
log(calmConvert(hr, -1))
log(calmConvert(hr, NaN))

log('@numerals/kaktovik')
log(calmConvert(ka, 123))
log(calmConvert(ka, 123.456))
log(calmConvert(ka, -1))
log(calmConvert(ka, NaN))
log('Done')

function calmConvert(convert:(n:number) => string, source: number): string {
Expand Down
Loading

0 comments on commit c469e06

Please sign in to comment.