-
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.
covert number into hieroglyphic numerals
- Loading branch information
Showing
20 changed files
with
277 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# hieroglyphic Changelog | ||
<!-- https://keepachangelog.com/en/1.0.0/ --> | ||
|
||
## [0.0.1] 2024-04-30 | ||
### Added | ||
- Initial project covert number into hieroglyphic 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,30 @@ | ||
# @numerals/hieroglyphic | ||
|
||
[![Version](https://img.shields.io/badge/version-0.0.1-blue.svg)](https://github.com/amerharb/numerals/tree/hieroglyphic/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/hieroglyphic/version/0.0.1/packages/hieroglyphic/badges/coverage.svg) | ||
![Github workflow](https://github.com/amerharb/numerals/actions/workflows/lint-test.yaml/badge.svg?branch=hieroglyphic/version/0.0.1) | ||
|
||
**@numerals/hieroglyphic** is a package for converting number into hieroglyphic numeral. | ||
|
||
`2 -> 𓀀𓀀` | ||
|
||
## How to use | ||
npm: | ||
```shell | ||
npm i @numerals/hieroglyphic | ||
``` | ||
|
||
yarn: | ||
```shell | ||
yarn add @numerals/hieroglyphic | ||
``` | ||
|
||
Type Script: | ||
```ts | ||
import { convert } from '@numerals/hieroglyphic'; | ||
console.log(convert(1)); // 𓀀 | ||
console.log(convert(2)); // 𓀀𓀀 | ||
console.log(convert(10)); // 𓀊 | ||
console.log(convert(1000)); // 𓀪 | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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/hieroglyphic", | ||
"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": [ | ||
"hieroglyphic-numberals", | ||
"hieroglyphic-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,34 @@ | ||
import { Hi } 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 > 10_000_000) { | ||
throw new Error('Source is too big, only numbers up to 10 000 000 are supported') | ||
} | ||
|
||
let result = '' | ||
let reminder = source | ||
const arr = [1000_000, 100_000, 10_000, 1000, 100, 10, 1] as const | ||
while (reminder > 0) { | ||
for (const n of arr) { | ||
if (reminder - n >= 0) { | ||
result += Hi[n] | ||
reminder -= n | ||
break | ||
} | ||
} | ||
} | ||
|
||
return result | ||
} |
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,19 @@ | ||
const numbers = [ | ||
String.fromCodePoint(0x13000), /** #0 𓀀 U+13000 hieroglyphic numeral 1 */ | ||
String.fromCodePoint(0x1300A), /** #1 𓀊 U+1300A hieroglyphic numeral 10 */ | ||
String.fromCodePoint(0x1301A), /** #2 𓀚 U+1301A hieroglyphic numeral 100 */ | ||
String.fromCodePoint(0x1302A), /** #3 𓀪 U+1302A hieroglyphic numeral 1000 */ | ||
String.fromCodePoint(0x1303A), /** #4 𓀰 U+1303A hieroglyphic numeral 10_000 */ | ||
String.fromCodePoint(0x1304A), /** #5 𓁀 U+1304A hieroglyphic numeral 100_000 */ | ||
String.fromCodePoint(0x1305A), /** #6 𓁐 U+1305A hieroglyphic numeral 1000_000 */ | ||
] as const | ||
|
||
export const Hi = { | ||
1: numbers[0], | ||
10: numbers[1], | ||
100: numbers[2], | ||
1000: numbers[3], | ||
10_000: numbers[4], | ||
100_000: numbers[5], | ||
1000_000: numbers[6], | ||
} |
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 { Hi } from '../src/numerals' | ||
import { describe, expect, it } from '@jest/globals' | ||
|
||
describe('convert()', () => { | ||
it('convert 1 into 𓀀', () => { | ||
const actual = convert(1) | ||
expect(actual).toEqual(Hi[1]) | ||
}) | ||
it('convert 2 into 𓀀𓀀', () => { | ||
const actual = convert(2) | ||
expect(actual).toEqual(Hi[1] + Hi[1]) | ||
}) | ||
it('convert 10 into 𓀊', () => { | ||
const actual = convert(10) | ||
expect(actual).toEqual(Hi[10]) | ||
}) | ||
it('convert 11 into 𓀊𓀀', () => { | ||
const actual = convert(11) | ||
expect(actual).toEqual(Hi[10] + Hi[1]) | ||
}) | ||
it('convert 100 into 𓀚', () => { | ||
const actual = convert(100) | ||
expect(actual).toEqual(Hi[100]) | ||
}) | ||
it('convert 101 into 𓀚𓀀', () => { | ||
const actual = convert(101) | ||
expect(actual).toEqual(Hi[100] + Hi[1]) | ||
}) | ||
it('convert 1000 into 𓀪', () => { | ||
const actual = convert(1000) | ||
expect(actual).toEqual(Hi[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') | ||
}) | ||
}) |
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", | ||
} | ||
} |
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
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.