Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-containerpattern

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-containerpattern

A 'Container pattern' object for a clean global use of data.

  • 0.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
increased by21.43%
Maintainers
1
Weekly downloads
 
Created
Source

node-containerpattern

A 'Container pattern' object for a clean global use of data. Basicaly, it extends Map object with lot of controls, recursive methods and documentation

Installation

$ npm install node-containerpattern

Features

  • Remember data by there choosen keys
  • use optional skeleton to ensure data formats
  • Access to the data easily and recursively
  • Check recursively data by the key and the value
  • Manipule the data : set, get, has, delete, ...
  • Easily create documenation

Doc

-- Inheritance --

check the official 'Map' object documentation

-- Attributes --

  • object documentations used to save documentation by data's key
  • object limits used to limit data's values possibilities
  • string recursionSeparator used to parse recursive keys (default : '.')
  • object skeletons used to force data type

-- Constructor --

  • constructor([ string recursionSeparator = "." ])

-- Methods --

  • clear() : return this clearData & clearDocumentations & clearLimits & clearSkeletons
  • clearData() : return this forget all the keys and there values and documentations (=> Map.clear)
  • clearDocumentations() : return this forget all the skeletons
  • clearLimits() : return this forget all the limits
  • clearSkeletons() : return this forget all the skeletons
  • delete(string key) : return this forget a key and its value
  • document(string key, string documentation) : return this attach a documentation on the data. only visible if "set" method is applied with this key.
  • documentation() : return JSON object generate a documentation for all the stored data
  • get(string key) : return mixed return the value in association with this key (may be recursive)
  • has(string key) : return bool check if a key is used (may be recursive)
  • limit(string key, array limit) : return this associate a key with a limit
  • set(string key, mixed value) : return this associate and remember a key with a value (may be recursive)
  • skeleton(string key, string skeleton) : return this skeleton must be "array", "boolean", "email", "float", "integer", "ipv4", "ipv6", "number", "object", "string"

-- notes --

  • if the skeleton is an 'array' or an 'object', and value data is a string, JSON.parse is apply before throw any error
  • if the skeleton is an 'email', value must be a string. it can be empty, but must be a valid address if not

Examples

const Container = require('node-containerpattern');
var container = new Container();

container
  .skeleton("contact", "email").document("contact", "Contact address")
  .skeleton("debug", "boolean").document("debug", "This is the debug module")
  .skeleton("vat", "float")
  .skeleton("heigth", "integer")

  .set('contact', "myaddress@provider.com")
  .set('debug', true) // '"yes"', '"y"', '"1"', '1', '"true"' or 'true' => get = true, else => get = false
  .set('vat', '5.5').set('vat', 5.5)
  .set('conf', { usr : { login : 'login', pwd : 'pwd' } })
  .set('conf.usr.login', "login2")
  .set('object', new Object())

  .limit("debug", [true, false]); // debug is now limited to 'true' or 'false'

console.log(container.get('conf').usr.login);
console.log(container.get('conf.usr.login'));
console.log(container.get('object'));
console.log(container.get('conf'));

container.delete('object');

console.log(container.has('object'));
console.log(container.size);

for (let key of container.keys()) {
  console.log(key);
}
for (let value of container.values()) {
  console.log(value);
}

container.forEach((value, key) => {
  console.log("container[" + key + "] = " + value);
});

console.log(container.documentation());

container.clear();

Tests

$ gulp

License

ISC

Keywords

FAQs

Package last updated on 03 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc