@codecompose/words-to-numbers

中文文档
2.0.1发布于 2024/03/08MITTypeScriptES Module近 30 天下载 8067

将文本单词转换为数字, 并带有可选模糊文本匹配

中文使用文档
文档目录7 节
  1. 使用量
  2. 基本实例
  3. 字符串中的多个数字
  4. 与模糊匹配
  5. 小数点
  6. 数字
  7. 隐蔽的上百人

单词到数字

这个寄存器来自 字从数 因为 项目似乎被放弃了.

代码库经过了现代化,在 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

版本与发布记录

@codecompose/words-to-numbers 共发布 4 个版本,首次发布于 2024/02/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.1latest2024/03/082 年前
2.0.02024/02/232 年前
2.0.0-0next2024/02/232 年前
1.6.02024/02/162 年前

关于 @codecompose/words-to-numbers 的常见问题

@codecompose/words-to-numbers 是什么?

将文本单词转换为数字, 并带有可选模糊文本匹配

如何安装 @codecompose/words-to-numbers?

在项目目录运行 npm install @codecompose/words-to-numbers,或使用 pnpm add / yarn add / bun add。

@codecompose/words-to-numbers 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@codecompose/words-to-numbers 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@codecompose/words-to-numbers 可以商用吗?

@codecompose/words-to-numbers 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@codecompose/words-to-numbers 的下载量有多少?

根据 npm 官方下载统计,@codecompose/words-to-numbers 在 2026/10/10 – 2026/11/08 这 30 天内被下载 8,067 次,日均约 269 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codecompose/words-to-numbers 还在维护吗?

最新版本 2.0.1 发布于 2024/03/08(2 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/02/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。