Skip to content

Commit

Permalink
Lint- and build-only changes:
Browse files Browse the repository at this point in the history
Switched to Mocha/Karma for testing (from Nodeunit)
Using eslint
Using bower for CryptoJS dependencies
Builds sourcemaps
Smarter Gruntfile builds
  • Loading branch information
nicjansma committed Mar 26, 2015
1 parent 2abfb7a commit ff6d4a4
Show file tree
Hide file tree
Showing 36 changed files with 4,803 additions and 5,229 deletions.
43 changes: 43 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"rules": {
// enabled over default
"valid-jsdoc": [1, {
"requireReturn": false,
"prefer": {
"return": "returns"
}
}],
"guard-for-in": 2,
"no-div-regex": 2,
"no-else-return": 2,
"no-eq-null": 2,
"no-floating-decimal": 2,
"no-self-compare": 2,
"no-void": 2,
"radix": 2,
"wrap-iife": 2,
"no-mixed-requires": 2,
"no-new-require": 2,
"no-path-concat": 2,
"brace-style": [2, "1tbs", { "allowSingleLine": false }],
"comma-style": [2, "last"],
"consistent-this": [2, "that"],
"no-inline-comments": 2,
"no-lonely-if": 2,
"no-multiple-empty-lines": [1, {"max": 1}],
"no-nested-ternary": 2,
"space-after-function-name": [2, "never"],
"space-after-keywords": 1,
"space-before-blocks": 1,
"space-in-brackets": 1,
"space-in-parens": 1,
"space-unary-ops": 1,
"spaced-line-comment": 1,
"max-len": [1, 120, 4],

//
// Disabled rules
//
"consistent-return": 0
}
}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/node_modules
npm-debug.log
.project
.settings/
.settings/
/eslint.xml
/test/*.tap
/test/coverage
/bower_components
7 changes: 6 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
deps
.bowerrc
.eslintrc
.gitmodules
dist
test
.npmignore
.gitmodules
Gruntfile.js
bower.json
.travis.yml
karma.config.js
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
language: node_js
node_js:
- "0.12"
- "0.11"
- "0.10"
before_install: npm install -g grunt-cli
before_install:
- npm install -g grunt-cli bower
- bower install
173 changes: 115 additions & 58 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,138 @@
/*eslint-env node*/
module.exports = function(grunt) {
"use strict";

// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
pkg: grunt.file.readJSON("package.json"),
clean: {
options: {},
build: ["test/*.tap", "test/coverage"]
},
concat: {
options: {
stripBanners: false,
seperator: ";"
},
dist: {
src: [
"src/utils.js",
"src/domainnamerule.js",
"src/saltthepass.js"
],
dest: "dist/<%= pkg.name %>.js"
},
"dist-withdeps": {
src: [
"bower_components/cryptojslib/components/core.js",
"bower_components/cryptojslib/components/x64-core.js",
"bower_components/cryptojslib/components/sha1.js",
"bower_components/cryptojslib/components/sha512.js",
"bower_components/cryptojslib/components/sha3.js",
"bower_components/cryptojslib/components/md5.js",
"bower_components/cryptojslib/components/ripemd160.js",
"bower_components/cryptojslib/components/enc-base64.js",
"src/utils.js",
"src/domainnamerule.js",
"src/saltthepass.js"
],
dest: "dist/<%= pkg.name %>.withdeps.js"
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> v<%= pkg.version %> */\n'
banner: "/*! <%= pkg.name %> v<%= pkg.version %> */\n",
mangle: true,
sourceMap: true
},
build: {
files: {
'dist/<%= pkg.name %>.min.js': [
'src/utils.js',
'src/domainnamerule.js',
'src/saltthepass.js'
],
'dist/<%= pkg.name %>.withdeps.min.js': [
'deps/crypto-js/core.js',
'deps/crypto-js/x64-core.js',
'deps/crypto-js/sha1.js',
'deps/crypto-js/sha512.js',
'deps/crypto-js/sha3.js',
'deps/crypto-js/md5.js',
'deps/crypto-js/ripemd160.js',
'deps/crypto-js/enc-base64.js',
'src/utils.js',
'src/domainnamerule.js',
'src/saltthepass.js'
]
"dist/<%= pkg.name %>.min.js": ["dist/<%= pkg.name %>.js"],
"dist/<%= pkg.name %>.withdeps.min.js": ["dist/<%= pkg.name %>.withdeps.js"]
}
}
},
jshint: {
files: [ 'src/**/*.js', 'test/**/*.js' ],
options: {
bitwise: true,
camelcase: true,
curly: true,
eqeqeq: true,
forin: true,
immed: true,
indent: 4,
latedef: true,
newcap: true,
noempty: true,
nonew: true,
quotmark: true,
jquery: true,
undef: true,
unused: true,
strict: true,
trailing: true,
browser: true,
node: true,
white: false,
globals: {
define: true,
window: true
}
eslint: {
console: {
src: [
"Gruntfile.js",
"src/**/*.js",
"test/*.js"
]
},
build: {
options: {
"output-file": "eslint.xml",
"format": "jslint-xml",
"silent": true
},
src: [
"Gruntfile.js",
"src/**/*.js",
"test/*.js"
]
}
},
nodeunit: {
all: ['test/*.js']
mochaTest: {
test: {
options: {
reporter: "tap",
captureFile: "test/mocha.tap"
},
src: [
"src/saltthepass.js",
"test/*.js"
]
}
},
karma: {
options: {
singleRun: true,
colors: true,
configFile: "./karma.config.js",
preprocessors: {
"dist/saltthepass.withdeps.js": ["coverage"]
},
basePath: "./",
files: [
"bower_components/mocha/mocha.css",
"bower_components/mocha/mocha.js",
"bower_components/expect/index.js",
"dist/saltthepass.withdeps.js",
"test/test-*.js"
]
},
console: {
browsers: ["PhantomJS"],
frameworks: ["mocha"]
}
}
});

//
// Plugins
//
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-karma");
grunt.loadNpmTasks("grunt-mocha-test");
grunt.loadNpmTasks("gruntify-eslint");

//
// Tasks
//
grunt.registerTask('default', ['jshint', 'uglify']);
grunt.registerTask('test', ['nodeunit']);
grunt.registerTask('lint', ['uglify']);
grunt.registerTask('travis', ['nodeunit', 'jshint']);
grunt.registerTask('all', ['nodeunit', 'jshint', 'uglify']);
};
grunt.registerTask("test", ["mochaTest", "karma:console"]);

grunt.registerTask("lint", ["eslint:console"]);
grunt.registerTask("lint:build", ["eslint:build"]);

grunt.registerTask("build", ["concat", "uglify"]);

//
// Task Groups
//
grunt.registerTask("default", ["lint", "build"]);
grunt.registerTask("travis", ["test", "lint"]);
grunt.registerTask("all", ["clean", "lint:console", "build", "test"]);
};
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# saltthepass.js

