Skip to content

Commit

Permalink
Mayan/version/0.0.1 (#5)
Browse files Browse the repository at this point in the history
- Add Mayan numeral conversion
  • Loading branch information
amerharb authored Apr 28, 2024
1 parent c9a39ff commit dda002e
Show file tree
Hide file tree
Showing 27 changed files with 356 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn workspaces foreach --all install --immutable

- run: yarn workspaces foreach --all install
- run: yarn lint
- run: yarn build
- run: yarn test
9 changes: 5 additions & 4 deletions .github/workflows/publish-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
run: |
if [[ $TAG_NAME =~ ^eastern-arabic\/v.* ]]; then
PACKAGE_NAME="eastern-arabic"
elif [[ $TAG_NAME =~ ^mayan\/v.* ]]; then
PACKAGE_NAME="mayan"
else
echo "❌ tag name: $TAG_NAME doesn't point to any publishable package"
exit 1
Expand Down Expand Up @@ -71,8 +73,7 @@ jobs:
- run: yarn build
- run: yarn test

- name: publish @numerals/eastern-arabic @latest to npm
if: ${{ env.PACKAGE_NAME == 'eastern-arabic' }}
run: yarn workspace @numerals/eastern-arabic npm publish --access public --tag latest
- name: publish @numerals package @latest to npm
run: yarn workspace @numerals/$PACKAGE_NAME npm publish --access public --tag latest
env:
NODE_AUTH_TOKEN: ${{ secrets.EASTERN_ARABIC_PUBLISH_AUTH_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NUMERALS_PUBLISH_AUTH_TOKEN }}
9 changes: 5 additions & 4 deletions .github/workflows/publish-next.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
run: |
if [[ $TAG_NAME =~ ^eastern-arabic\/v.* ]]; then
PACKAGE_NAME="eastern-arabic"
elif [[ $TAG_NAME =~ ^mayan\/v.* ]]; then
PACKAGE_NAME="mayan"
else
echo "❌ tag name: $TAG_NAME doesn't point to any publishable package"
exit 1
Expand Down Expand Up @@ -71,8 +73,7 @@ jobs:
- run: yarn build
- run: yarn test

- name: publish @numerals/eastern-arabic @next to npm
if: ${{ env.PACKAGE_NAME == 'eastern-arabic' }}
run: yarn workspace @numerals/eastern-arabic npm publish --access public --tag next
- name: publish @numerals package @next to npm
run: yarn workspace @numerals/$PACKAGE_NAME npm publish --access public --tag next
env:
NODE_AUTH_TOKEN: ${{ secrets.EASTERN_ARABIC_PUBLISH_AUTH_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NUMERALS_PUBLISH_AUTH_TOKEN }}
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.2.0] 2024-04-28
### Added
- Add Mayan numeral conversion

## [0.0.1] 2024-03-05
### Added
- Root project structure
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ This is a monorepo for the Numerals project.
### eastern-arabic
[README](https://github.com/amerharb/numerals/blob/main/packages/eastern-arabic/README.md)

### mayan
[README](https://github.com/amerharb/numerals/blob/main/packages/mayan/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 @@ -3,10 +3,11 @@
"private": true,
"workspaces": [
"packages/eastern-arabic",
"packages/mayan",
"packages/numerals-client",
"packages/numerals-web"
],
"version": "0.0.1",
"version": "0.2.0",
"author": "Amer Harb",
"license": "ISC",
"scripts": {
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions packages/mayan/CHANGELOG.md
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
12 changes: 12 additions & 0 deletions packages/mayan/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.
31 changes: 31 additions & 0 deletions packages/mayan/README.md
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)); // 𝋰𝋠
```
1 change: 1 addition & 0 deletions packages/mayan/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/mayan/doc/U1D2E0.pdf
Binary file not shown.
14 changes: 14 additions & 0 deletions packages/mayan/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/mayan/package.json
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 added packages/mayan/src/U0600.pdf
Binary file not shown.
51 changes: 51 additions & 0 deletions packages/mayan/src/index.ts
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}"`)
}
45 changes: 45 additions & 0 deletions packages/mayan/src/numerals.ts
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],
}
43 changes: 43 additions & 0 deletions packages/mayan/test/index.test.ts
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')
})
})
6 changes: 6 additions & 0 deletions packages/mayan/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
}
}
3 changes: 2 additions & 1 deletion packages/numerals-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"lint:fix": "npx eslint . --fix"
},
"dependencies": {
"@numerals/eastern-arabic": "0.0.1-next.4"
"@numerals/eastern-arabic": "0.0.2",
"@numerals/mayan": "0.0.1-next.2"
}
}
19 changes: 12 additions & 7 deletions packages/numerals-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { convert } from '@numerals/eastern-arabic'
import { convert as ar } from '@numerals/eastern-arabic'
import { convert as ma } from '@numerals/mayan'

log('@numerals/eastern-arabic')
log(calmConvert(ar, 123))
log(calmConvert(ar, 123.456))
log(calmConvert(ar, -1))
log(calmConvert(ar, NaN))

log(calmConvert(123))
log(calmConvert(123.456))
log(calmConvert(-1))
log(calmConvert(NaN))

log('@numerals/mayan')
log(calmConvert(ma, 123))
log(calmConvert(ma, 123.456))
log(calmConvert(ma, -1))
log(calmConvert(ma, NaN))

log('Done')

function calmConvert(source: number): string {
function calmConvert(convert:(n:number) => string, source: number): string {
try {
return convert(source)
} catch (e: any) {
Expand Down
4 changes: 4 additions & 0 deletions packages/numerals-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

<!-- https://keepachangelog.com/en/1.0.0/ -->

## [0.0.2] 2024-04-28
### Added
- Add Mayan numeral conversion

## [0.0.1] 2024-04-23
### Added
- Setup NextJS
Expand Down
Loading

0 comments on commit dda002e

Please sign in to comment.