Comparing version 1.0.1 to 1.0.2
'use strict'; | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,134 +7,8 @@ value: true | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _Quri = require('./Quri'); | ||
/** | ||
* @class Criteria | ||
* | ||
* A class to wrap a QURI string creation | ||
*/ | ||
var _Quri2 = _interopRequireDefault(_Quri); | ||
var Criteria = (function () { | ||
/** | ||
* Criteria constructor | ||
* | ||
* @param andOr Sets the and|or for all expressions at this level | ||
*/ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function Criteria() { | ||
var andOr = arguments.length <= 0 || arguments[0] === undefined ? 'and' : arguments[0]; | ||
_classCallCheck(this, Criteria); | ||
this.andOr = andOr; | ||
this.criteria = []; | ||
} | ||
/** | ||
* Appends a new expression. | ||
* | ||
* @example appendExpression('customer_name', 'like', 'Greg%') | ||
* | ||
* @param {string} fieldName Field name | ||
* @param {string} operator String '==', '!=', '>', '>=', '<', '<=', 'in', 'not_in', 'like', 'between' | ||
* @param {string,number,Array} value Value(s) that match the operator. | ||
* The only operators that allow array values are in|out|nin | ||
*/ | ||
_createClass(Criteria, [{ | ||
key: 'appendExpression', | ||
value: function appendExpression(fieldName, operator, value) { | ||
this.criteria.push({ | ||
fieldName: fieldName, | ||
operator: operator, | ||
value: value | ||
}); | ||
} | ||
/** | ||
* Appends a criteria object to the current criteria array. | ||
* The criteria object may be a new Criteria class or any object with a toString method. | ||
* | ||
* @param {Criteria} criteria | ||
*/ | ||
}, { | ||
key: 'appendCriteria', | ||
value: function appendCriteria(criteria) { | ||
this.criteria.push({ | ||
criteria: criteria | ||
}); | ||
} | ||
/** | ||
* Returns the formatted QURI string | ||
* | ||
* @returns {string} | ||
*/ | ||
}, { | ||
key: 'toString', | ||
value: function toString() { | ||
var criteriaMap = this.criteria.map(function (expression) { | ||
if (expression.hasOwnProperty('criteria')) { | ||
return '(' + expression.criteria.toString() + ')'; | ||
} | ||
var operator = Criteria.operatorToString(expression.operator); | ||
var valueStr = JSON.stringify(expression.value); | ||
if (valueStr.charAt(0) == '[') { | ||
// If it's an array we need to remove the [ ] from the outside. | ||
valueStr = valueStr.substring(1, valueStr.length - 1); | ||
} | ||
return JSON.stringify(expression.fieldName) + '.' + operator + '(' + valueStr + ')'; | ||
}); | ||
return criteriaMap.join(this.andOr == 'and' ? ',' : '|'); | ||
} | ||
/** | ||
* Takes the operator string from the user and returns the corresponding string in the QURI specificiation. | ||
* | ||
* @example operatorToString('=='); // 'eq' | ||
* | ||
* @param {string} operatorStr | ||
* @returns {string} | ||
*/ | ||
}], [{ | ||
key: 'operatorToString', | ||
value: function operatorToString(operatorStr) { | ||
switch (operatorStr) { | ||
case '=': | ||
case '==': | ||
case 'eq': | ||
return 'eq'; | ||
case '!=': | ||
case 'neq': | ||
return 'neq'; | ||
case '>': | ||
case 'gt': | ||
return 'gt'; | ||
case '>=': | ||
case 'gte': | ||
return 'gte'; | ||
case '<': | ||
case 'lt': | ||
return 'lt'; | ||
case '<=': | ||
case 'lte': | ||
return 'lte'; | ||
case 'in': | ||
return 'in'; | ||
case 'not_in': | ||
case 'nin': | ||
return 'nin'; | ||
case 'like': | ||
return 'like'; | ||
case 'between': | ||
return 'between'; | ||
} | ||
} | ||
}]); | ||
return Criteria; | ||
})(); | ||
exports.default = Criteria; | ||
exports.default = _Quri2.default; |
{ | ||
"name": "quri", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "JS wrapper for the QURI string specification", | ||
@@ -53,2 +53,3 @@ "main": "dist/index.js", | ||
"eslint": "*", | ||
"eslint-config-airbnb": "^4.0.0", | ||
"isparta": "*", | ||
@@ -55,0 +56,0 @@ "rimraf": "*", |
@@ -14,3 +14,3 @@ # quri-js | ||
```sh | ||
npm i -D quri | ||
npm install quri | ||
``` | ||
@@ -27,7 +27,7 @@ | ||
```js | ||
import Criteria from "../src/index.js"; | ||
import quri from "quri"; | ||
let criteria = new Criteria(); | ||
let quri = new quri(); | ||
criteria.toString(); // "field_1".eq("my value") | ||
quri.toString(); // "field_1".eq("my value") | ||
``` | ||
@@ -38,12 +38,12 @@ | ||
```js | ||
let criteria = new Criteria(); | ||
criteria.appendExpression('field_1', '==', 'outer'); | ||
let quri = new quri(); | ||
quri.appendExpression('field_1', '==', 'outer'); | ||
let nestedCriteria = new Criteria('or'); | ||
nestedCriteria.appendExpression('field_2', 'like', 'nested%'); | ||
nestedCriteria.appendExpression('field_3', 'in', [1,2,3,4]); | ||
let nestedQuri = new quri('or'); | ||
nestedQuri.appendExpression('field_2', 'like', 'nested%'); | ||
nestedQuri.appendExpression('field_3', 'in', [1,2,3,4]); | ||
criteria.appendCriteria(nestedCriteria); | ||
quri.appendCriteria(nestedQuri); | ||
criteria.toString(); | ||
quri.toString(); | ||
// "field_1".eq("outer"),("field_2".eq("nested%")|"field_3".in(1,2,3,4)) | ||
@@ -50,0 +50,0 @@ ``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
14752
6
284
14
2