v0.2.1
v0.2.2

Copyright 2013 Nic Jansma
Copyright 2015 Nic Jansma

http://nicj.net

Expand All @@ -12,7 +12,7 @@ Licensed under the MIT license

saltthepass.js is the algorithm that generates salted passwords for [SaltThePass.com](https://saltthepass.com/).

saltthepass.js can be used to build your own app, website or program to generate the same salted password as
saltthepass.js can be used to build your own app, website or program to generate the same salted passwords as
[saltthepass.com](https://saltthepass.com) does.

## Download
Expand All @@ -28,7 +28,7 @@ __Production (without CryptoJS):__ [saltthepass.min.js](https://github.com/nicja
__Production (with CryptoJS built-in):__ [saltthepass.withdeps.min.js](https://github.com/nicjansma/saltthepass.js/raw/master/dist/saltthepass.withdeps.min.js)
~ 8.5kb (minified / gzipped)

saltthepass.js is also available as the [npm saltthepass module](https://npmjs.org/package/saltthepass). You can install
saltthepass.js is also available as the [npm saltthepass module](https://npmjs.org/package/saltthepass). You can install it
using Node Package Manager (npm):

npm install saltthepass
Expand All @@ -40,9 +40,10 @@ Please see [SaltThePass.com](https://saltthepass.com/) for a description of how/
### Requirements

saltthepass.js depends on the [CryptoJS library](http://code.google.com/p/crypto-js/). SaltThePass is tested to work
with CryptoJS v3.1.2, which is included in the `deps/crypto-js` folder.
with CryptoJS v3.1.2, which can be installed via the bower `cryptojslib` package.

You will need to load the following CryptoJS modules in this order prior to loading saltthepass.js:
You will need to load the following CryptoJS modules in this order prior to using `saltthepass.js`, if not using one of
the pre-built versions in `dist/` such as `saltthepass.withdeps.js` or `saltthepass.withdeps.min.js`:

* crypto-js/core
* crypto-js/x64-core
Expand All @@ -55,7 +56,11 @@ You will need to load the following CryptoJS modules in this order prior to load

### Browser - Development Versions

To use un-minified versions of saltthepass.js in the browser, you need to load the files in this order:
To use un-minified versions of saltthepass.js in the browser, you need to have the `cryptojslib` bower package:

bower install cryptojslib

Then load the files in this order:

```html
<script type="text/javascript" src="deps/crypto-js/core.js"></script>
Expand All @@ -71,6 +76,13 @@ To use un-minified versions of saltthepass.js in the browser, you need to load t
<script type="text/javascript" src="src/saltthepass.js"></script>
```

The file `dist/saltthepass.withdeps.js` is a single JavaScript file with all of the above components in the correct
order, so it can be used instead if desired:

```html
<script type="text/javascript" src="dist/saltthepass.withdeps.js"></script>
```

### Browser - Minified Versions

There are two minified versions of saltthepass.js provided in the `dist/` folder:
Expand Down Expand Up @@ -319,4 +331,4 @@ The tests can also be run in a web browser:
* v0.1.0 - 2013-05-22: Initial version
* v0.2.0 - 2013-07-16: `DomainNameRule` and `standardizeDomain()` added.
* v0.2.1 - 2013-07-17: `DomainNameRule.validregex` added
* v0.2.2 - 2013-07-17: `DomainNameRule.validregex` and `DomainNameRule.regex` are case-sensitive now
* v0.2.2 - 2013-07-17: `DomainNameRule.validregex` and `DomainNameRule.regex` are case-sensitive now
33 changes: 33 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "saltthepass.js",
"version": "0.2.2",
"authors": [
"Nic Jansma <nic@nicj.net>"
],
"description": "SaltThePass.com algorithm",
"main": "dist/saltthepass.js",
"moduleType": [
"amd",
"globals",
"node"
],
"keywords": [
"saltthepass"
],
"license": "MIT",
"homepage": "http://github.com/nicjansma/saltthepass.js",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"cryptojslib": "~3.1.2"
},
"devDependencies": {
"mocha": "~2.2.1",
"expect": "~0.3.1"
}
}
Loading

0 comments on commit ff6d4a4

Please sign in to comment.