diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 49c96c9..0000000 --- a/.eslintrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "parser": "babel-eslint", - "env": { - "browser": true, - "node": true, - "es6": true - }, - "rules": { - "quotes": [2, "single"] - } -} diff --git a/.gitignore b/.gitignore index 7f8def1..e235d8b 100644 --- a/.gitignore +++ b/.gitignore @@ -21,5 +21,8 @@ node_modules bower_components .idea +*.sublime* .zuulrc + + diff --git a/.npmignore b/.npmignore index 58b9334..270286e 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,5 @@ -test.js -bower.json **/.* -gulpfile.babel.js +test/ +bower.json +node_modules/ +*.log diff --git a/.travis.yml b/.travis.yml index 46895ba..aa1d99c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,12 @@ -language: node_js +language: node_js' matrix: include: - - node_js: "iojs" - env: SAUCELABS=false - - node_js: "0.10" - env: SAUCELABS=false - - node_js: "0.12" + - node_js: "stable" env: SAUCELABS=true + - node_js: "4" + env: SAUCELABS=true + - node_js: "0.12" + env: SAUCELABS=false cache: directories: - node_modules @@ -22,7 +22,6 @@ deploy: secure: QG0di2PIjXr0V1hQupe9HRbiE7OvB/XUt7Jjc6tqKTJbF7KFKPqE1fZBPwdJk76Q8jp2E+2XTWFKg/Y2H681XL0ehEWHMf14VxSLVNCjNLyiTM5EgbryW5emHLeSbQZDQ8TMK84u+ZPmgnNp+3QuuOerDqpOEQMJX4SxyWFDCLfUSBF2fLOAbjiyJy6cbjKuAjM5SN+fQ0l4uOmOE8pQhpryjlmjniOh1EjQTGCtR1G4NRQnWvon7p5cgdMyXhioXOT5UjFFAeqUrDaNycLf8ufPOzsCdVOZC6YUFb90AFlrSEsVO9wA9hoCAGUb9hU7fK6JabLD7AxNVlzGUYP0r0Oge+QWmNlgs94f5FZb7Uvho91aTYl5JaHMra2OoBvCaym8kcUFqgdAXWMgZod1wwg138z6vhqqhU5p8X3VgQuAe1ztly053Rm9s8VbkxzKWrBPJNVlfEvmQKAHkZklrDk7kYcCz2k5YGy8qV+vzfUH/5jVhJllTxo9q21BWvPHed6y6PSZvZkoCCFsL66jHdjREyeH8J7MQfaB8aDtqQJ1eXfjTWMvKGQRONUHt1x7q4TiGs8CtuGW1ZAPiNoZGCqPbLBcHLlPY3kwhwqfSv3MP8U1PhT6lbnZrI6IkvUWegivZDmYCV11fYvEB3pkZ6ZdOKOXp6EQVSqSfV0jUqw= on: tags: true - node_js: "0.12" repo: leodido/luhn.js notifications: email: false diff --git a/.zuul.yml b/.zuul.yml index 40225ce..363cfef 100644 --- a/.zuul.yml +++ b/.zuul.yml @@ -23,8 +23,3 @@ browsers: capabilities: recordScreenshots: false videoUploadOnPass: false - -browserify: - - transform: - name: babelify - optional: runtime diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..65ffe17 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# 1.1.0 + +* Support for node.js 0.12, 4 and latest stable +* Half the sizes of the bundles + (production: ~350 bytes, development: ~700 bytes) +* Location of bundles changed to directory **lib/** +* Tests for ~ 50 browsers + +# 1.0.1 + +* Initial release +* UMD bundle +* Support for node.js 0.10, 0.12 and io.js +* Tests for ~ 50 browsers diff --git a/LICENSE b/LICENSE index fa712e2..fd1ff38 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Leonardo Di Donato +Copyright (c) 2016 Leonardo Di Donato Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index d1b916e..e325e68 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,11 @@ This algorithm (also known as [Luhn formula](https://en.wikipedia.org/wiki/Luhn_ ### Install -~1KB. +**~ 500 bytes**. -[UMD](https://github.com/umdjs/umd) builds for development - **index.js** and **index.js.map** - and production - **index.min.js** - available. +[UMD](https://github.com/umdjs/umd) bundles for development - **[index.js](lib/index.js)** with sourcemap **[index.js.map](lib/index.js.map)** - and production - **[index.min.js](lib/index.min.js)** - available. -So it's installable both on **node** and/or for **browsers**. +So it's installable both on **node** and/or for **browsers**, with almost every module system existing (e.g. AMD, CJS). ``` $ npm install luhn-alg @@ -43,7 +43,7 @@ $ true ### Browsers -Include the UMD build (e.g., **index.min.js**) and you'll have a **luhn** function on the window/global scope. +Include the bundle (e.g., **index.min.js**) and you'll have a **luhn** function on the window/global scope. Or use CommonJS, AMD, WTFYW etc. @@ -52,7 +52,7 @@ Tests This project is fully unit tested on: -* node.js 0.10, node.js 0.12, io.js +* node.js 0.12, node.js 4, latest node.js stable release * about 50 [browser versions](https://github.com/leodido/luhn.js/blob/master/.zuul.yml) Credits @@ -63,4 +63,4 @@ Credits --- -[![Analytics](https://ga-beacon.appspot.com/UA-49657176-1/luhn.js)](https://github.com/igrigorik/ga-beacon) +[![Analytics](https://ga-beacon.appspot.com/UA-49657176-1/luhn.js?flat)](https://github.com/igrigorik/ga-beacon) diff --git a/bower.json b/bower.json index 8e5f5df..16d78fe 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "luhn-alg", - "main": "index.js", - "version": "1.0.1", + "main": "lib/index.js", + "version": "1.1.0", "authors": [ "Leo Di Donato " ], diff --git a/index.js b/index.js deleted file mode 100644 index b285803..0000000 --- a/index.js +++ /dev/null @@ -1,28 +0,0 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.luhn = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0; - }; -})([0, 2, 4, 6, 8, 1, 3, 5, 7, 9]); - -module.exports = exports['default']; - -},{}]},{},[1])(1) -}); - - -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 5e663cf..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["node_modules/browserify/node_modules/browser-pack/_prelude.js","src.js"],"names":[],"mappings":"AAAA;ACAA,YAAY,CAAC;;;;;;qBAEE,CAAA,UAAS,KAAK,EAAE;AAC7B,SAAO,UAAU,MAAM,EAAE;AACvB,QAAI,GAAG,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC;QAClC,GAAG,GAAG,CAAC;QACP,GAAG,GAAG,CAAC,CAAC;;AAEV,WAAO,GAAG,EAAE,EAAE;AACZ,SAAG,IAAI,EAAE,GAAG,IAAI,CAAC,CAAA,AAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;KACrE;;AAED,WAAO,GAAG,GAAG,EAAE,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC;GAClC,CAAC;CACH,CAAA,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC","file":"index.js","sourceRoot":"/source/","sourcesContent":["(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o 0;\n };\n}([0, 2, 4, 6, 8, 1, 3, 5, 7, 9]);\n"]} \ No newline at end of file diff --git a/index.min.js b/index.min.js deleted file mode 100644 index 744921d..0000000 --- a/index.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.luhn=e()}}(function(){return function e(n,r,t){function o(u,i){if(!r[u]){if(!n[u]){var d="function"==typeof require&&require;if(!i&&d)return d(u,!0);if(f)return f(u,!0);var l=new Error("Cannot find module '"+u+"'");throw l.code="MODULE_NOT_FOUND",l}var p=r[u]={exports:{}};n[u][0].call(p.exports,function(e){var r=n[u][1][e];return o(r?r:e)},p,p.exports,e,n,r,t)}return r[u].exports}for(var f="function"==typeof require&&require,u=0;u0}}([0,2,4,6,8,1,3,5,7,9]),n.exports=r["default"]},{}]},{},[1])(1)}); \ No newline at end of file diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..28dd0a6 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,26 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define('luhn', factory) : + (global.luhn = factory()); +}(this, function () { 'use strict'; + + var luhn = function luhn(array) { + return function (number) { + var len = number ? number.length : 0, + bit = 1, + sum = 0; + + while (len--) { + sum += !(bit ^= 1) ? parseInt(number[len], 10) : array[number[len]]; + } + + return sum % 10 === 0 && sum > 0; + }; + }; + + var index = luhn([0, 2, 4, 6, 8, 1, 3, 5, 7, 9]); + + return index; + +})); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/index.js.map b/lib/index.js.map new file mode 100644 index 0000000..030b8e4 --- /dev/null +++ b/lib/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["'use strict';\n\nconst luhn = array => {\n return number => {\n let len = number ? number.length : 0,\n bit = 1,\n sum = 0;\n\n while (len--) {\n sum += !(bit ^= 1) ? parseInt(number[len], 10) : array[number[len]];\n }\n\n return sum % 10 === 0 && sum > 0;\n };\n}\n\nexport default luhn([0, 2, 4, 6, 8, 1, 3, 5, 7, 9]);\n"],"names":[],"mappings":";;;;;;EAEA,IAAM,OAAO,SAAP,IAAO,QAAS;AACpB,EAAA,SAAO,kBAAU;AACf,EAAA,QAAI,MAAM,SAAS,OAAO,MAAP,GAAgB,CAAzB;UACR,MAAM,CAAN;UACA,MAAM,CAAN,CAHa;;AAKf,EAAA,WAAO,KAAP,EAAc;AACZ,EAAA,aAAO,EAAE,OAAO,CAAP,CAAF,GAAc,SAAS,OAAO,GAAP,CAAT,EAAsB,EAAtB,CAAd,GAA0C,MAAM,OAAO,GAAP,CAAN,CAA1C,CADK;OAAd;;AAIA,EAAA,WAAO,MAAM,EAAN,KAAa,CAAb,IAAkB,MAAM,CAAN,CATV;KAAV,CADa;GAAT;;AAcb,cAAe,KAAK,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,EAA4B,CAA5B,CAAL,CAAf;;;;"} \ No newline at end of file diff --git a/lib/index.min.js b/lib/index.min.js new file mode 100644 index 0000000..e8362b9 --- /dev/null +++ b/lib/index.min.js @@ -0,0 +1 @@ +!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define("luhn",n):e.luhn=n()}(this,function(){"use strict";var e=function(e){return function(n){for(var t=n?n.length:0,o=1,u=0;t--;)u+=(o^=1)?e[n[t]]:parseInt(n[t],10);return u%10===0&&u>0}},n=e([0,2,4,6,8,1,3,5,7,9]);return n}); \ No newline at end of file diff --git a/package.json b/package.json index 6b1be0b..815972a 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "luhn-alg", "description": "Fastest implementation of the Luhn algorithm", - "version": "1.0.1", - "main": "index.js", - "jsnext:main": "src.js", + "version": "1.1.0", + "main": "lib/index.js", + "jsnext:main": "src/src.js", "author": { "name": "Leo Di Donato", "email": "leodidonato@gmail.com", @@ -19,26 +19,18 @@ "url": "http://github.com/leodido/luhn.js/issues" }, "devDependencies": { - "babel": "^5.5.6", - "babel-eslint": "^3.1.15", - "babel-runtime": "^5.5.8", - "babelify": "^6.1.2", - "browserify": "^10.2.4", - "chai": "^3.0.0", - "del": "^1.2.0", - "eslint": "^0.23.0", - "gulp": "gulpjs/gulp.git#4.0", - "gulp-bump": "^0.3.1", - "gulp-cli": "gulpjs/gulp-cli#4.0", - "gulp-rename": "^1.2.2", - "gulp-sourcemaps": "^1.5.2", - "gulp-uglify": "^1.2.0", - "gulp-util": "^3.0.5", - "mocha": "^2.2.5", - "phantomjs": "^1.9.17", - "vinyl-buffer": "^1.0.0", - "vinyl-source-stream": "^1.1.0", - "zuul": "^3.0.0" + "babel-eslint": "^5.0.0", + "babel-preset-es2015-rollup": "^1.1.1", + "del-cli": "^0.2.0", + "eslint": "^2.2.0", + "eslint-config-defaults": "^9.0.0", + "estraverse-fb": "^1.3.1", + "mocha": "^2.4.5", + "phantomjs": "^2.1.3", + "rollup": "^0.25.4", + "rollup-plugin-babel": "^2.4.0", + "uglify-js": "^2.6.2", + "zuul": "^3.9.0" }, "keywords": [ "luhn algorithm", @@ -60,10 +52,35 @@ "test": "([ \"${SAUCELABS}\" = true ] && npm run testz) || true", "testz": "./node_modules/.bin/zuul --no-coverage --concurrency 5 -- test.js", "testp": "./node_modules/.bin/zuul --phantom -- test.js", - "testl": "./node_modules/.bin/zuul --local 8080 --open -- test.js", - "prepublish": "./node_modules/.bin/gulp production" + "testl": "./node_modules/.bin/zuul --local 8080 --open -- test/*.js", + + "lint": "./node_modules/.bin/eslint src/*.js test/*.js", + "clean": "./node_modules/.bin/del-cli lib/", + "prebundle": "npm run clean", + "bundle": "./node_modules/.bin/rollup -c rollup.config.js", + "predist": "npm run bundle", + "dist": "./node_modules/.bin/uglifyjs -c -m -o lib/index.min.js -- lib/index.js", + "prepublish": "" }, "engines": { - "node": ">=0.10" + "node": ">=0.12" + }, + "eslintConfig": { + "extends": "eslint-config-defaults", + "parser": "babel-eslint", + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" + }, + "env": { + "es6": true, + "mocha": true + }, + "rules": { + "quotes": [ + 2, + "single" + ] + } } } diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..614b46b --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,17 @@ +'use strict' + +import babel from 'rollup-plugin-babel'; + +export default { + entry: 'src/index.js', + format: 'umd', + moduleName: 'luhn', + moduleId: 'luhn', + sourceMap: true, + plugins: [ + babel({ + exclude: 'node_modules/**' + }) + ], + dest: 'lib/index.js' +} diff --git a/src/.babelrc b/src/.babelrc new file mode 100644 index 0000000..3bff21e --- /dev/null +++ b/src/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": [ "es2015-rollup" ] +} diff --git a/src.js b/src/index.js similarity index 69% rename from src.js rename to src/index.js index 9f7015b..bfa29da 100644 --- a/src.js +++ b/src/index.js @@ -1,7 +1,7 @@ 'use strict'; -export default function(array) { - return function (number) { +const luhn = array => { + return number => { let len = number ? number.length : 0, bit = 1, sum = 0; @@ -12,4 +12,6 @@ export default function(array) { return sum % 10 === 0 && sum > 0; }; -}([0, 2, 4, 6, 8, 1, 3, 5, 7, 9]); +} + +export default luhn([0, 2, 4, 6, 8, 1, 3, 5, 7, 9]); diff --git a/test.js b/test/index.js similarity index 96% rename from test.js rename to test/index.js index 4a8ceaa..a00e9be 100644 --- a/test.js +++ b/test/index.js @@ -1,6 +1,6 @@ 'use strict'; -/* global describe:false, it:false */ + import { expect } from 'chai'; import luhn from './src';