From b8204bef0d2625d1d4b4d2e2a29b6f597dfd666c Mon Sep 17 00:00:00 2001 From: Jim Fitzpatrick Date: Sat, 10 Oct 2015 10:28:51 -0400 Subject: [PATCH] Initial commit --- .coveralls.yml | 1 + .gitignore | 3 +++ .jshintignore | 2 ++ .jshintrc | 27 +++++++++++++++++++++++++++ .travis.yml | 5 +++++ LICENSE | 19 +++++++++++++++++++ index.js | 14 ++++++++++++++ package.json | 38 ++++++++++++++++++++++++++++++++++++++ test/index.test.js | 28 ++++++++++++++++++++++++++++ 9 files changed, 137 insertions(+) create mode 100644 .coveralls.yml create mode 100644 .gitignore create mode 100644 .jshintignore create mode 100644 .jshintrc create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 index.js create mode 100644 package.json create mode 100644 test/index.test.js diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..87464e2 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1 @@ +repo_token: qcOrGf8Cb6s3exIvwx1jf4mWVIZAsLsEh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..df9af16 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +coverage +node_modules +npm-debug.log diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 0000000..ba2a97b --- /dev/null +++ b/.jshintignore @@ -0,0 +1,2 @@ +node_modules +coverage diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..a7edf75 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,27 @@ +{ + "bitwise": false, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "forin": false, + "freeze": true, + "globalstrict": true, + "immed": true, + "indent": 4, + "latedef": true, + "maxcomplexity" : 6, + "maxdepth": 5, + "newcap": true, + "noarg": true, + "node": true, + "noempty": true, + "nonew": true, + "nonstandard": false, + "plusplus": true, + "quotmark": true, + "regexp": true, + "strict": true, + "trailing": true, + "undef": true, + "unused": true +} diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d195419 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: + - "0.10" + - "0.12" +script: "npm run validate" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f9238bb --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2015 Jim Fitzpatrick + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/index.js b/index.js new file mode 100644 index 0000000..454c7dd --- /dev/null +++ b/index.js @@ -0,0 +1,14 @@ +'use strict'; + +module.exports = function(store) { + var prop = function() { + if (arguments.length) { store = arguments[0]; } + return store; + }; + + prop.toJSON = function() { + return store; + }; + + return prop; +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..a0f8d03 --- /dev/null +++ b/package.json @@ -0,0 +1,38 @@ +{ + "name": "prop-factory", + "version": "1.0.0", + "description": "Getter-setter factory utility", + "main": "index.js", + "scripts": { + "coverage": "istanbul cover test/*.js", + "coveralls": "npm run coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", + "lint": "jshint .", + "test": "tape test/*.js", + "validate": "npm run lint && npm test && npm run coveralls" + }, + "repository": { + "type": "git", + "url": "https://github.com/jimf/prop-factory" + }, + "keywords": [ + "getter", + "setter", + "prop", + "property", + "factory", + "util", + "utility" + ], + "author": "Jim Fitzpatrick", + "license": "MIT", + "bugs": { + "url": "https://github.com/jimf/prop-factory/issues" + }, + "homepage": "https://github.com/jimf/prop-factory", + "devDependencies": { + "coveralls": "^2.11.2", + "istanbul": "^0.3.14", + "jshint": "^2.7.0", + "tape": "^4.0.0" + } +} diff --git a/test/index.test.js b/test/index.test.js new file mode 100644 index 0000000..7bf1001 --- /dev/null +++ b/test/index.test.js @@ -0,0 +1,28 @@ +'use strict'; + +var test = require('tape'), + prop = require('..'); + +test('prop factory', function(assert) { + assert.plan(5); + + var value = prop(); + assert.equal(value(), undefined, + 'should have default value of undefined'); + + assert.equal(value('a value'), 'a value', + 'should return argument that was passed)'); + + assert.equal(value(), 'a value', + 'should set value to argument passed'); + + value = prop('default value'); + assert.equal(value(), 'default value', + 'should allow default value to be specified'); + + var data = { foo: prop('bar') }; + assert.deepEqual(JSON.stringify(data), JSON.stringify({ foo: 'bar' }), + 'should be JSON-serializable'); + + assert.end(); +});