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

number-to-words

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

number-to-words - npm Package Compare versions

Comparing version 1.2.3 to 1.2.4

.editorconfig

10

bower.json
{
"name": "number-to-words",
"description": "Contains some util methods for converting numbers into words, ordinal words and ordinal numbers.",
"version": "1.2.3",
"version": "1.2.4",
"main": "./numberToWords.min.js",

@@ -11,3 +11,5 @@ "authors": [

"Aleksey Pilyugin (https://github.com/pilyugin)",
"Jeremiah Hall (https://github.com/jeremiahrhall)"
"Jeremiah Hall (https://github.com/jeremiahrhall)",
"Adriano Melo (https://github.com/adrianomelo)",
"dmrzn (https://github.com/dmrzn)"
],

@@ -36,2 +38,6 @@ "homepage": "https://github.com/marlun78/number-to-words",

"spec",
".editorconfig",
".eslint",
".npmrc",
".prettierrc",
"gulpfile.js",

@@ -38,0 +44,0 @@ "wrapBundle.tmpl",

40

gulpfile.js

@@ -5,3 +5,2 @@ 'use strict';

var gulp = require('gulp');
var gutil = require('gulp-util');
var gulpPlugins = {

@@ -14,21 +13,24 @@ concat: require('gulp-concat'),

};
var log = require('fancy-log');
var license = require('uglify-save-license');
var pkg = require('./package.json');
var USE_STRICT_PATTERN = /(['"]use strict['"];?\n?)/g;
var REQUIRE_PATTERN = /((?:var |,)[^=]+=\s*require\([^\)]+\);?\n?)/g;
var EXPORT_PATTERN = /((?:module\.)?exports\s*=\s*[^,;]+;?\n?)/g;
function bundleTask() {
var USE_STRICT_PATTERN = /(['"]use strict['"];?\n?)/g;
var REQUIRE_PATTERN = /((?:var |,)[^=]+=\s*require\([^\)]+\);?\n?)/g;
var EXPORT_PATTERN = /((?:module\.)?exports\s*=\s*[^,;]+;?\n?)/g;
var files = [
'./src/isFinite.js',
'./src/makeOrdinal.js',
'./src/toOrdinal.js',
'./src/toWords.js',
'./src/toWordsOrdinal.js'
];
var files = [
'./src/maxSafeInteger.js',
'./src/isFinite.js',
'./src/isSafeNumber.js',
'./src/makeOrdinal.js',
'./src/toOrdinal.js',
'./src/toWords.js',
'./src/toWordsOrdinal.js'
];
gulp.task('default', ['build']);
gulp.task('build', ['bundle']);
gulp.task('bundle', function () {
return gulp.src(files)
.on('error', gutil.log)
.on('error', log.error)
.pipe(gulpPlugins.wrap({ src: 'wrapEach.tmpl' }))

@@ -42,5 +44,9 @@ .pipe(gulpPlugins.replace(USE_STRICT_PATTERN, ''))

// Minified version
.pipe(gulpPlugins.uglify())
.pipe(gulpPlugins.uglify({ output: { comments: license } }))
.pipe(gulpPlugins.rename('numberToWords.min.js'))
.pipe(gulp.dest('./'));
});
}
module.exports = {
build: gulp.parallel(bundleTask)
};
/*!
* Number-To-Words util
* @version v1.2.3
* @version v1.2.4
* @link https://github.com/marlun78/number-to-words
* @author Martin Eneqvist (https://github.com/marlun78)
* @contributors Aleksey Pilyugin (https://github.com/pilyugin),Jeremiah Hall (https://github.com/jeremiahrhall)
* @contributors Aleksey Pilyugin (https://github.com/pilyugin),Jeremiah Hall (https://github.com/jeremiahrhall),Adriano Melo (https://github.com/adrianomelo),dmrzn (https://github.com/dmrzn)
* @license MIT

@@ -16,4 +16,9 @@ */

// ========== file: /src/isFinite.js ==========
// ========== file: /src/maxSafeInteger.js ==========
var MAX_SAFE_INTEGER = 9007199254740991;
// ========== file: /src/isFinite.js ==========
// Simplified https://gist.github.com/marlun78/885eb0021e980c6ce0fb

@@ -25,2 +30,10 @@ function isFinite(value) {

// ========== file: /src/isSafeNumber.js ==========
function isSafeNumber(value) {
return typeof value === 'number' && Math.abs(value) <= MAX_SAFE_INTEGER;
}
// ========== file: /src/makeOrdinal.js ==========

@@ -87,5 +100,15 @@

var num = parseInt(number, 10);
if (!isFinite(num)) throw new TypeError('Not a finite number: ' + number + ' (' + typeof number + ')');
if (!isFinite(num)) {
throw new TypeError(
'Not a finite number: ' + number + ' (' + typeof number + ')'
);
}
if (!isSafeNumber(num)) {
throw new RangeError(
'Input is not a safe number, it’s either too large or too small.'
);
}
var str = String(num);
var lastTwoDigits = num % 100;
var lastTwoDigits = Math.abs(num % 100);
var betweenElevenAndThirteen = lastTwoDigits >= 11 && lastTwoDigits <= 13;

@@ -133,3 +156,13 @@ var lastChar = str.charAt(str.length - 1);

var num = parseInt(number, 10);
if (!isFinite(num)) throw new TypeError('Not a finite number: ' + number + ' (' + typeof number + ')');
if (!isFinite(num)) {
throw new TypeError(
'Not a finite number: ' + number + ' (' + typeof number + ')'
);
}
if (!isSafeNumber(num)) {
throw new RangeError(
'Input is not a safe number, it’s either too large or too small.'
);
}
words = generateWords(num);

@@ -136,0 +169,0 @@ return asOrdinal ? makeOrdinal(words) : words;

@@ -1,1 +0,9 @@

!function(){"use strict";function e(e){return!("number"!=typeof e||e!==e||e===1/0||e===-(1/0))}function t(e){return h.test(e)||s.test(e)?e+"th":u.test(e)?e.replace(u,"ieth"):a.test(e)?e.replace(a,n):e}function n(e,t){return d[t]}function o(t){var n=parseInt(t,10);if(!e(n))throw new TypeError("Not a finite number: "+t+" ("+typeof t+")");var o=String(n),r=n%100,i=r>=11&&13>=r,f=o.charAt(o.length-1);return o+(i?"th":"1"===f?"st":"2"===f?"nd":"3"===f?"rd":"th")}function r(n,o){var r,f=parseInt(n,10);if(!e(f))throw new TypeError("Not a finite number: "+n+" ("+typeof n+")");return r=i(f),o?t(r):r}function i(e){var t,n,o=arguments[1];return 0===e?o?o.join(" ").replace(/,$/,""):"zero":(o||(o=[]),0>e&&(o.push("minus"),e=Math.abs(e)),20>e?(t=0,n=x[e]):p>e?(t=e%v,n=M[Math.floor(e/v)],t&&(n+="-"+x[t],t=0)):y>e?(t=e%p,n=i(Math.floor(e/p))+" hundred"):c>e?(t=e%y,n=i(Math.floor(e/y))+" thousand,"):b>e?(t=e%c,n=i(Math.floor(e/c))+" million,"):g>e?(t=e%b,n=i(Math.floor(e/b))+" billion,"):m>e?(t=e%g,n=i(Math.floor(e/g))+" trillion,"):w>=e&&(t=e%m,n=i(Math.floor(e/m))+" quadrillion,"),o.push(n),i(t,o))}function f(e){var n=r(e);return t(n)}var l="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||this,h=/(hundred|thousand|(m|b|tr|quadr)illion)$/,s=/teen$/,u=/y$/,a=/(zero|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)$/,d={zero:"zeroth",one:"first",two:"second",three:"third",four:"fourth",five:"fifth",six:"sixth",seven:"seventh",eight:"eighth",nine:"ninth",ten:"tenth",eleven:"eleventh",twelve:"twelfth"},v=10,p=100,y=1e3,c=1e6,b=1e9,g=1e12,m=1e15,w=9007199254740992,x=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"],M=["zero","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"],z={toOrdinal:o,toWords:r,toWordsOrdinal:f};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=z),exports.numberToWords=z):l.numberToWords=z}();
/*!
* Number-To-Words util
* @version v1.2.4
* @link https://github.com/marlun78/number-to-words
* @author Martin Eneqvist (https://github.com/marlun78)
* @contributors Aleksey Pilyugin (https://github.com/pilyugin),Jeremiah Hall (https://github.com/jeremiahrhall),Adriano Melo (https://github.com/adrianomelo),dmrzn (https://github.com/dmrzn)
* @license MIT
*/
!function(){"use strict";var e="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||this,t=9007199254740991;function f(e){return!("number"!=typeof e||e!=e||e===1/0||e===-1/0)}function l(e){return"number"==typeof e&&Math.abs(e)<=t}var n=/(hundred|thousand|(m|b|tr|quadr)illion)$/,r=/teen$/,o=/y$/,i=/(zero|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)$/,s={zero:"zeroth",one:"first",two:"second",three:"third",four:"fourth",five:"fifth",six:"sixth",seven:"seventh",eight:"eighth",nine:"ninth",ten:"tenth",eleven:"eleventh",twelve:"twelfth"};function h(e){return n.test(e)||r.test(e)?e+"th":o.test(e)?e.replace(o,"ieth"):i.test(e)?e.replace(i,a):e}function a(e,t){return s[t]}var u=10,d=100,p=1e3,v=1e6,b=1e9,y=1e12,c=1e15,g=9007199254740992,m=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"],w=["zero","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"];function x(e,t){var n,r=parseInt(e,10);if(!f(r))throw new TypeError("Not a finite number: "+e+" ("+typeof e+")");if(!l(r))throw new RangeError("Input is not a safe number, it’s either too large or too small.");return n=function e(t){var n,r,o=arguments[1];if(0===t)return o?o.join(" ").replace(/,$/,""):"zero";o||(o=[]);t<0&&(o.push("minus"),t=Math.abs(t));t<20?(n=0,r=m[t]):t<d?(n=t%u,r=w[Math.floor(t/u)],n&&(r+="-"+m[n],n=0)):t<p?(n=t%d,r=e(Math.floor(t/d))+" hundred"):t<v?(n=t%p,r=e(Math.floor(t/p))+" thousand,"):t<b?(n=t%v,r=e(Math.floor(t/v))+" million,"):t<y?(n=t%b,r=e(Math.floor(t/b))+" billion,"):t<c?(n=t%y,r=e(Math.floor(t/y))+" trillion,"):t<=g&&(n=t%c,r=e(Math.floor(t/c))+" quadrillion,");o.push(r);return e(n,o)}(r),t?h(n):n}var M={toOrdinal:function(e){var t=parseInt(e,10);if(!f(t))throw new TypeError("Not a finite number: "+e+" ("+typeof e+")");if(!l(t))throw new RangeError("Input is not a safe number, it’s either too large or too small.");var n=String(t),r=Math.abs(t%100),o=11<=r&&r<=13,i=n.charAt(n.length-1);return n+(o?"th":"1"===i?"st":"2"===i?"nd":"3"===i?"rd":"th")},toWords:x,toWordsOrdinal:function(e){return h(x(e))}};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=M),exports.numberToWords=M):e.numberToWords=M}();
{
"name": "number-to-words",
"description": "Contains some util methods for converting numbers into words, ordinal words and ordinal numbers.",
"version": "1.2.3",
"version": "1.2.4",
"main": "./src",

@@ -10,22 +10,27 @@ "browser": "./numberToWords.min.js",

"Aleksey Pilyugin (https://github.com/pilyugin)",
"Jeremiah Hall (https://github.com/jeremiahrhall)"
"Jeremiah Hall (https://github.com/jeremiahrhall)",
"Adriano Melo (https://github.com/adrianomelo)",
"dmrzn (https://github.com/dmrzn)"
],
"devDependencies": {
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-uglify": "^1.4.0",
"gulp-util": "^3.0.7",
"gulp-wrap": "^0.11.0",
"http-server": "^0.9.0",
"jasmine": "^2.3.2",
"phantomjs-prebuilt": "^2.1.7"
"eslint": "5.3.0",
"fancy-log": "1.3.2",
"gulp": "4.0.0",
"gulp-concat": "2.6.1",
"gulp-rename": "1.4.0",
"gulp-replace": "1.0.0",
"gulp-uglify": "3.0.1",
"gulp-wrap": "0.14.0",
"http-server": "0.11.1",
"jasmine": "3.2.0",
"phantomjs-prebuilt": "2.1.16",
"uglify-save-license": "0.4.1"
},
"scripts": {
"build": "gulp build",
"test": "npm run test:node",
"lint": "node node_modules/eslint/bin/eslint.js .",
"test": "npm run lint && npm run test:node",
"test:node": "jasmine",
"test:phantom": "node_modules/phantomjs-prebuilt/bin/phantomjs node_modules/phantomjs-prebuilt/lib/phantom/examples/run-jasmine2.js 'http://localhost:3456/spec/'",
"test:server": "http-server ./ -p 3456"
"test:phantom": "phantomjs ./spec/phantom/run-jasmine3.js 'http://localhost:3456/spec/'",
"test:server": "http-server ./ -p 3456 -c-1"
},

