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

consultant

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consultant - npm Package Compare versions

Comparing version 0.1.20 to 0.1.23

lib/Validator.d.ts

2

lib/Consultant.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var InputFactory_1 = require("./InputFactory");

@@ -10,4 +11,3 @@ var Consultant = (function () {

exports.Consultant = Consultant;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Consultant;
//# sourceMappingURL=Consultant.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Consultant_1 = require("./Consultant");
var consultant = new Consultant_1.Consultant();
var rules = {
makefile: {
type: String,
aliases: ['f'],
label: 'Makefile',
description: 'Load tasks from FILE',
parameter: 'FILE',
'default': ['makefile.js'],
uiHidden: false,
min: 0,
max: undefined,
validate: function (value) {
return value.length >= 3 || 'minimum 3 chars required';
}
}
};
var x = consultant.input.fromCommandLine(rules);
console.log(x.validate());
module.exports = consultant;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,3 @@

import { Rule, RuleCollection } from './Rule';
import { RuleCollection } from './Rule';
import { ValidationResult } from './Validator';
export declare class Input {

@@ -6,16 +7,5 @@ rules: RuleCollection;

constructor(rules: RuleCollection, argv: Object);
checkType(rule: Rule, item: any): void;
checkValues(rule: Rule, item: any): void;
checkOccurences(rule: Rule, item: any): void;
checkCustomValidation(rule: Rule, item: any): void;
findValues(rule: Rule, argv: any, key: any): never[];
validate(): {
values: {};
validationErrors: {};
};
consume(): {
consumed: null;
result: null;
};
validate(): ValidationResult;
consume(): any;
}
export default Input;
"use strict";
var pathNotation_1 = require("./utils/pathNotation");
Object.defineProperty(exports, "__esModule", { value: true });
var Validator_1 = require("./Validator");
var Input = (function () {

@@ -8,97 +9,5 @@ function Input(rules, argv) {

}
Input.prototype.checkType = function (rule, item) {
for (var _i = 0, _a = item.value; _i < _a.length; _i++) {
var value = _a[_i];
if (value.constructor !== rule.type) {
item.validationErrors.push({ error: "invalid type - " + value.constructor });
return;
}
}
};
Input.prototype.checkValues = function (rule, item) {
if (rule.values !== undefined) {
for (var _i = 0, _a = item.value; _i < _a.length; _i++) {
var value = _a[_i];
if (rule.values.indexOf(value) === -1) {
item.validationErrors.push({ error: "invalid value - " + value });
return;
}
}
}
};
Input.prototype.checkOccurences = function (rule, item) {
var length = item.value.length;
if ((rule.min !== undefined && length < rule.min) ||
(rule.max !== undefined && length > rule.max)) {
item.validationErrors.push({ error: "out of range - " + length });
}
};
Input.prototype.checkCustomValidation = function (rule, item) {
if (rule.validate === undefined) {
return;
}
item.value.forEach(function (currentValue) {
if (rule.validate(currentValue) !== true) {
item.validationErrors.push({ error: "validation failed - " + currentValue });
}
});
};
Input.prototype.findValues = function (rule, argv, key) {
var foundValues = [];
var value = pathNotation_1.pathNotation(argv, key);
if (value !== undefined) {
if (Array.isArray(value)) {
foundValues = foundValues.concat(value);
}
else {
foundValues.push(value);
}
}
if (rule.aliases !== undefined) {
for (var _i = 0, _a = rule.aliases; _i < _a.length; _i++) {
var alias = _a[_i];
var value2 = pathNotation_1.pathNotation(argv, alias);
if (value2 === undefined) {
continue;
}
if (Array.isArray(value2)) {
foundValues = foundValues.concat(value2);
}
else {
foundValues.push(value2);
}
}
}
return foundValues;
};
Input.prototype.validate = function () {
var result = {
values: {},
validationErrors: {}
};
for (var _i = 0, _a = Object.keys(this.rules); _i < _a.length; _i++) {
var ruleKey = _a[_i];
var rule = this.rules[ruleKey];
var item = {
validationErrors: [],
value: this.findValues(rule, this.argv, ruleKey)
};
this.checkType(rule, item);
this.checkValues(rule, item);
this.checkOccurences(rule, item);
this.checkCustomValidation(rule, item);
if (item.value.length === 0) {
item.value = rule.default;
}
else if (rule.max <= 1) {
item.value = item.value[0];
}
if (item.value !== undefined) {
result.values[ruleKey] = item.value;
}
if (item.validationErrors.length > 0) {
result.validationErrors[ruleKey] = item.validationErrors;
}
}
return result;
var validator = new Validator_1.Validator();
return validator.validate(this.rules, this.argv);
};

@@ -114,4 +23,3 @@ Input.prototype.consume = function () {

exports.Input = Input;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Input;
//# sourceMappingURL=Input.js.map

@@ -1,2 +0,1 @@

/// <reference types="es6-shim" />
import { RuleCollection } from './Rule';

@@ -3,0 +2,0 @@ import { Input } from './Input';

@@ -7,3 +7,3 @@ "use strict";

function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
step((generator = generator.apply(thisArg, _arguments || [])).next());
});

@@ -38,2 +38,3 @@ };

};
Object.defineProperty(exports, "__esModule", { value: true });
var yargsParser = require("yargs-parser");

@@ -89,4 +90,3 @@ var colors = require("colors/safe");

exports.InputFactory = InputFactory;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = InputFactory;
//# sourceMappingURL=InputFactory.js.map

@@ -1,2 +0,1 @@

/// <reference types="es6-shim" />
import { Rule } from './Rule';

@@ -16,10 +15,10 @@ import { RuleCollection } from './Rule';

questionInfo: QuestionInfo[];
constructor(cancelValue: any);
importRuleForStringWithMultipleChoices(key: string, rule: Rule): void;
importRuleForString(key: string, rule: Rule): void;
importRuleForBoolean(key: string, rule: Rule): void;
importRule(key: string, rule: Rule): void;
importRules(rules: RuleCollection): void;
constructor(cancelValue: any, questionInfo?: QuestionInfo[]);
importRuleForStringWithMultipleChoices(key: string, rule: Rule): Inquiry;
importRuleForString(key: string, rule: Rule): Inquiry;
importRuleForBoolean(key: string, rule: Rule): Inquiry;
importRule(key: string, rule: Rule): Inquiry;
importRules(rules: RuleCollection): Inquiry;
prompt(): Promise<InquiryResult>;
}
export default Inquiry;

