New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

words-to-numbers

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

words-to-numbers - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

42

dist/index.js

@@ -7,2 +7,6 @@ 'use strict';

var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _assign = require('babel-runtime/core-js/object/assign');

@@ -12,6 +16,2 @@

var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
exports.wordsToNumbers = wordsToNumbers;

@@ -31,3 +31,3 @@

var COUNT = {
var PRIMARY_COUNT = {
zero: 0,

@@ -72,3 +72,6 @@ a: 1,

nineteen: 19,
nineteenth: 19,
nineteenth: 19
};
var SECONDARY_COUNT = {
twenty: 20,

@@ -92,2 +95,4 @@ twentieth: 20,

var COUNT = (0, _assign2.default)({}, PRIMARY_COUNT, SECONDARY_COUNT);
var MAGNITUDE = {

@@ -116,7 +121,24 @@ hundred: 100,

var extractNumberRegions = function extractNumberRegions(words) {
var reduced = words.map(function (word) {
return NUMBER_WORDS.indexOf(clean(word)) > -1;
}).reduce(function (acc, isNumberWord, i) {
var numWords = words.length;
var numberWords = words.map(function (word) {
return NUMBER_WORDS.includes(clean(word));
});
var pointReached = false;
var reduced = numberWords.reduce(function (acc, isNumberWord, i) {
if (isNumberWord) {
if (!(0, _itsSet2.default)(acc.start)) acc.start = i;
if (words[i] === 'point') pointReached = true;
if (!(0, _itsSet2.default)(acc.start)) {
acc.start = i;
} else if ((0, _keys2.default)(PRIMARY_COUNT).includes(words[i - 1]) && (0, _keys2.default)(PRIMARY_COUNT).includes(words[i]) && !pointReached) {
acc.regions.push({ start: acc.start, end: i - 1 });
if (i === numWords - 1) {
acc.regions.push({ start: i, end: i });
} else {
acc.start = i;
}
}
} else if ((0, _itsSet2.default)(acc.start)) {

@@ -123,0 +145,0 @@ acc.regions.push({ start: acc.start, end: i - 1 });

{
"name": "words-to-numbers",
"description": "convert textual words to numbers with optional fuzzy text matching",
"version": "1.2.0",
"version": "1.2.1",
"license": "MIT",

@@ -6,0 +6,0 @@ "options": {

@@ -6,3 +6,2 @@ /* eslint-disable no-unused-expressions */

it('one hundred', () => {

@@ -74,2 +73,10 @@ expect(wtn('one hundred')).to.equal(100);

it('one two three', () => {
expect(wtn('one two three')).to.equal('1 2 3');
});
it('test one two three test', () => {
expect(wtn('test one two three test')).to.equal('test 1 2 3 test');
});
it('won huntred', () => {

@@ -76,0 +83,0 @@ expect(wtn('won huntred', {fuzzy: true})).to.equal(100);

@@ -6,3 +6,3 @@ // inpired by this answer on stackoverflow: http://stackoverflow.com/a/12014376 by http://stackoverflow.com/users/631193/javaandcsharp and thanks to @Greg Hewgill for the original, written in Python.

const COUNT = {
const PRIMARY_COUNT = {
zero: 0,

@@ -48,2 +48,5 @@ a: 1,

nineteenth: 19,
};
const SECONDARY_COUNT = {
twenty: 20,

@@ -67,2 +70,4 @@ twentieth: 20,

const COUNT = Object.assign({}, PRIMARY_COUNT, SECONDARY_COUNT);
const MAGNITUDE = {

@@ -91,7 +96,30 @@ hundred: 100,

const extractNumberRegions = words => {
const reduced = words
.map(word => NUMBER_WORDS.indexOf(clean(word)) > -1)
const numWords = words.length;
const numberWords = words
.map(word => NUMBER_WORDS.includes(clean(word)));
let pointReached = false;
const reduced = numberWords
.reduce((acc, isNumberWord, i) => {
if (isNumberWord) {
if (!itsSet(acc.start)) acc.start = i;
if (words[i] === 'point') pointReached = true;
if (!itsSet(acc.start)) {
acc.start = i;
}
else if (
Object.keys(PRIMARY_COUNT).includes(words[i - 1]) &&
Object.keys(PRIMARY_COUNT).includes(words[i]) &&
!pointReached
) {
acc.regions.push({start: acc.start, end: i - 1});
if (i === numWords - 1) {
acc.regions.push({start: i, end: i});
}
else {
acc.start = i;
}
}
}

@@ -98,0 +126,0 @@ else if (itsSet(acc.start)) {

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