BVB Source Codes

reactide Show namespace.js Source code

Return Download reactide: download namespace.js Source code - Download reactide Source code - Type:.js
  1. /**
  2.  * class Namespace
  3.  *
  4.  * Simple object for storing attributes. Implements equality by attribute names
  5.  * and values, and provides a simple string representation.
  6.  *
  7.  * See also [original guide][1]
  8.  *
  9.  * [1]:http://docs.python.org/dev/library/argparse.html#the-namespace-object
  10.  **/
  11. 'use strict';
  12.  
  13. var $$ = require('./utils');
  14.  
  15. /**
  16.  * new Namespace(options)
  17.  * - options(object): predefined propertis for result object
  18.  *
  19.  **/
  20. var Namespace = module.exports = function Namespace(options) {
  21.   $$.extend(this, options);
  22. };
  23.  
  24. /**
  25.  * Namespace#isset(key) -> Boolean
  26.  * - key (string|number): property name
  27.  *
  28.  * Tells whenever `namespace` contains given `key` or not.
  29.  **/
  30. Namespace.prototype.isset = function (key) {
  31.   return $$.has(this, key);
  32. };
  33.  
  34. /**
  35.  * Namespace#set(key, value) -> self
  36.  * -key (string|number|object): propery name
  37.  * -value (mixed): new property value
  38.  *
  39.  * Set the property named key with value.
  40.  * If key object then set all key properties to namespace object
  41.  **/
  42. Namespace.prototype.set = function (key, value) {
  43.   if (typeof (key) === 'object') {
  44.     $$.extend(this, key);
  45.   } else {
  46.     this[key] = value;
  47.   }
  48.   return this;
  49. };
  50.  
  51. /**
  52.  * Namespace#get(key, defaultValue) -> mixed
  53.  * - key (string|number): property name
  54.  * - defaultValue (mixed): default value
  55.  *
  56.  * Return the property key or defaulValue if not set
  57.  **/
  58. Namespace.prototype.get = function (key, defaultValue) {
  59.   return !this[key] ? defaultValue : this[key];
  60. };
  61.  
  62. /**
  63.  * Namespace#unset(key, defaultValue) -> mixed
  64.  * - key (string|number): property name
  65.  * - defaultValue (mixed): default value
  66.  *
  67.  * Return data[key](and delete it) or defaultValue
  68.  **/
  69. Namespace.prototype.unset = function (key, defaultValue) {
  70.   var value = this[key];
  71.   if (value !== null) {
  72.     delete this[key];
  73.     return value;
  74.   }
  75.   return defaultValue;
  76. };
  77.  
downloadnamespace.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top