to-chinese-numeral
Advanced tools
Comparing version
"use strict"; | ||
function toChineseNumeral(num) { | ||
if (typeof num !== "number") { | ||
if (typeof num !== "number" || Number.isNaN(num)) { | ||
throw new TypeError("Not a number"); | ||
@@ -5,0 +5,0 @@ } |
{ | ||
"name": "to-chinese-numeral", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A function that takes a Number as its argument and returns a Chinese numeral string.", |
@@ -0,1 +1,3 @@ | ||
 [](https://npmjs.org/package/to-chinese-numeral) | ||
# to-chinese-numeral | ||
@@ -20,3 +22,3 @@ | ||
const num = toChineseNumeral(156) | ||
// num = | ||
// num = 一百五十六 | ||
} catch (error) { | ||
@@ -35,2 +37,2 @@ console.error(error.message) | ||
This package was inspired by a [challenge](https://www.codewars.com/kata/52608f5345d4a19bed000b31/train/javascript) on [codewars.com](https://www.codewars.com/) | ||
This package was inspired by a [challenge](https://www.codewars.com/kata/52608f5345d4a19bed000b31/train/javascript) on [codewars.com](https://www.codewars.com/). |
function toChineseNumeral(num: number) { | ||
if (typeof num !== "number") { | ||
if (typeof num !== "number" || Number.isNaN(num)) { | ||
throw new TypeError("Not a number") | ||
@@ -4,0 +4,0 @@ } |
@@ -39,2 +39,10 @@ const toChineseNumeral = require("../dist/index.js") | ||
expect(() => { | ||
toChineseNumeral(NaN) | ||
}).toThrow(TypeError) | ||
expect(() => { | ||
toChineseNumeral("") | ||
}).toThrow(TypeError) | ||
expect(() => { | ||
toChineseNumeral(56896325) | ||
@@ -41,0 +49,0 @@ }).toThrow(RangeError) |
15697
10.52%10
11.11%250
2.46%37
5.71%