pax_global_header00006660000000000000000000000064124455452310014517gustar00rootroot0000000000000052 comment=93c5a0f3fd09527c0cf37e2b8fe7b3a90e3bf9f1 individual-3.0.0/000077500000000000000000000000001244554523100136475ustar00rootroot00000000000000individual-3.0.0/.gitignore000066400000000000000000000000421244554523100156330ustar00rootroot00000000000000node_modules *.log *.err coverage individual-3.0.0/.travis.yml000066400000000000000000000001661244554523100157630ustar00rootroot00000000000000language: node_js node_js: - "0.8" - "0.10" - "0.11" before_install: npm i npm@latest -g script: npm run travis individual-3.0.0/LICENCE000066400000000000000000000020321244554523100146310ustar00rootroot00000000000000Copyright (c) 2012 Raynos. 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.individual-3.0.0/README.md000066400000000000000000000037721244554523100151370ustar00rootroot00000000000000# individual [![build status][build-png]][build] [![Coverage Status][cover-png]][cover] [![Davis Dependency status][dep-png]][dep] [![NPM][npm-png]][npm] [![browser support][test-png]][test] Garantueed individual values ## Example ```js var Individual = require("individual") var moduleCache = Individual("__MY_MODULE_CACHE", {}) // moduleCache is a individual variable local to this file. // It will always be the same value and defaults to {}. ``` This gives you a singleton value by a unique name (it stores it as a global variable). ## Use cases Your module has an internal cache. If your module is loaded twice, (someone didn't npm dedup and has two copies of your module) you would have two seperate caches that dont talk to each other. Best case your cache is less efficient. Worst case you have a cache because the native C++ extension you talk to crashes if you instantiate something twice. You need a garantuee that this value is an individual, there is only one of it. I use it myself because opening a SockJS websocket to the same URI twice causes an infinite loop. I need a garantuee that I have an individual value for the SockJS connection so I can see whether I already have an open connection. ## WHY GLOBALS >:( I can't imagine any other way to do it. I hate it too. Make a pull request if you know the real solution ## Installation `npm install individual` ## Contributors - Raynos ## MIT Licenced [build-png]: https://secure.travis-ci.org/Raynos/individual.png [build]: https://travis-ci.org/Raynos/individual [cover-png]: https://coveralls.io/repos/Raynos/individual/badge.png [cover]: https://coveralls.io/r/Raynos/individual [dep-png]: https://david-dm.org/Raynos/individual.png [dep]: https://david-dm.org/Raynos/individual [test-png]: https://ci.testling.com/Raynos/individual.png [test]: https://ci.testling.com/Raynos/individual [npm-png]: https://nodei.co/npm/individual.png?stars&downloads [npm]: https://nodei.co/npm/individual individual-3.0.0/index.js000066400000000000000000000004701244554523100153150ustar00rootroot00000000000000'use strict'; /*global window, global*/ var root = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : {}; module.exports = Individual; function Individual(key, value) { if (key in root) { return root[key]; } root[key] = value; return value; } individual-3.0.0/one-version.js000066400000000000000000000011711244554523100164510ustar00rootroot00000000000000'use strict'; var Individual = require('./index.js'); module.exports = OneVersion; function OneVersion(moduleName, version, defaultValue) { var key = '__INDIVIDUAL_ONE_VERSION_' + moduleName; var enforceKey = key + '_ENFORCE_SINGLETON'; var versionValue = Individual(enforceKey, version); if (versionValue !== version) { throw new Error('Can only have one copy of ' + moduleName + '.\n' + 'You already have version ' + versionValue + ' installed.\n' + 'This means you cannot install version ' + version); } return Individual(key, defaultValue); } individual-3.0.0/package.json000066400000000000000000000024561244554523100161440ustar00rootroot00000000000000{ "name": "individual", "version": "3.0.0", "description": "Garantueed individual values", "keywords": [], "author": "Raynos ", "repository": "git://github.com/Raynos/individual.git", "main": "index", "homepage": "https://github.com/Raynos/individual", "contributors": [ { "name": "Jake Verbaten" } ], "bugs": { "url": "https://github.com/Raynos/individual/issues", "email": "raynos2@gmail.com" }, "dependencies": {}, "devDependencies": { "coveralls": "^2.10.0", "istanbul": "^0.2.7", "run-browser": "^1.3.1", "tape": "^2.12.3" }, "licenses": [ { "type": "MIT", "url": "http://github.com/Raynos/individual/raw/master/LICENSE" } ], "scripts": { "test": "node test.js", "cover": "istanbul cover --report none --print detail test.js", "travis": "npm run cover -s && istanbul report lcov && ((cat coverage/lcov.info | coveralls) || exit 0)" }, "testling": { "files": "test.js", "browsers": [ "ie/8..latest", "firefox/16..latest", "firefox/nightly", "chrome/22..latest", "chrome/canary", "opera/12..latest", "opera/next", "safari/5.1..latest", "ipad/6.0..latest", "iphone/6.0..latest", "android-browser/4.2..latest" ] } } individual-3.0.0/test.js000066400000000000000000000007601244554523100151670ustar00rootroot00000000000000var test = require('tape'); var Individual = require('./index.js'); test('can create Individual', function (assert) { var obj = Individual('someName', 42); assert.equal(obj, 42); var obj2 = Individual('someName', 50); assert.equal(obj, 42); assert.end(); }); test('different keys', function (assert) { var obj = Individual('someName2', 42); var obj2 = Individual('otherName2', 50); assert.equal(obj, 42); assert.equal(obj2, 50); assert.end(); });