Skip to content

Commit

Permalink
Merge pull request #44 from Psychopoulet/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Psychopoulet committed Oct 14, 2020
2 parents b01c589 + 6f26467 commit bc4b893
Show file tree
Hide file tree
Showing 10 changed files with 390 additions and 188 deletions.
2 changes: 1 addition & 1 deletion lib/ensureDataArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// module

module.exports = (key, skeleton, value) => {
module.exports = function ensureDataArray (key, skeleton, value) {

let result = value;

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

// module

module.exports = (key, skeleton, value) => {
module.exports = function ensureDataBasic (key, skeleton, value) {

if ("string" === skeleton) {
return String(value);
Expand Down
2 changes: 1 addition & 1 deletion lib/ensureDataObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// module

module.exports = (key, skeleton, value) => {
module.exports = function ensureDataObject (key, skeleton, value) {

let result = value;

Expand Down
2 changes: 1 addition & 1 deletion lib/ensureDataSpecific.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// module

module.exports = (key, skeleton, value) => {
module.exports = function ensureDataSpecific (key, skeleton, value) {

if (isEmptyString(value)) {
return value.trim();
Expand Down
2 changes: 1 addition & 1 deletion lib/ensureKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// module

module.exports = (key) => {
module.exports = function ensureKey (key) {

if (!isDefined(key)) {
throw new ReferenceError("The key does not exist");
Expand Down
2 changes: 1 addition & 1 deletion lib/getTypeValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// module

module.exports = (value) => {
module.exports = function getTypeValue (value) {

if (isArray(value)) {
return "array";
Expand Down
31 changes: 28 additions & 3 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,39 @@ module.exports = class NodeContainerPattern extends Map {

const fullKey = !isEmptyString(previousKeys) ? previousKeys + this.recursionSeparator + key : key;

const type = isNotEmptyString(this.skeletons[fullKey]) ? this.skeletons[fullKey] : getTypeValue(value);

let min = null;
if (isDefined(this.mins[fullKey])) {
min = this.mins[fullKey];
}
else if ("array" === type) {
min = 0;
}

let regex = null;
if (isDefined(this.regexs[fullKey])) {

regex = String(this.regexs[fullKey]);

if (regex.length && regex.startsWith("/")) {
regex = regex.slice(1, regex.length);
}

if (regex.length && regex.endsWith("/")) {
regex = regex.slice(0, regex.length - 1);
}

}

result[key] = {
"documentation": this.documentations[fullKey] ? this.documentations[fullKey] : "",
"fullkey": fullKey,
"min": isDefined(this.mins[fullKey]) ? this.mins[fullKey] : null,
min,
"max": isDefined(this.maxs[fullKey]) ? this.maxs[fullKey] : null,
"limits": isArray(this.limits[fullKey]) ? this.limits[fullKey] : null,
"regex": isDefined(this.regexs[fullKey]) ? String(this.regexs[fullKey]) : null,
"type": isNotEmptyString(this.skeletons[fullKey]) ? this.skeletons[fullKey] : getTypeValue(value)
regex,
type
};

if ("array" === result[key].type) {
Expand Down
34 changes: 34 additions & 0 deletions lib/stringifyRegex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use strict";

// deps

// natives
const { join } = require("path");

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

// module

module.exports = function stringifyRegex (regex) {

if (isString(regex) || isRegExp(regex)) {

let stringified = isString(regex) ? regex : String(regex);

if (stringified.length && stringified.startsWith("/")) {
stringified = stringified.slice(1, stringified.length);
}

if (stringified.length && stringified.endsWith("/")) {
stringified = stringified.slice(0, stringified.length - 1);
}

return stringified;

}
else {
return null;
}

};
47 changes: 47 additions & 0 deletions test/1_stringifyRegex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
eslint-disable max-statements
*/

"use strict";

// deps

// natives
const { strictEqual } = require("assert");
const { join } = require("path");

// locals
const stringifyRegex = require(join(__dirname, "..", "lib", "stringifyRegex.js"));

// tests

describe("stringifyRegex", () => {

it("should check with nothing", () => {

strictEqual(stringifyRegex(), null, "stringifyRegex result test is invalid");

});

it("should check with boolean", () => {

strictEqual(stringifyRegex(true), null, "stringifyRegex result test is invalid");

});

it("should check with string", () => {

strictEqual(stringifyRegex("test"), "test", "stringifyRegex result test is invalid");
strictEqual(stringifyRegex("/test"), "test", "stringifyRegex result test is invalid");
strictEqual(stringifyRegex("test/"), "test", "stringifyRegex result test is invalid");
strictEqual(stringifyRegex("/test/"), "test", "stringifyRegex result test is invalid");

});

it("should check with regex", () => {

strictEqual(stringifyRegex(/^test$/), "^test$", "stringifyRegex result test is invalid");

});

});
Loading

0 comments on commit bc4b893

Please sign in to comment.