Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jimf committed Oct 10, 2015
1 parent eb4b3c1 commit b8204be
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 0 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
@@ -0,0 +1 @@
repo_token: qcOrGf8Cb6s3exIvwx1jf4mWVIZAsLsEh
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
coverage
node_modules
npm-debug.log
2 changes: 2 additions & 0 deletions .jshintignore
@@ -0,0 +1,2 @@
node_modules
coverage
27 changes: 27 additions & 0 deletions .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
}
5 changes: 5 additions & 0 deletions .travis.yml
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.10"
- "0.12"
script: "npm run validate"
19 changes: 19 additions & 0 deletions 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.
14 changes: 14 additions & 0 deletions 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;
};
38 changes: 38 additions & 0 deletions 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"
}
}
28 changes: 28 additions & 0 deletions 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();
});

0 comments on commit b8204be

Please sign in to comment.