-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Kaktovik numeral package
- Loading branch information
Showing
32 changed files
with
346 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.