Comparing version 1.1.0 to 2.0.0
@@ -5,2 +5,6 @@ <!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
- [v2.0.0](#v200) | ||
- [v1.1.0](#v110) | ||
- [v1.0.3](#v103) | ||
- [v1.0.2](#v102) | ||
- [v1.0.0](#v100) | ||
@@ -10,4 +14,35 @@ | ||
### v2.0.0 | ||
* Renamed `toJS`/`fromJS` to `serialize`/`deserialize` to remove unexpected | ||
side effects when Quri instances are stored inside [Immutable.js][immutable] | ||
data structures. | ||
* Added `toJSON`/`fromJSON` for easier JSON string handling. | ||
* Added `parse` to handle either strings with `fromJSON` or objects with `deserialize` | ||
* Aliased `serialize`/`deserialize` as `serialise`/`deserialise` | ||
* Aliased `toJSON` as `stringify` | ||
### v1.1.0 | ||
* Fixed inconsistent behaviour of `toJS`/`fromJS`. | ||
* Updated `fromJS` to handle null/undefined with a new Quri instance. | ||
* Calling `fromJS` on an existing Quri instance will return a clone of the | ||
original. | ||
### v1.0.3 | ||
* Expanded `fromJS` to handle object format on input data. | ||
* Added verbose (object format) option to `toJS`. | ||
* Added constants. | ||
### v1.0.2 | ||
* Renamed class from `Criteria` to `Quri`. | ||
* `toJS`/`fromJS` added for object serialization. | ||
* Chaining support. | ||
### v1.0.0 | ||
* quri-js initial commit. | ||
* quri-js initial commit. | ||
[immutable]: https://facebook.github.io/immutable-js/ |
129
dist/quri.js
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
@@ -7,6 +11,2 @@ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -72,5 +72,7 @@ | ||
_createClass(Quri, [{ | ||
key: 'appendExpression', | ||
/** | ||
@@ -159,11 +161,11 @@ * Appends a new expression. | ||
* | ||
* @returns {object} | ||
* @param {object} options - Formatting options. | ||
* @param {Object} options - Formatting options. | ||
* @param {bool} options.verbose - If true, output expressions as objects, | ||
* otherwise output expressions as arrays. Defaults to false. | ||
* @returns {Object} | ||
*/ | ||
}, { | ||
key: 'toJS', | ||
value: function toJS() { | ||
key: 'serialize', | ||
value: function serialize() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
@@ -186,3 +188,3 @@ | ||
if (item instanceof Quri) { | ||
object.criteria.push(item.toJS(options)); | ||
object.criteria.push(item.serialize(options)); | ||
} else if (typeof item === 'string' || !item.field || !item.operator) { | ||
@@ -195,2 +197,3 @@ object.criteria.push(item); | ||
if (options.verbose) { | ||
@@ -222,5 +225,45 @@ object.criteria.push({ field: field, operator: operator, value: value }); | ||
/** | ||
* Imports the criteria from a plain JS object | ||
* Alias of `serialize`. | ||
* | ||
* @param {object} object - The input object | ||
* @param {Object} options - Formatting options. | ||
* @param {bool} options.verbose - If true, output expressions as objects, | ||
* otherwise output expressions as arrays. Defaults to false. | ||
* @returns {Object} | ||
*/ | ||
}, { | ||
key: 'serialise', | ||
value: function serialise(options) { | ||
return this.serialize(options); | ||
} | ||
/** | ||
* Convert this Quri instance to a JSON string, | ||
* using the object returned from `serialize`. | ||
* | ||
* @returns {string} The JSON string. | ||
*/ | ||
}, { | ||
key: 'toJSON', | ||
value: function toJSON() { | ||
return JSON.stringify(this.serialize()); | ||
} | ||
/** | ||
* Alias of `toJSON`. | ||
* | ||
* @returns {string} The JSON string. | ||
*/ | ||
}, { | ||
key: 'stringify', | ||
value: function stringify() { | ||
return this.toJSON(); | ||
} | ||
/** | ||
* Imports the criteria from a plain JS object. | ||
* | ||
* @param {Object} object - The input object. | ||
* @returns {Quri} | ||
@@ -260,4 +303,4 @@ */ | ||
}], [{ | ||
key: 'fromJS', | ||
value: function fromJS(object) { | ||
key: 'deserialize', | ||
value: function deserialize(object) { | ||
if (!object) { | ||
@@ -278,5 +321,5 @@ return new Quri(); | ||
if (item instanceof Quri || item.criteria) { | ||
// Clone quri instances with fromJS to avoid mutating data. | ||
// Clone quri instances with deserialize to avoid mutating data. | ||
// Assume any objects with a criteria property should become Quri instances. | ||
quri.appendQuri(Quri.fromJS(item)); | ||
quri.appendQuri(Quri.deserialize(item)); | ||
} else if (item.field && item.operator) { | ||
@@ -288,2 +331,3 @@ // Assume an expression object | ||
quri.appendExpression(field, operator, value); | ||
@@ -295,7 +339,8 @@ } else if (Array.isArray(item) && item.length === 3) { | ||
var field = _item[0]; | ||
var operator = _item[1]; | ||
var value = _item[2]; | ||
var _field = _item[0]; | ||
var _operator = _item[1]; | ||
var _value = _item[2]; | ||
quri.appendExpression(field, operator, value); | ||
quri.appendExpression(_field, _operator, _value); | ||
} else { | ||
@@ -325,2 +370,48 @@ // Assume anything else is a string or toString-able criteria object. | ||
/** | ||
* Alias of `deserialize`. | ||
* | ||
* @param {Object} object - The input object. | ||
* @returns {Quri} | ||
*/ | ||
}, { | ||
key: 'deserialise', | ||
value: function deserialise(object) { | ||
return Quri.deserialize(object); | ||
} | ||
/** | ||
* Parses a JSON string into a Quri instance. | ||
* | ||
* @param {string} json - The JSON string representing serialized Quri data. | ||
* @returns {Quri} The parsed Quri instance. | ||
*/ | ||
}, { | ||
key: 'fromJSON', | ||
value: function fromJSON(json) { | ||
if (!json) { | ||
return new Quri(); | ||
} | ||
var object = JSON.parse(json); | ||
return Quri.deserialize(object); | ||
} | ||
/** | ||
* If given a string, parses it with `fromJSON`, or if given an object, | ||
* parses it with `deserialize`. | ||
* | ||
* @param {string|Object} raw - The JSON string, or serialized quri data. | ||
* @returns {Quri} The parsed Quri instance. | ||
*/ | ||
}, { | ||
key: 'parse', | ||
value: function parse(raw) { | ||
return typeof raw === 'string' ? Quri.fromJSON(raw) : Quri.deserialize(raw); | ||
} | ||
/** | ||
* Takes the operator string from the user and returns the corresponding | ||
@@ -327,0 +418,0 @@ * string in the QURI specificiation. |
{ | ||
"name": "quri", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "JS wrapper for the QURI string specification", | ||
@@ -11,11 +11,11 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"clean": "rimraf dist", | ||
"clean": "rimraf dist coverage", | ||
"lint": "eslint src test", | ||
"check": "npm run lint -s && dependency-check package.json --entry src", | ||
"watch": "watch 'npm run build' src test", | ||
"test": "babel-node test/index.js | tspec", | ||
"test": "mocha", | ||
"prebuild": "npm run check -s && npm run clean -s", | ||
"build": "babel --optional runtime src -d dist", | ||
"postbuild": "npm run test -s", | ||
"coverage": "babel-node node_modules/isparta/bin/isparta cover test/index.js", | ||
"coverage": "istanbul cover _mocha", | ||
"coveralls": "npm run coverage -s && coveralls < coverage/lcov.info", | ||
@@ -46,6 +46,8 @@ "postcoveralls": "rimraf ./coverage", | ||
"devDependencies": { | ||
"babel-cli": "^6.3.17", | ||
"babel-core": "^6.3.26", | ||
"babel-eslint": "*", | ||
"babel-preset-es2015": "^6.3.13", | ||
"babel-cli": "^6.6.4", | ||
"babel-core": "^6.6.4", | ||
"babel-eslint": "^6.0.2", | ||
"babel-preset-es2015": "^6.5.0", | ||
"babel-register": "^6.7.2", | ||
"chai": "^3.5.0", | ||
"coveralls": "*", | ||
@@ -55,9 +57,8 @@ "dependency-check": "*", | ||
"eslint": "*", | ||
"eslint-config-airbnb": "^4.0.0", | ||
"isparta": "*", | ||
"eslint-config-airbnb": "^6.2.0", | ||
"istanbul": "^1.0.0-alpha.2", | ||
"mocha": "^2.4.5", | ||
"rimraf": "*", | ||
"tap-spec": "*", | ||
"tape": "*", | ||
"watch": "*" | ||
} | ||
} |
@@ -62,5 +62,5 @@ # quri-js | ||
quri.toJS(); | ||
quri.serialize(); | ||
// { criteria: [ [ 'field_1', '==', 'my value' ] ] } | ||
quri.toJS({ verbose: true }); | ||
quri.serialize({ verbose: true }); | ||
// { conjunction: 'and', criteria: [ { field: 'field_1', operator: '==', value: 'my value' } ] } | ||
@@ -72,11 +72,11 @@ quri.conjunction | ||
quri = Quri.fromJS({ criteria: [ [ 'field_1', '==', 'my value' ] ] }) | ||
quri = Quri.deserialize({ criteria: [ [ 'field_1', '==', 'my value' ] ] }) | ||
quri.toString(); | ||
// "field_1".eq("my value") | ||
quri = Quri.fromJS({ criteria: [ { field: 'field_1', operator: '==', value: 'my value' } ] }); | ||
quri = Quri.deserialize({ criteria: [ { field: 'field_1', operator: '==', value: 'my value' } ] }); | ||
quri.toString(); | ||
// "field_1".eq("my value") | ||
quri = Quri.fromJS({ conjunction: 'or', criteria: [ | ||
quri = Quri.deserialize({ conjunction: 'or', criteria: [ | ||
[ 'field_1', '==', 'my value' ], | ||
@@ -88,3 +88,3 @@ [ 'field_2', '==', 'my value 2' ] | ||
quri = Quri.fromJS({ conjunction: 'or', criteria: [ | ||
quri = Quri.deserialize({ conjunction: 'or', criteria: [ | ||
{ field: 'field_1', operator: '==', value: 'my value' }, | ||
@@ -91,0 +91,0 @@ { field: 'field_2', operator: '==', value: 'my value 2' } |
21103
397
15