forked from dreamerslab/node.secret
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4b9f211
Showing
7 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
*.sock | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.DS_Store | ||
*.sock | ||
node_modules | ||
support | ||
test | ||
examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 1.0.0 / 2011-07-05 | ||
|
||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Secret | ||
|
||
An `in memory key value store module` for node.js | ||
|
||
|
||
|
||
## Description | ||
|
||
[Global objects are evil in javascript](http://bit.ly/e6DUOi). They are easily to be overwritten, especially when you mix your code with others. Secret provides a way to store your data or functions that can be used later. It works cross modules and files without creating globals. | ||
|
||
|
||
|
||
## Requires | ||
|
||
- node >= 0.4.x | ||
|
||
|
||
|
||
## Installation | ||
|
||
npm install secret | ||
|
||
|
||
|
||
## Usage | ||
|
||
> Require module. | ||
var secret = require( 'secret' ); | ||
|
||
> Store data to be called or withdraw later.. | ||
secret.set( 'age', 17 ); | ||
secret.set( 'name', 'ben' ); | ||
secret.set( 'do-some-thing', function( arg1, arg2, arg3 ){ | ||
// do something here | ||
}); | ||
|
||
> Get stored data, it works cross modules and files. | ||
var age = secret.get( 'age' ); | ||
|
||
> Calling a stored function. | ||
// You can pass as many arguments as you wish | ||
secret.execute( 'do-some-thing', arg1, arg2, arg3 ... ); | ||
|
||
> Remove stored data. | ||
secret.remove( 'age' ); | ||
|
||
|
||
|
||
## License | ||
|
||
(The MIT License) | ||
|
||
Copyright (c) 2011 dreamerslab <ben@dreamerslab.com> | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./lib/secret'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/*! | ||
* Secret | ||
* Copyright(c) 2011 Ben Lin <ben@dreamerslab.com> | ||
* MIT Licensed | ||
* | ||
* @fileoverview | ||
* An`in memory key value store module` for node.js. | ||
* With Secret you can store data in a clousure and use it later without creating globals. | ||
*/ | ||
|
||
|
||
|
||
/** | ||
* @private | ||
* @namespace A namespace to store data. | ||
*/ | ||
var trunk = {}; | ||
|
||
|
||
|
||
/** | ||
* @public | ||
*/ | ||
module.exports = { | ||
|
||
version : '1.0.0', | ||
|
||
|
||
|
||
/** | ||
* Store data in a closure to be called or withdraw later. | ||
* @this {Secret} | ||
* @param {String} key Data key. | ||
* @param {String|Number|Array|Object|Function} value Data value. | ||
* @return {this} Return `this` to enable chaining. | ||
* @example | ||
* | ||
* var secret = require( 'secret' ); | ||
* secret.set( 'age', 17 ); | ||
* secret.set( 'name', 'ben' ); | ||
* secret.set( 'do-some-thing', function( arg1, arg2, arg3 ){ | ||
* // do something here | ||
* }); | ||
*/ | ||
set : function( key, value ){ | ||
// data can be overwritten | ||
trunk[ key ] = value; | ||
|
||
return this; | ||
}, | ||
|
||
|
||
|
||
/** | ||
* Get stored data. | ||
* @this {Secret} | ||
* @param {String} key Data key. | ||
* @return {data|false} Return the stored data if available. | ||
* @example | ||
* | ||
* var secret = require( 'secret' ); | ||
* secret.get( 'age' ); | ||
*/ | ||
get : function( key ){ | ||
// make sure the calling out name exist | ||
if( trunk[ key ] !== undefined ){ | ||
return trunk[ key ]; | ||
} | ||
return false; | ||
}, | ||
|
||
|
||
|
||
/** | ||
* Calling a stored function. | ||
* @this {Secret} | ||
* @param {String} arguments[ 0 ] Data key. | ||
* @param {String|Number|Array|Object|Function} [arguments[ 1 ]] Arguments to be passed to the stored function. | ||
* @return {this} Return `this` to enable chaining. | ||
* @example | ||
* | ||
* var secret = require( 'secret' ); | ||
* // You can pass as many arguments as you wish | ||
* secret.execute( 'do-some-thing', arg1, arg2, arg3 ... ); | ||
*/ | ||
execute : function(){ | ||
var key, tmp; | ||
|
||
key = [].shift.call( arguments ); | ||
// make sure the calling function exist | ||
if( trunk[ key ] !== undefined ){ | ||
|
||
// execute store function | ||
tmp = trunk[ key ]; | ||
if( Object.prototype.toString.call( tmp ) === '[object Function]' ){ | ||
tmp.apply( this, arguments ); | ||
}else{ | ||
throw 'Secret error: on action "execute" - "' + key + '" is not a function'; | ||
} | ||
} | ||
|
||
return this; | ||
}, | ||
|
||
|
||
|
||
/** | ||
* Remove stored data. | ||
* @this {Secret} | ||
* @param {String} key Data key. | ||
* @return {this} Return `this` to enable chaining. | ||
* @example | ||
* | ||
* var secret = require( 'secret' ); | ||
* secret.remove( 'age' ); | ||
*/ | ||
remove : function( key ){ | ||
delete trunk[ key ]; | ||
|
||
return this; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "secret" | ||
, "version": "1.0.0" | ||
, "description": "An `in memory key value store module` for node.js" | ||
, "keywords": [ "secret", "key value", "global" ] | ||
, "author": "dreamerslab <ben@dreamerslab.com>" | ||
, "dependencies": {} | ||
, "main": "index" | ||
, "engines": { "node >= 0.4.0" } | ||
} |