From a7bc40620fd9dbc157ee61749382885a4ba4e4ff Mon Sep 17 00:00:00 2001 From: kgryte Date: Thu, 19 Feb 2015 17:38:38 -0800 Subject: [PATCH] [UPDATE] fmt. support String objects. add dotfiles. --- .editorconfig | 11 ++++++++ .gitattributes | 1 + .gitignore | 2 +- .jshintignore | 14 ++++++++++ .jshintrc | 71 +++++++++++++++++++++++++++++++++++++++++++++++ .npmignore | 7 +++-- Makefile | 34 +++++++++++++++++++---- README.md | 34 +++++++++++++++-------- examples/index.js | 6 ++-- lib/index.js | 44 ++++++++++++++++------------- package.json | 8 ++++-- test/test.js | 26 +++++++++-------- 12 files changed, 202 insertions(+), 56 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .jshintignore create mode 100644 .jshintrc diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8e74bf3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.gitignore b/.gitignore index 35bd6c4..cc6c4b6 100644 --- a/.gitignore +++ b/.gitignore @@ -50,7 +50,7 @@ Desktop.ini # Node.js # ########### -node_modules/ +/node_modules/ # Matlab # ########## diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 0000000..3163c22 --- /dev/null +++ b/.jshintignore @@ -0,0 +1,14 @@ + +# Directories # +############### +build/ +reports/ +dist/ + +# Node.js # +########### +/node_modules/ + +# Git # +####### +.git* diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..d09f1fa --- /dev/null +++ b/.jshintrc @@ -0,0 +1,71 @@ +{ + "bitwise": false, + "camelcase": false, + "curly": true, + "eqeqeq": true, + "es3": false, + "forin": true, + "freeze": true, + "immed": true, + "indent": 4, + "latedef": "nofunc", + "newcap": true, + "noarg": true, + "noempty": false, + "nonbsp": true, + "nonew": true, + "plusplus": false, + "quotmark": "single", + "undef": true, + "unused": true, + "strict": true, + "maxparams": 10, + "maxdepth": 5, + "maxstatements": 100, + "maxcomplexity": false, + "maxlen": 1000, + "asi": false, + "boss": false, + "debug": false, + "eqnull": false, + "esnext": false, + "evil": false, + "expr": false, + "funcscope": false, + "globalstrict": false, + "iterator": false, + "lastsemic": false, + "laxbreak": false, + "laxcomma": false, + "loopfunc": false, + "maxerr": 1000, + "moz": false, + "multistr": false, + "notypeof": false, + "proto": false, + "scripturl": false, + "shadow": false, + "sub": true, + "supernew": false, + "validthis": false, + "noyield": false, + "browser": true, + "browserify": true, + "couch": false, + "devel": true, + "dojo": false, + "jasmine": false, + "jquery": false, + "mocha": true, + "mootools": false, + "node": true, + "nonstandard": false, + "prototypejs": false, + "qunit": false, + "rhino": false, + "shelljs": false, + "worker": false, + "wsh": false, + "yui": false, + "globals": {} +} \ No newline at end of file diff --git a/.npmignore b/.npmignore index 9bdd67a..9db298d 100644 --- a/.npmignore +++ b/.npmignore @@ -13,11 +13,12 @@ examples/ reports/ support/ test/ +benchmark/ # Node.js # ########### .npmignore -node_modules/ +/node_modules/ # Logs # ######## @@ -46,4 +47,6 @@ Desktop.ini # Utilities # ############# .jshintrc -.travis.yml \ No newline at end of file +.jshintignore +.travis.yml +.editorconfig diff --git a/Makefile b/Makefile index ab6f14b..d8fb6dd 100644 --- a/Makefile +++ b/Makefile @@ -8,22 +8,18 @@ NODE_ENV ?= test # NOTES # -NOTES ?= 'TODO|FIXME' +NOTES ?= 'TODO|FIXME|WARNING|HACK|NOTE' # MOCHA # -# Specify the test framework bin locations: MOCHA ?= ./node_modules/.bin/mocha _MOCHA ?= ./node_modules/.bin/_mocha - -# Specify the mocha reporter: MOCHA_REPORTER ?= spec # ISTANBUL # -# Istanbul configuration: ISTANBUL ?= ./node_modules/.bin/istanbul ISTANBUL_OUT ?= ./reports/coverage ISTANBUL_REPORT ?= lcov @@ -31,6 +27,12 @@ ISTANBUL_LCOV_INFO_PATH ?= $(ISTANBUL_OUT)/lcov.info ISTANBUL_HTML_REPORT_PATH ?= $(ISTANBUL_OUT)/lcov-report/index.html +# JSHINT # + +JSHINT ?= ./node_modules/.bin/jshint +JSHINT_REPORTER ?= ./node_modules/jshint-stylish/stylish.js + + # FILES # @@ -81,7 +83,8 @@ test-istanbul-mocha: node_modules NODE_ENV=$(NODE_ENV) \ NODE_PATH=$(NODE_PATH_TEST) \ $(ISTANBUL) cover \ - --dir $(ISTANBUL_OUT) --report $(ISTANBUL_REPORT) \ + --dir $(ISTANBUL_OUT) \ + --report $(ISTANBUL_REPORT) \ $(_MOCHA) -- \ --reporter $(MOCHA_REPORTER) \ $(TESTS) @@ -99,13 +102,30 @@ view-istanbul-report: +# LINT # + +.PHONY: lint lint-jshint + +lint: lint-jshint + +lint-jshint: node_modules + $(JSHINT) \ + --reporter $(JSHINT_REPORTER) \ + ./ + + + # NODE # # Installing node_modules: +.PHONY: install + install: npm install # Clean node: +.PHONY: clean-node + clean-node: rm -rf node_modules @@ -113,5 +133,7 @@ clean-node: # CLEAN # +.PHONY: clean + clean: rm -rf build diff --git a/README.md b/README.md index 82e095c..f6e845b 100644 --- a/README.md +++ b/README.md @@ -16,23 +16,35 @@ For use in the browser, use [browserify](https://github.com/substack/node-browse ## Usage -To use the module, - ``` javascript var isLowercase = require( 'validate.io-lowercase' ); +``` -console.log( isLowercase( 'hello' ) ); -// Returns true +#### isLowercase( value ) -console.log( isLowercase( 'Hello' ) ); -// Returns false +Validates if a `value` is a lowercase `string`. + +``` javascript +var value = 'beep'; + +var bool = isLowercase( value ); +// returns true ``` -Note: this method validates that a `value` is a `string`. +__Note__: this method validates that a `value` is a `string`. For all other types, the method returns `false`. + ## Examples +``` javascript +console.log( isLowercase( 'hello' ) ); +// returns true + +console.log( isLowercase( 'Hello' ) ); +// returns false +``` + To run the example code from the top-level application directory, ``` bash @@ -44,7 +56,7 @@ $ node ./examples/index.js ### Unit -Unit tests use the [Mocha](http://visionmedia.github.io/mocha) test framework with [Chai](http://chaijs.com) assertions. To run the tests, execute the following command in the top-level application directory: +Unit tests use the [Mocha](http://mochajs.org) test framework with [Chai](http://chaijs.com) assertions. To run the tests, execute the following command in the top-level application directory: ``` bash $ make test @@ -64,16 +76,16 @@ $ make test-cov Istanbul creates a `./reports/coverage` directory. To access an HTML version of the report, ``` bash -$ open reports/coverage/lcov-report/index.html +$ make view-cov ``` +--- ## License [MIT license](http://opensource.org/licenses/MIT). ---- ## Copyright Copyright © 2014. Athan Reines. @@ -95,4 +107,4 @@ Copyright © 2014. Athan Reines. [dev-dependencies-url]: https://david-dm.org/dev/validate-io/lowercase [github-issues-image]: http://img.shields.io/github/issues/validate-io/lowercase.svg -[github-issues-url]: https://github.com/validate-io/lowercase/issues \ No newline at end of file +[github-issues-url]: https://github.com/validate-io/lowercase/issues diff --git a/examples/index.js b/examples/index.js index 21baad7..0d476d3 100644 --- a/examples/index.js +++ b/examples/index.js @@ -1,7 +1,9 @@ +'use strict'; + var isLowercase = require( './../lib' ); console.log( isLowercase( 'hello' ) ); -// Returns true +// returns true console.log( isLowercase( 'Hello' ) ); -// Returns false \ No newline at end of file +// returns false \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index a508383..15375f7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -8,11 +8,11 @@ * * * NOTES: -* [1] +* [1] * * * TODO: -* [1] +* [1] * * * LICENSE: @@ -26,26 +26,30 @@ * */ -(function() { - 'use strict'; +'use strict'; - /** - * FUNCTION: isLowercase( value ) - * Validates if a value is a lowercase string. - * - * @param {String} value - value to be validated - * @returns {Boolean} boolean indicating whether value is a lowercase string - */ - function isLowercase( value ) { - if ( typeof value !== 'string' ) { - return false; - } - return ( value === value.toLowerCase() ); - } // end FUNCTION isLowercase() +// MODULES // +var isString = require( 'validate.io-string' ); - // EXPORTS // - module.exports = isLowercase; +// ISLOWERCASE // -})(); \ No newline at end of file +/** +* FUNCTION: isLowercase( value ) +* Validates if a value is a lowercase string. +* +* @param {String} value - value to be validated +* @returns {Boolean} boolean indicating whether value is a lowercase string +*/ +function isLowercase( value ) { + if ( isString( value ) ) { + return ( value.valueOf() === value.toLowerCase() ); + } + return false; +} // end FUNCTION isLowercase() + + +// EXPORTS // + +module.exports = isLowercase; diff --git a/package.json b/package.json index e97d6ed..51153ac 100644 --- a/package.json +++ b/package.json @@ -34,12 +34,16 @@ "bugs": { "url": "https://github.com/validate-io/lowercase/issues" }, - "dependencies": {}, + "dependencies": { + "validate.io-string": "^1.0.1" + }, "devDependencies": { "chai": "1.x.x", "mocha": "1.x.x", "coveralls": "^2.11.1", - "istanbul": "^0.3.0" + "istanbul": "^0.3.0", + "jshint": "^2.5.10", + "jshint-stylish": "^1.0.0" }, "licenses": [ { diff --git a/test/test.js b/test/test.js index 08b6cdc..3b9e346 100644 --- a/test/test.js +++ b/test/test.js @@ -1,3 +1,5 @@ +/* global require, describe, it */ +'use strict'; // MODULES // @@ -17,7 +19,6 @@ var expect = chai.expect, // TESTS // describe( 'validate.io-lowercase', function tests() { - 'use strict'; it( 'should export a function', function test() { expect( isLowercase ).to.be.a( 'function' ); @@ -25,24 +26,25 @@ describe( 'validate.io-lowercase', function tests() { it( 'should positively validate', function test() { assert.ok( isLowercase( 'hello' ) ); + assert.ok( isLowercase( new String( 'hello' ) ) ); }); it( 'should negatively validate', function test() { var values = [ - 5, - [], - true, - function(){}, - null, - {}, - NaN, - 'Hello', - undefined - ]; + 5, + [], + true, + function(){}, + null, + {}, + NaN, + 'Hello', + undefined + ]; for ( var i = 0; i < values.length; i++ ) { assert.ok( !isLowercase( values[i] ) ); } }); -}); \ No newline at end of file +});