-
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 Mayan numeral conversion
- Loading branch information
Showing
27 changed files
with
356 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
# Changelog | ||
<!-- https://keepachangelog.com/en/1.0.0/ --> | ||
|
||
## [0.2.0] 2024-04-28 | ||
### Added | ||
- Add Mayan numeral conversion | ||
|
||
## [0.0.1] 2024-03-05 | ||
### Added | ||
- Root project structure |
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
File renamed without changes.
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 @@ | ||
# mayan Changelog | ||
<!-- https://keepachangelog.com/en/1.0.0/ --> | ||
|
||
## [0.0.1] 2024-04-25 | ||
### Added | ||
- Initial project covert number into mayan 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,31 @@ | ||
# @numerals/mayan | ||
|
||
[![Version](https://img.shields.io/badge/version-0.0.1-blue.svg)](https://github.com/amerharb/numerals/tree/mayan/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/mayan/version/0.0.1/packages/mayan/badges/coverage.svg) | ||
![Github workflow](https://github.com/amerharb/numerals/actions/workflows/lint-test.yaml/badge.svg?branch=mayan/version/0.0.1) | ||
|
||
**@numerals/mayan** is a package for converting number into mayan numeral. | ||
|
||
`19 -> 𝋳` | ||
|
||
## How to use | ||
npm: | ||
```shell | ||
npm i @numerals/mayan | ||
``` | ||
|
||
yarn: | ||
```shell | ||
yarn add @numerals/mayan | ||
``` | ||
|
||
Type Script: | ||
```js | ||
import { convert } from '@numerals/mayan'; | ||
console.log(convert(0)); // 𝋠 | ||
console.log(convert(1)); // 𝋡 | ||
console.log(convert(10)); // 𝋪 | ||
console.log(convert(19)); // 𝋳 | ||
console.log(convert(20)); // 𝋰𝋠 | ||
``` |
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/mayan", | ||
"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": [ | ||
"mayan-numberals", | ||
"mayan-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" | ||
} | ||
} |
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,51 @@ | ||
import { Ma } from './numerals' | ||
|
||
const map = new Map<string, string>( | ||
[ | ||
['0', Ma['0']], | ||
['1', Ma['1']], | ||
['2', Ma['2']], | ||
['3', Ma['3']], | ||
['4', Ma['4']], | ||
['5', Ma['5']], | ||
['6', Ma['6']], | ||
['7', Ma['7']], | ||
['8', Ma['8']], | ||
['9', Ma['9']], | ||
['a', Ma['10']], | ||
['b', Ma['11']], | ||
['c', Ma['12']], | ||
['d', Ma['13']], | ||
['e', Ma['14']], | ||
['f', Ma['15']], | ||
['g', Ma['16']], | ||
['h', Ma['17']], | ||
['i', Ma['18']], | ||
['j', Ma['19']], | ||
] | ||
) | ||
|
||
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 % 1 !== 0) { | ||
throw new Error('Source is not an integer, only integers are supported') | ||
} | ||
|
||
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 = [ | ||
'\ud834\uDEE0', /** #0 𝋠 U+1D2E0 mayan numeral 0 */ | ||
'\ud834\uDEE1', /** #1 𝋡 U+1D2E1 mayan numeral 1 */ | ||
'\ud834\uDEE2', /** #2 𝋢 U+1D2E2 mayan numeral 2 */ | ||
'\ud834\uDEE3', /** #3 𝋣 U+1D2E3 mayan numeral 3 */ | ||
'\ud834\uDEE4', /** #4 𝋤 U+1D2E4 mayan numeral 4 */ | ||
'\ud834\uDEE5', /** #5 𝋥 U+1D2E5 mayan numeral 5 */ | ||
'\ud834\uDEE6', /** #6 𝋦 U+1D2E6 mayan numeral 6 */ | ||
'\ud834\uDEE7', /** #7 𝋧 U+1D2E7 mayan numeral 7 */ | ||
'\ud834\uDEE8', /** #8 𝋨 U+1D2E8 mayan numeral 8 */ | ||
'\ud834\uDEE9', /** #9 𝋩 U+1D2E9 mayan numeral 9 */ | ||
'\ud834\uDEEA', /** #10 𝋪 U+1D2EA mayan numeral 10 */ | ||
'\ud834\uDEEB', /** #11 𝋫 U+1D2EB mayan numeral 11 */ | ||
'\ud834\uDEEC', /** #12 𝋬 U+1D2EC mayan numeral 12 */ | ||
'\ud834\uDEED', /** #13 𝋭 U+1D2ED mayan numeral 13 */ | ||
'\ud834\uDEEE', /** #14 𝋮 U+1D2EE mayan numeral 14 */ | ||
'\ud834\uDEEF', /** #15 𝋯 U+1D2EF mayan numeral 15 */ | ||
'\ud834\uDEF0', /** #16 𝋰 U+1D2F0 mayan numeral 16 */ | ||
'\ud834\uDEF1', /** #17 𝋱 U+1D2F1 mayan numeral 17 */ | ||
'\ud834\uDEF2', /** #18 𝋲 U+1D2F2 mayan numeral 18 */ | ||
'\ud834\uDEF3', /** #19 𝋳 U+1D2F3 mayan numeral 19 */ | ||
] as const | ||
|
||
export const Ma = { | ||
'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,43 @@ | ||
import { convert } from '../src' | ||
import { Ma } from '../src/numerals' | ||
import { describe, expect, it } from '@jest/globals' | ||
|
||
describe('convert()', () => { | ||
it('convert 0 into 𝋠', () => { | ||
const actual = convert(0) | ||
expect(actual).toEqual(Ma['0']) | ||
}) | ||
it('convert 1 into 𝋡', () => { | ||
const actual = convert(1) | ||
expect(actual).toEqual(Ma['1']) | ||
}) | ||
it('convert 10 into 𝋪', () => { | ||
const actual = convert(10) | ||
expect(actual).toEqual(Ma['10']) | ||
}) | ||
it('convert 19 into 𝋳', () => { | ||
const actual = convert(19) | ||
expect(actual).toEqual(Ma['19']) | ||
}) | ||
it('convert 20 into 𝋰𝋠', () => { | ||
const actual = convert(20) | ||
expect(actual).toEqual(`${Ma['1']}${Ma['0']}`) | ||
}) | ||
it('convert 21 into 𝋡𝋡', () => { | ||
const actual = convert(21) | ||
expect(actual).toEqual(`${Ma['1']}${Ma['1']}`) | ||
}) | ||
it('convert 39 into 𝋡𝋳', () => { | ||
const actual = convert(39) | ||
expect(actual).toEqual(`${Ma['1']}${Ma['19']}`) | ||
}) | ||
it('convert 40 into 𝋢𝋠', () => { | ||
const actual = convert(40) | ||
expect(actual).toEqual(`${Ma['2']}${Ma['0']}`) | ||
}) | ||
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.