@@ -32,0 +37,0 @@ "repository": {

@@ -62,7 +62,11 @@

##### Version 1.2.3 (final 1.x release)
- Bug fix in `isFinite` for Phantom and IE. Thanks to @jeremiahrhall.
##### Version 1.2.4 (final 1.x release)
- Bug fix in `toOrdinal`. When passed -11, -12 and -13 it returned an incorrect suffix ([#15](https://github.com/marlun78/number-to-words/issues/15)). Thanks to @dmrzn.
- `toOrdinal` and `toWords` now throws a more precise error when passed an unsafe number ([#13](https://github.com/marlun78/number-to-words/pull/13)). Thanks to @adrianomelo.
##### Version 1.2.3
- Bug fix in `isFinite` for Phantom and IE ([#10](https://github.com/marlun78/number-to-words/pull/10)). Thanks to @jeremiahrhall.
##### Version 1.2.2
- Bug fix in `toOrdinal`. Input 11, 12, and 13 now yelds the correct suffix. Thanks to @pilyugin.
- Bug fix in `toOrdinal`. Input 11, 12, and 13 now yields the correct suffix ([#8](https://github.com/marlun78/number-to-words/pull/8)). Thanks to @pilyugin.

@@ -69,0 +73,0 @@ ##### Version 1.2.1

'use strict';
var toOrdinal = typeof require !== 'undefined' ? require('../src/toOrdinal') : window.numberToWords.toOrdinal;
var MAX_SAFE_INTEGER = 9007199254740991;
describe('toOrdinal', function () {
var tests = [
{ input: -121, expect: '-121st' },
{ input: -13, expect: '-13th' },
{ input: -12, expect: '-12th' },
{ input: -11, expect: '-11th' },
{ input: -3, expect: '-3rd' },
{ input: -2, expect: '-2nd' },
{ input: -1, expect: '-1st' },

@@ -33,2 +40,14 @@ { input: 0, expect: '0th' },

tests.forEach(addTest);
it('should throw a RangeError if input is greater or lesser than MAX_SAFE_INTEGER', function() {
var unsafe = MAX_SAFE_INTEGER + 100;
expect(function() {
toOrdinal(unsafe);
}).toThrowError(/Input is not a safe number/);
expect(function() {
toOrdinal(-unsafe);
}).toThrowError(/Input is not a safe number/);
});
});
'use strict';
var MAX_SAFE_INTEGER = 9007199254740991;
var toWords = typeof require !== 'undefined' ? require('../src/toWords') : window.numberToWords.toWords;

@@ -91,4 +92,4 @@

{
input: 9007199254740992,
expect: 'nine quadrillion, seven trillion, one hundred ninety-nine billion, two hundred fifty-four million, seven hundred forty thousand, nine hundred ninety-two'
input: MAX_SAFE_INTEGER,
expect: 'nine quadrillion, seven trillion, one hundred ninety-nine billion, two hundred fifty-four million, seven hundred forty thousand, nine hundred ninety-one'
}

@@ -115,2 +116,14 @@ ];

});
it('should throw a RangeError if input is greater or lesser than MAX_SAFE_INTEGER', function() {
var unsafe = MAX_SAFE_INTEGER + 100;
expect(function() {
toWords(unsafe);
}).toThrowError(/Input is not a safe number/);
expect(function() {
toWords(-unsafe);
}).toThrowError(/Input is not a safe number/);
});
});

@@ -117,0 +130,0 @@

'use strict';
var isFinite = require('./isFinite');
var isSafeNumber = require('./isSafeNumber');

@@ -14,5 +15,15 @@ /**

var num = parseInt(number, 10);
if (!isFinite(num)) throw new TypeError('Not a finite number: ' + number + ' (' + typeof number + ')');
if (!isFinite(num)) {
throw new TypeError(
'Not a finite number: ' + number + ' (' + typeof number + ')'
);
}
if (!isSafeNumber(num)) {
throw new RangeError(
'Input is not a safe number, it’s either too large or too small.'
);
}
var str = String(num);
var lastTwoDigits = num % 100;
var lastTwoDigits = Math.abs(num % 100);
var betweenElevenAndThirteen = lastTwoDigits >= 11 && lastTwoDigits <= 13;

@@ -19,0 +30,0 @@ var lastChar = str.charAt(str.length - 1);

@@ -5,2 +5,3 @@ 'use strict';

var isFinite = require('./isFinite');
var isSafeNumber = require('./isSafeNumber');

@@ -36,3 +37,13 @@ var TEN = 10;

var num = parseInt(number, 10);
if (!isFinite(num)) throw new TypeError('Not a finite number: ' + number + ' (' + typeof number + ')');
if (!isFinite(num)) {
throw new TypeError(
'Not a finite number: ' + number + ' (' + typeof number + ')'
);
}
if (!isSafeNumber(num)) {
throw new RangeError(
'Input is not a safe number, it’s either too large or too small.'
);
}
words = generateWords(num);

@@ -39,0 +50,0 @@ return asOrdinal ? makeOrdinal(words) : words;

Sorry, the diff of this file is not supported yet

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