单词到数字
这个寄存器来自 字从数 因为 项目似乎被放弃了.
代码库经过了现代化,在 2. 0 下发布,并进行了以下修改: 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码库 代码 代码库 代码库 代码库
- 修正无效的软件包列表
- 删除转写并完成 纯无害环境管理
- 添加打字符 类型推论
- 删除陈旧和陈旧的依赖关系
- 使用 Vitest 替换旧的测试工具
- 将 Clj- fuzy 升级到最新版本
- 添加更美的格式
- 使用 PNPM 作为软件包管理器
我以后可能会把代码转换成打字机 但代码质量很差 我不确定这是否值得 欢迎公关.
我还用PNPM取代了国家预防机制,这是不必要的,但仅仅是针对个人的 优先选择.
使用量
npm install @codecompose/words-to-numbers
如果整个字符串是一个数字,它就会返回一个 Number 类型
否则它会带着所有数字实例返回原始字符串
替换.
TODO: 为解析混合数字和单词添加功能. 公关欢迎.
基本实例
import wordsToNumbers from "words-to-numbers";
wordsToNumbers("one hundred"); //100
wordsToNumbers("one hundred and five"); //105
wordsToNumbers("one hundred and twenty five"); //125
wordsToNumbers("four thousand and thirty"); //4030
wordsToNumbers("six million five thousand and two"); //6005002
wordsToNumbers("a thousand one hundred and eleven"); //1111
wordsToNumbers("twenty thousand five hundred and sixty nine"); //20569
wordsToNumbers("five quintillion"); //5000000000000000000
wordsToNumbers("one-hundred"); //100
wordsToNumbers("one-hundred and five"); //105
wordsToNumbers("one-hundred and twenty-five"); //125
wordsToNumbers("four-thousand and thirty"); //4030
wordsToNumbers("six-million five-thousand and two"); //6005002
wordsToNumbers("a thousand, one-hundred and eleven"); //1111
wordsToNumbers("twenty-thousand, five-hundred and sixty-nine"); //20569
字符串中的多个数字
返回所有已替换实例的字符串 .
wordsToNumbers('there were twenty-thousand, five-hundred and sixty-nine X in the five quintillion Y')) // 'there were 20569 X in the 5000000000000000000 Y'
与模糊匹配
用途 雅罗距离 以找到数字词的最佳匹配。 不要完全依赖这个 准确...
import wordsToNumbers from "words-to-numbers";
wordsToNumbers("won huntred", { fuzzy: true }); //100
wordsToNumbers("too thousant and fiev", { fuzzy: true }); //2005
wordsToNumbers("tree millyon sefen hunderd and twinty sex", { fuzzy: true }); //3000726
小数点
import wordsToNumbers from "words-to-numbers";
wordsToNumbers("ten point five"); //10.5
wordsToNumbers("three point one four one five nine two six"); //3.1415926
数字
import wordsToNumbers from "words-to-numbers";
wordsToNumbers("first"); //1
wordsToNumbers("second"); //2
wordsToNumbers("third"); //3
wordsToNumbers("fourteenth"); //14
wordsToNumbers("twenty fifth"); //25
wordsToNumbers("thirty fourth"); //34
wordsToNumbers("forty seventh"); //47
wordsToNumbers("fifty third"); //53
wordsToNumbers("sixtieth"); //60
wordsToNumbers("seventy second"); //72
wordsToNumbers("eighty ninth"); //89
wordsToNumbers("ninety sixth"); //96
wordsToNumbers("one hundred and eighth"); //108
wordsToNumbers("one hundred and tenth"); //110
wordsToNumbers("one hundred and ninety ninth"); //199
隐蔽的上百人
wordsToNumbers("nineteen eighty four", { impliedHundreds: true }); //1984
wordsToNumbers("one thirty", { impliedHundreds: true }); //130
wordsToNumbers("six sixty two", { impliedHundreds: true }); //662
wordsToNumbers("ten twelve", { impliedHundreds: true }); //1012
wordsToNumbers("nineteen ten", { impliedHundreds: true }); //1910
wordsToNumbers("twenty ten", { impliedHundreds: true }); //2010
wordsToNumbers("twenty seventeen", { impliedHundreds: true }); //2017
wordsToNumbers("twenty twenty", { impliedHundreds: true }); //2020
wordsToNumbers("twenty twenty one", { impliedHundreds: true }); //2021
wordsToNumbers("fifty sixty three", { impliedHundreds: true }); //5063
wordsToNumbers("fifty sixty", { impliedHundreds: true }); //5060
wordsToNumbers("fifty sixty three thousand", { impliedHundreds: true }); //5063000
wordsToNumbers("one hundred thousand", { impliedHundreds: true }); //100000