Skip to content

Commit

Permalink
Merge pull request #37 from Psychopoulet/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Psychopoulet committed Oct 1, 2020
2 parents c645eb5 + 02564b4 commit d0bcbda
Show file tree
Hide file tree
Showing 29 changed files with 1,164 additions and 532 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = {
"no-control-regex": "error",
"no-debugger": "error",
"no-dupe-args": "error",
"no-dupe-else-if": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty": "error",
Expand All @@ -53,12 +54,14 @@ module.exports = {
"no-extra-parens": "error",
"no-extra-semi": "error",
"no-func-assign": "error",
"no-import-assign": "error",
"no-inner-declarations": "error",
"no-invalid-regexp": "error",
"no-irregular-whitespace": "error",
"no-obj-calls": "error",
"no-prototype-builtins": "error",
"no-regex-spaces": "error",
"no-setter-return": "error",
"no-sparse-arrays": "error",
"no-template-curly-in-string": "error",
"no-unexpected-multiline": "error",
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: node_js
node_js:
- "8"
- "10"
- "12"
- "14"
install:
- "npm install -g typescript"
- "npm install"
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,30 @@ $ npm install node-containerpattern

* ``` constructor(recursionSeparator: string = ".") ```

-- Attributes --

* ``` documentations: object ```
* ``` limits: object ```
* ``` mins: object ```
* ``` maxs: object ```
* ``` recursionSeparator: string ```
* ``` skeletons: object ```

-- Methods --

* ``` clear(): this ``` clearData & clearDocumentations & clearLimits & clearSkeletons
* ``` clearData() : this ``` forget all the keys and there values and documentations (=> Map.clear)
* ``` clearDocumentations() : this ``` forget all the skeletons
* ``` clearLimits() : this ``` forget all the limits
* ``` clearMinsMaxs() : this ``` forget all the min & max limits
* ``` clearSkeletons() : this ``` forget all the skeletons
* ``` delete(key: string) : this ``` forget a key and its value
* ``` document(key: string, documentation: string) : this ``` attach a documentation on the data. only visible if "set" method is applied with this key.
* ``` documentation() : JSON object ``` generate a documentation for all the stored data
* ``` get(key: string) : mixed ``` the value in association with this key (may be recursive)
* ``` has(key: string) : bool ``` check if a key is used (may be recursive)
* ``` min(key: string, min: integer) : this ``` associate a key with a min value (min length for string & array) (MUST have a valid skeleton : [ "integer", "float", "number", "string", "array" ])
* ``` max(key: string, max: integer) : this ``` associate a key with a max value (max length for string & array) (MUST have a valid skeleton : [ "integer", "float", "number", "string", "array" ])
* ``` limit(key: string, limit: Array<string>) : this ``` associate a key with a limit
* ``` set(key: string, mixed value) : this ``` associate and remember a key with a value (may be recursive)
* ``` skeleton(key: string, skeleton: string) : this ``` skeleton must be "array", "boolean", "email", "float", "integer", "ipv4", "ipv6", "number", "object", "string"
Expand Down Expand Up @@ -76,7 +88,9 @@ container
.set("conf.usr.login", "login2")
.set("object", new Object())

.limit("debug", [true, false]); // debug is now limited to 'true' or 'false'
.min("contact", 6) // min length : 6 (x@x.xx)
.limit("debug", [true, false]) // debug is now limited to 'true' or 'false'
.min("vat", 0).max("vat", 50); // cannot be less than 0% or more than 50%

console.log(container.get("conf").usr.login);
console.log(container.get("conf.usr.login"));
Expand Down
49 changes: 0 additions & 49 deletions lib/ensureData.js

This file was deleted.

7 changes: 5 additions & 2 deletions lib/ensureDataArray.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

"use strict";

// deps

const { isArray, isString } = require(require("path").join(__dirname, "validators"));
// natives
const { join } = require("path");

// locals
const { isArray, isString } = require(join(__dirname, "validators"));

// module

Expand Down
6 changes: 5 additions & 1 deletion lib/ensureDataBasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

// deps

const { isNumber, isInteger } = require(require("path").join(__dirname, "validators"));
// natives
const { join } = require("path");

// locals
const { isNumber, isInteger } = require(join(__dirname, "validators"));

// module

Expand Down
7 changes: 5 additions & 2 deletions lib/ensureDataObject.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

"use strict";

// deps

const { isPlainObject, isString } = require(require("path").join(__dirname, "validators"));
// natives
const { join } = require("path");

// locals
const { isPlainObject, isString } = require(join(__dirname, "validators"));

// module

Expand Down
24 changes: 13 additions & 11 deletions lib/ensureDataSpecific.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
eslint no-extra-parens: 0
*/

"use strict";

// deps

const { isEmail, isEmptyString, isIPV4, isIPV6 } = require(require("path").join(__dirname, "validators"));
// natives
const { join } = require("path");

// locals
const { isEmail, isEmptyString, isIPV4, isIPV6 } = require(join(__dirname, "validators"));

// module

Expand All @@ -15,12 +15,14 @@ module.exports = (key, skeleton, value) => {
if (isEmptyString(value)) {
return value.trim();
}
else if (
("email" === skeleton && !isEmail(value)) ||
("ipv4" === skeleton && !isIPV4(value)) ||
("ipv6" === skeleton && !isIPV6(value))
) {
throw new TypeError("The \"" + key + "\" data does not correspond to the skeleton");
else if ("email" === skeleton && !isEmail(value)) {
throw new TypeError("The \"" + key + "\" data does not correspond to the \"email\" skeleton");
}
else if ("ipv4" === skeleton && !isIPV4(value)) {
throw new TypeError("The \"" + key + "\" data does not correspond to the \"ipv4\" skeleton");
}
else if ("ipv6" === skeleton && !isIPV6(value)) {
throw new TypeError("The \"" + key + "\" data does not correspond to the \"ipv6\" skeleton");
}
else {
return value;
Expand Down
7 changes: 5 additions & 2 deletions lib/ensureKey.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

"use strict";

// deps

const { isDefined, isString, isEmptyString } = require(require("path").join(__dirname, "validators"));
// natives
const { join } = require("path");

// locals
const { isDefined, isString, isEmptyString } = require(join(__dirname, "validators"));

// module

Expand Down
13 changes: 9 additions & 4 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ declare module "node-containerpattern" {
// Map
public size: number;

protected _documentations: object;
protected _limits: object;
protected _skeletons: object;
protected _recursionSeparator: string;
public documentations: object;
public limits: object;
public mins: object;
public maxs: object;
public skeletons: object;
public recursionSeparator: string;

constructor(recursionSeparator?: string);

Expand All @@ -26,13 +28,16 @@ declare module "node-containerpattern" {
public clearData(): Container;
public clearDocumentations(): Container;
public clearLimits(): Container;
public clearMinsMaxs(): Container;
public clearSkeletons(): Container;
public delete(key: string): Container;
public document(key: string, value: string): Container;
public documentation(): object;
public get(key: string): any;
public has(key: string): boolean;
public limit(key: string, limit: Array<string>): boolean;
public min(key: string, min: number): Container;
public max(key: string, max: number): Container;
public set(key: string, value: any): Container;
public skeleton(key: string, value: string): Container;

Expand Down
Loading

0 comments on commit d0bcbda

Please sign in to comment.