(
+ [
+ ['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}"`)
+}
diff --git a/packages/mayan/src/numerals.ts b/packages/mayan/src/numerals.ts
new file mode 100644
index 0000000..9ad98d3
--- /dev/null
+++ b/packages/mayan/src/numerals.ts
@@ -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],
+}
diff --git a/packages/mayan/test/index.test.ts b/packages/mayan/test/index.test.ts
new file mode 100644
index 0000000..caaad1f
--- /dev/null
+++ b/packages/mayan/test/index.test.ts
@@ -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')
+ })
+})
diff --git a/packages/mayan/tsconfig.json b/packages/mayan/tsconfig.json
new file mode 100644
index 0000000..9f0325b
--- /dev/null
+++ b/packages/mayan/tsconfig.json
@@ -0,0 +1,6 @@
+{
+ "extends": "../../tsconfig.json",
+ "compilerOptions": {
+ "outDir": "dist",
+ }
+}
diff --git a/packages/numerals-client/package.json b/packages/numerals-client/package.json
index a38f919..e9d9ae7 100644
--- a/packages/numerals-client/package.json
+++ b/packages/numerals-client/package.json
@@ -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"
}
}
diff --git a/packages/numerals-client/src/index.ts b/packages/numerals-client/src/index.ts
index b28259d..6f78e46 100644
--- a/packages/numerals-client/src/index.ts
+++ b/packages/numerals-client/src/index.ts
@@ -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) {
diff --git a/packages/numerals-web/CHANGELOG.md b/packages/numerals-web/CHANGELOG.md
index 09dc26d..ccba170 100644
--- a/packages/numerals-web/CHANGELOG.md
+++ b/packages/numerals-web/CHANGELOG.md
@@ -2,6 +2,10 @@
+## [0.0.2] 2024-04-28
+### Added
+- Add Mayan numeral conversion
+
## [0.0.1] 2024-04-23
### Added
- Setup NextJS
diff --git a/packages/numerals-web/package.json b/packages/numerals-web/package.json
index 1465ae4..7819f6a 100644
--- a/packages/numerals-web/package.json
+++ b/packages/numerals-web/package.json
@@ -1,7 +1,7 @@
{
"name": "numerals-web",
"private": true,
- "version": "0.0.1",
+ "version": "0.0.2",
"scripts": {
"dev": "next dev",
"build": "next build",
@@ -14,7 +14,8 @@
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@mui/joy": "^5.0.0-beta.11",
- "@numerals/eastern-arabic": "0.0.1-next.4",
+ "@numerals/eastern-arabic": "0.0.2",
+ "@numerals/mayan": "0.0.1-next.2",
"@vercel/analytics": "^1.1.2",
"@vercel/speed-insights": "^1.0.9",
"next": "^14.1.0",
diff --git a/packages/numerals-web/src/app/layout.tsx b/packages/numerals-web/src/app/layout.tsx
index 31109c8..f91d4c6 100644
--- a/packages/numerals-web/src/app/layout.tsx
+++ b/packages/numerals-web/src/app/layout.tsx
@@ -1,11 +1,12 @@
import Head from 'next/head'
import { Analytics } from '@vercel/analytics/react'
import { SpeedInsights } from '@vercel/speed-insights/next'
-import { Inter } from 'next/font/google'
+import { Inter, Noto_Sans_Mayan_Numerals } from 'next/font/google'
import type { Metadata } from 'next'
import React from 'react'
const inter = Inter({ subsets: ['latin'] })
+const notoSansMayan = Noto_Sans_Mayan_Numerals({ subsets: ['latin', 'mayan-numerals'], weight: '400' })
export const metadata: Metadata = {
title: 'Numerals web',
@@ -23,7 +24,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
-
+
{children}
diff --git a/packages/numerals-web/src/app/page.tsx b/packages/numerals-web/src/app/page.tsx
index 52ce4fa..3bb5e65 100644
--- a/packages/numerals-web/src/app/page.tsx
+++ b/packages/numerals-web/src/app/page.tsx
@@ -2,11 +2,13 @@
import { useState } from 'react'
import Select from 'react-select'
-import { convert } from '@numerals/eastern-arabic'
+import { convert as convertAr } from '@numerals/eastern-arabic'
+import { convert as convertMa } from '@numerals/mayan'
import Image from 'next/image'
enum Numerals {
EasternArabic = 'easternArabic',
+ Mayan = 'mayan',
}
export default function Home() {
@@ -16,6 +18,7 @@ export default function Home() {
const options = [
{ value: Numerals.EasternArabic, label: 'Eastern Arabic ٤ ٣ ٢ ١' },
+ { value: Numerals.Mayan, label: 'Mayan 𝋠 𝋡 𝋢 𝋣' },
]
const ToSelect = () =>
@@ -54,8 +61,12 @@ export default function Home() {
if (!toValue) {
return
}
- const result = convert(parseFloat(e.target.value))
- setResultText(result)
+ try {
+ const result = convert(parseFloat(e.target.value), toValue)
+ setResultText(result)
+ } catch (e: any) {
+ setResultText(e.message)
+ }
}}
style={{ padding: '10px', width: '100%', minHeight: '100px', fontSize: '25px' }}
/>
@@ -74,12 +85,14 @@ export default function Home() {
- This is an open source project. based on npm package{' '}
+ This is an open source project. based on
packages:{' '}
-
{' '}@numerals/eastern-arabic
+
+ {' '}@numerals/mayan
+
You can find the source code on{' '}
@@ -97,3 +110,12 @@ export default function Home() {
)
}
+
+function convert(source: number, to: Numerals): string {
+ switch (to) {
+ case Numerals.EasternArabic:
+ return convertAr(source)
+ case Numerals.Mayan:
+ return convertMa(source)
+ }
+}
diff --git a/packages/numerals-web/yarn.lock b/packages/numerals-web/yarn.lock
index 94ed9b0..0fcc417 100644
--- a/packages/numerals-web/yarn.lock
+++ b/packages/numerals-web/yarn.lock
@@ -621,10 +621,17 @@ __metadata:
languageName: node
linkType: hard
-"@numerals/eastern-arabic@npm:0.0.1-next.4":
- version: 0.0.1-next.4
- resolution: "@numerals/eastern-arabic@npm:0.0.1-next.4"
- checksum: 10c0/e28c0374e56a4d6e73ca36acea3737916aba412ba725179463ac355c3cc1170c61cdc4c485649a3aec7a9737562bd3fe56ca7af9c1949f7fc1ba9131327c0245
+"@numerals/eastern-arabic@npm:0.0.2":
+ version: 0.0.2
+ resolution: "@numerals/eastern-arabic@npm:0.0.2"
+ checksum: 10c0/e68a81453bd3d0db3187744cb8963d8b525f864fe7ac9432ebebacb9483c5f24b09fd18cecf95a897929985b6ea606aa240946043b925fe182d348aac0adcc8e
+ languageName: node
+ linkType: hard
+
+"@numerals/mayan@npm:0.0.1-next.2":
+ version: 0.0.1-next.2
+ resolution: "@numerals/mayan@npm:0.0.1-next.2"
+ checksum: 10c0/aa16e559bc4e835d2e3beb82cc33b78c522053571486332340b35b3bf25f4125a31c5664731b753a85c95a3b918d6ae220f296ad5e7836e92488f005ca382a27
languageName: node
linkType: hard
@@ -2796,7 +2803,8 @@ __metadata:
"@emotion/react": "npm:^11.11.1"
"@emotion/styled": "npm:^11.11.0"
"@mui/joy": "npm:^5.0.0-beta.11"
- "@numerals/eastern-arabic": "npm:0.0.1-next.4"
+ "@numerals/eastern-arabic": "npm:0.0.2"
+ "@numerals/mayan": "npm:0.0.1-next.2"
"@types/node": "npm:^20.12.5"
"@types/react": "npm:^18"
"@types/react-dom": "npm:^18"
diff --git a/yarn.lock b/yarn.lock
index 02ec67f..195c88e 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1300,10 +1300,10 @@ __metadata:
languageName: node
linkType: hard
-"@numerals/eastern-arabic@npm:0.0.1-next.4":
- version: 0.0.1-next.4
- resolution: "@numerals/eastern-arabic@npm:0.0.1-next.4"
- checksum: 10c0/e28c0374e56a4d6e73ca36acea3737916aba412ba725179463ac355c3cc1170c61cdc4c485649a3aec7a9737562bd3fe56ca7af9c1949f7fc1ba9131327c0245
+"@numerals/eastern-arabic@npm:0.0.2":
+ version: 0.0.2
+ resolution: "@numerals/eastern-arabic@npm:0.0.2"
+ checksum: 10c0/e68a81453bd3d0db3187744cb8963d8b525f864fe7ac9432ebebacb9483c5f24b09fd18cecf95a897929985b6ea606aa240946043b925fe182d348aac0adcc8e
languageName: node
linkType: hard
@@ -1313,6 +1313,19 @@ __metadata:
languageName: unknown
linkType: soft
+"@numerals/mayan@npm:0.0.1-next.2":
+ version: 0.0.1-next.2
+ resolution: "@numerals/mayan@npm:0.0.1-next.2"
+ checksum: 10c0/aa16e559bc4e835d2e3beb82cc33b78c522053571486332340b35b3bf25f4125a31c5664731b753a85c95a3b918d6ae220f296ad5e7836e92488f005ca382a27
+ languageName: node
+ linkType: hard
+
+"@numerals/mayan@workspace:packages/mayan":
+ version: 0.0.0-use.local
+ resolution: "@numerals/mayan@workspace:packages/mayan"
+ languageName: unknown
+ linkType: soft
+
"@pkgjs/parseargs@npm:^0.11.0":
version: 0.11.0
resolution: "@pkgjs/parseargs@npm:0.11.0"
@@ -5297,7 +5310,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "numerals-client@workspace:packages/numerals-client"
dependencies:
- "@numerals/eastern-arabic": "npm:0.0.1-next.4"
+ "@numerals/eastern-arabic": "npm:0.0.2"
+ "@numerals/mayan": "npm:0.0.1-next.2"
languageName: unknown
linkType: soft
@@ -5325,7 +5339,8 @@ __metadata:
"@emotion/react": "npm:^11.11.1"
"@emotion/styled": "npm:^11.11.0"
"@mui/joy": "npm:^5.0.0-beta.11"
- "@numerals/eastern-arabic": "npm:0.0.1-next.4"
+ "@numerals/eastern-arabic": "npm:0.0.2"
+ "@numerals/mayan": "npm:0.0.1-next.2"
"@types/node": "npm:^20.12.5"
"@types/react": "npm:^18"
"@types/react-dom": "npm:^18"