@@ -7,3 +7,3 @@ "use strict";

function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
step((generator = generator.apply(thisArg, _arguments || [])).next());
});

@@ -38,7 +38,10 @@ };

};
Object.defineProperty(exports, "__esModule", { value: true });
var inquirer = require("inquirer");
var immunity = require("immunity");
var Inquiry = (function () {
function Inquiry(cancelValue) {
function Inquiry(cancelValue, questionInfo) {
if (questionInfo === void 0) { questionInfo = []; }
this.cancelValue = cancelValue;
this.questionInfo = [];
this.questionInfo = questionInfo;
}

@@ -48,5 +51,5 @@ Inquiry.prototype.importRuleForStringWithMultipleChoices = function (key, rule) {

if (rule.cancelValue !== undefined) {
choices.push(new inquirer.Separator());
choices = immunity.appendToArray(choices, new inquirer.Separator());
if (rule.cancelValue.constructor === String) {
choices.push({
choices = immunity.appendToArray(choices, {
name: rule.cancelValue,

@@ -58,3 +61,3 @@ value: this.cancelValue,

else {
choices.push({
choices = immunity.appendToArray(choices, {
name: rule.cancelValue.name,

@@ -66,3 +69,3 @@ value: this.cancelValue,

}
this.questionInfo.push({
return new Inquiry(this.cancelValue, immunity.appendToArray(this.questionInfo, {
key: key,

@@ -76,10 +79,9 @@ rule: rule,

}
});
}));
};
Inquiry.prototype.importRuleForString = function (key, rule) {
if (rule.values !== undefined) {
this.importRuleForStringWithMultipleChoices(key, rule);
return;
return this.importRuleForStringWithMultipleChoices(key, rule);
}
this.questionInfo.push({
return new Inquiry(this.cancelValue, immunity.appendToArray(this.questionInfo, {
key: key,

@@ -93,6 +95,6 @@ rule: rule,

}
});
}));
};
Inquiry.prototype.importRuleForBoolean = function (key, rule) {
this.questionInfo.push({
return new Inquiry(this.cancelValue, immunity.appendToArray(this.questionInfo, {
key: key,

@@ -106,38 +108,40 @@ rule: rule,

}
});
}));
};
Inquiry.prototype.importRule = function (key, rule) {
if (rule.uiHidden) {
return;
return this;
}
if (rule.type === String) {
this.importRuleForString(key, rule);
return this.importRuleForString(key, rule);
}
else if (rule.type === Boolean) {
this.importRuleForBoolean(key, rule);
if (rule.type === Boolean) {
return this.importRuleForBoolean(key, rule);
}
return this;
};
Inquiry.prototype.importRules = function (rules) {
var instance = this;
for (var _i = 0, _a = Object.keys(rules); _i < _a.length; _i++) {
var ruleKey = _a[_i];
var rule = rules[ruleKey];
this.importRule(ruleKey, rule);
instance = instance.importRule(ruleKey, rule);
}
return instance;
};
Inquiry.prototype.prompt = function () {
return __awaiter(this, void 0, void 0, function () {
var argv, _i, _a, questionInfo, result;
return __generator(this, function (_b) {
switch (_b.label) {
var argv, _i, _a, questionInfo, result, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
argv = {};
_i = 0, _a = this.questionInfo;
_b.label = 1;
_e.label = 1;
case 1:
if (!(_i < _a.length))
return [3 /*break*/, 4];
if (!(_i < _a.length)) return [3 /*break*/, 4];
questionInfo = _a[_i];
return [4 /*yield*/, inquirer.prompt(questionInfo.inquirerInput)];
case 2:
result = _b.sent();
result = _e.sent();
if ((questionInfo.rule.cancelValue !== undefined) && (result.value === this.cancelValue)) {

@@ -150,11 +154,17 @@ return [2 /*return*/, {

if (result.value.length === 0) {
argv[questionInfo.key] = questionInfo.rule.default;
immunity.appendToObject(argv, (_b = {},
_b[questionInfo.key] = questionInfo.rule.default,
_b));
}
else if (questionInfo.rule.max === undefined || questionInfo.rule.max > 1) {
argv[questionInfo.key] = [result.value];
immunity.appendToObject(argv, (_c = {},
_c[questionInfo.key] = [result.value],
_c));
}
else {
argv[questionInfo.key] = result.value;
immunity.appendToObject(argv, (_d = {},
_d[questionInfo.key] = result.value,
_d));
}
_b.label = 3;
_e.label = 3;
case 3:

@@ -174,4 +184,3 @@ _i++;

exports.Inquiry = Inquiry;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Inquiry;
//# sourceMappingURL=Inquiry.js.map

@@ -5,2 +5,7 @@ export declare type RuleTypes = StringConstructor | BooleanConstructor;

};
export declare type ValidateMethod = (value: any) => ValidationResult;
export declare type ValidationResult = {
result: Boolean;
message?: String;
};
export interface Rule {

@@ -13,3 +18,3 @@ type: RuleTypes;

values?: (string | any)[];
cancelValue?: string;
cancelValue?: any;
'default': string[];

@@ -20,4 +25,4 @@ uiHidden?: boolean;

max?: number;
validate?: Function;
validate?: ValidateMethod;
}
export default Rule;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=Rule.js.map

@@ -1,2 +0,2 @@

export declare function alignedString(input: any, initial?: string): string;
export declare function alignedString(input: (number | string)[], initial?: string): string;
export default alignedString;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function alignedString(input, initial) {

@@ -15,4 +16,3 @@ if (initial === void 0) { initial = ''; }

exports.alignedString = alignedString;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = alignedString;
//# sourceMappingURL=alignedString.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function pathNotation(sourceObj, targetPath, defaultValue, delimiter) {

@@ -17,4 +18,3 @@ if (defaultValue === void 0) { defaultValue = undefined; }

exports.pathNotation = pathNotation;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = pathNotation;
//# sourceMappingURL=pathNotation.js.map

@@ -19,3 +19,3 @@ {

],
"version": "0.1.20",
"version": "0.1.23",
"homepage": "",

@@ -54,9 +54,10 @@ "author": "Eser Ozvataf <eser@ozvataf.com>",

"colors": "^1.1.2",
"evangelist": "^0.0.2",
"inquirer": "^2.0.0",
"yargs-parser": "^4.2.0"
"evangelist": "^0.0.4",
"immunity": "^0.0.11",
"inquirer": "^3.0.6",
"yargs-parser": "^5.0.0"
},
"devDependencies": {
"@types/es6-shim": "^0.31.32"
"@types/es6-shim": "^0.31.33"
}
}

@@ -28,3 +28,3 @@ # [consultant](https://github.com/eserozvataf/consultant)

const page = consultant.createPage('Homepage', {
const rules = {
makefile: {

@@ -84,18 +84,17 @@ type: String,

}
});
};
// string parsing
let input1 = consultant.input.fromString(rules, 'eser testing --makefile testfile.js');
console.log(input1.validate());
// command line parsing
const argv = consultant.parse(process.argv.slice(2));
console.log(page.validate('main', argv));
let input2 = consultant.input.fromCommandLine(rules);
console.log(input2.validate());
// command line user interface
page.inquiry('main')
.then((answers) => {
console.log(answers);
consultant.input.fromInquiry(rules)
.then((input3) => {
console.log(input3);
});
// help
const help = [];
page.help('main', help);
console.log(help);
```

@@ -102,0 +101,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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