Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@codecompose/words-to-numbers

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codecompose/words-to-numbers - npm Package Compare versions

Comparing version 1.6.0 to 2.0.0-0

src/compiler.js

5

index.d.ts

@@ -1,2 +0,5 @@

export declare function wordsToNumbers(text: string, options?: { fuzzy: boolean }): string | number | null;
export declare function wordsToNumbers(
text: string,
options?: { fuzzy: boolean }
): string | number | null;
export default wordsToNumbers;

52

package.json
{
"name": "@codecompose/words-to-numbers",
"description": "convert textual words to numbers with optional fuzzy text matching",
"version": "1.6.0",
"description": "Convert textual words to numbers with optional fuzzy text matching",
"version": "2.0.0-0",
"license": "MIT",
"options": {
"mocha": "--require scripts/mocha_runner src/**/__tests__/**/*.js"
},
"main": "dist/index.js",
"type": "module",
"main": "./src/index.js",
"types": "./index.d.ts",
"files": [
"dist",
"src",
"index.d.ts"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"start": "babel --watch --plugins \"transform-runtime\" src --ignore __tests__ --out-dir ./dist",
"prepare": "babel --plugins \"transform-runtime\" src --ignore __tests__ --out-dir ./dist",
"lint": "eslint ./src",
"lintfix": "eslint ./src --fix",
"testonly": "mocha $npm_package_options_mocha",
"test": "npm run lint && npm run testonly",
"test-watch": "npm run testonly -- --watch --watch-extensions js"
},
"devDependencies": {
"babel-cli": "6.x.x",
"babel-core": "6.x.x",
"babel-eslint": "4.x.x",
"babel-plugin-transform-runtime": "6.x.x",
"babel-polyfill": "6.x.x",
"babel-preset-es2015": "6.x.x",
"babel-preset-stage-2": "6.x.x",
"chai": "3.x.x",
"eslint": "1.7.x",
"eslint-plugin-babel": "2.x.x",
"its-set": "^1.1.5",
"mocha": "2.x.x",
"nodemon": "1.7.x"
"eslint": "8.56.0",
"eslint-config-0x80": "^0.0.0",
"prettier": "^3.2.5",
"typescript": "^5.3.3",
"vitest": "^1.3.1"
},

@@ -48,6 +26,10 @@ "author": "Finn Fitzsimons <hello@finn.works>",

"dependencies": {
"babel-runtime": "6.x.x",
"clj-fuzzy": "^0.3.2",
"clj-fuzzy": "^0.4.1",
"its-set": "^1.1.5"
},
"scripts": {
"lint": "eslint .",
"test": "vitest ./src",
"format": "prettier --write ."
}
}
}
# Words To Numbers
Convert words to numbers. Optionally fuzzy match the words to numbers.
This repository was forked from
[words-from-numbers](https://github.com/finnfiddle/words-to-numbers) because the
project seems abandoned. This fork:
- Fixes the manifest and makes it a pure ESM package
- Removes old dependencies and Babel transpilation
- Uses Vitest to replace old testing tools
- Upgrades clj-fuzzy to latest version
- Add prettier formatting
- Replace NPM with PNPM
- Add basis for Typescript conversion
I might convert the code to Typescript later. PRs are welcome.
## Usage
```

@@ -9,3 +23,5 @@ npm install words-to-numbers

If the whole string passed is a number then it will return a `Number` type otherwise it will return the original string with all instances of numbers replaced.
If the whole string passed is a number then it will return a `Number` type
otherwise it will return the original string with all instances of numbers
replaced.

@@ -17,18 +33,18 @@ TODO: Add functionality for parsing mixed numbers and words. PRs welcome.

```javascript
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
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
```

@@ -46,9 +62,12 @@

Uses [Jaro distance](http://yomguithereal.github.io/clj-fuzzy/javascript.html#jaro) to find the best match for the number words. Don't rely on this being completely accurate...
Uses
[Jaro distance](http://yomguithereal.github.io/clj-fuzzy/javascript.html#jaro)
to find the best match for the number words. Don't rely on this being completely
accurate...
```javascript
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("won huntred", { fuzzy: true }); //100
wordsToNumbers("too thousant and fiev", { fuzzy: true }); //2005
wordsToNumbers("tree millyon sefen hunderd and twinty sex", { fuzzy: true }); //3000726
```

@@ -59,5 +78,5 @@

```javascript
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("ten point five"); //10.5
wordsToNumbers("three point one four one five nine two six"); //3.1415926
```

@@ -68,43 +87,36 @@

```javascript
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
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
```
## Commonjs
## Implied Hundreds
```javascript
const { wordsToNumbers } = require('words-to-numbers');
wordsToNumbers('one hundred'); //100;
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
```
## Implied Hundreds
```javascript
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
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc