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

fakerest

Package Overview
Dependencies
Maintainers
2
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fakerest - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

2

dist/FakeRest.min.js

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):"object"==typeof exports?exports.FakeRest=t():e.FakeRest=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";var r=n(3)["default"];Object.defineProperty(t,"__esModule",{value:!0});var o=n(1),i=r(o),u=n(2),s=r(u);t["default"]={Server:i["default"],Collection:s["default"]},e.exports=t["default"]},function(e,t,n){"use strict";function r(e){if(!e)return{};var t={},n=e.split("&");return n.map(function(e){if(-1===e.indexOf("="))t[e]=!0;else{var n=e.split("="),r=u(n,2),o=r[0],i=r[1];(0===i.indexOf("[")||0===i.indexOf("{"))&&(i=JSON.parse(i)),t[o.trim()]=i}}),t}var o=n(4)["default"],i=n(5)["default"],u=n(6)["default"],s=n(7)["default"],a=n(8)["default"],c=n(3)["default"];Object.defineProperty(t,"__esModule",{value:!0});var f=n(2),l=c(f),d=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?"":arguments[0];i(this,e),this.baseUrl=t,this.collections={},this.loggingEnabled=!1,this.requestInterceptors=[],this.responseInterceptors=[],this.batchUrl=null}return o(e,[{key:"init",value:function(e){for(var t in e)this.addCollection(t,new l["default"](e[t]))}},{key:"toggleLogging",value:function(){this.loggingEnabled=!this.loggingEnabled}},{key:"setBatch",value:function(e){this.batchUrl=e}},{key:"addCollection",value:function(e,t){this.collections[e]=t}},{key:"getCollection",value:function(e){return this.collections[e]}},{key:"getCollectionNames",value:function(){return s(this.collections)}},{key:"addRequestInterceptor",value:function(e){this.requestInterceptors.push(e)}},{key:"addResponseInterceptor",value:function(e){this.responseInterceptors.push(e)}},{key:"getCount",value:function(e,t){return this.collections[e].getCount(t)}},{key:"getAll",value:function(e,t){return this.collections[e].getAll(t)}},{key:"getOne",value:function(e,t){return this.collections[e].getOne(t)}},{key:"addOne",value:function(e,t){return this.collections[e].addOne(t)}},{key:"updateOne",value:function(e,t,n){return this.collections[e].updateOne(t,n)}},{key:"removeOne",value:function(e,t){return this.collections[e].removeOne(t)}},{key:"decode",value:function(e){if(e.queryString=decodeURIComponent(e.url.slice(e.url.indexOf("?")+1)),e.params=r(e.queryString),e.requestBody)try{e.json=JSON.parse(e.requestBody)}catch(t){}return this.requestInterceptors.reduce(function(e,t){return t(e)},e)}},{key:"respond",value:function(e,t,n){var r=arguments.length<=3||void 0===arguments[3]?200:arguments[3];t||(t={}),t["Content-Type"]||(t["Content-Type"]="application/json");var o={status:r,headers:t,body:e};return o=this.responseInterceptors.reduce(function(e,t){return t(e,n)},o),this.log(n,o),n.respond(o.status,o.headers,JSON.stringify(o.body))}},{key:"log",value:function(e,t){this.loggingEnabled&&(console.group?(console.groupCollapsed(e.method,e.url,"(FakeRest)"),console.group("request"),console.log(e.method,e.url),console.log("headers",e.requestHeaders),console.log("body ",e.requestBody),console.groupEnd(),console.group("response",t.status),console.log("headers",t.headers),console.log("body ",t.body),console.groupEnd(),console.groupEnd()):(console.log("FakeRest request ",e.method,e.url,"headers",e.requestHeaders,"body",e.requestBody),console.log("FakeRest response",t.status,"headers",t.headers,"body",t.body)))}},{key:"batch",value:function(e){var t=e.json,n=this.handle.bind(this),r=s(t).reduce(function(e,r){var o,i={url:t[r],method:"GET",params:{},respond:function(e,t,n){o={code:e,headers:s(t||{}).map(function(e){return{name:e,value:t[e]}}),body:n||{}}}};return n(i),e[r]=o||{code:404,headers:[],body:{}},e},{});return this.respond(r,{},e,200)}},{key:"handle",value:function(e){if(e=this.decode(e),this.batchUrl&&this.batchUrl===e.url&&"POST"===e.method)return this.batch(e);var t=!0,n=!1,r=void 0;try{for(var o,i=a(this.getCollectionNames());!(t=(o=i.next()).done);t=!0){var u=o.value,s=e.url.match(new RegExp("^"+this.baseUrl+"\\/("+u+")(\\/(\\d+))?(\\?.*)?$"));if(s)if(s[2]){var c=s[3];if("GET"==e.method)try{var f=this.getOne(u,c);return this.respond(f,null,e)}catch(l){return e.respond(404)}if("PUT"==e.method)try{var f=this.updateOne(u,c,e.json);return this.respond(f,null,e)}catch(l){return e.respond(404)}if("DELETE"==e.method)try{var f=this.removeOne(u,c);return this.respond(f,null,e)}catch(l){return e.respond(404)}}else{if("GET"==e.method){var d=e.params,h={};for(var p in d)"range"!==p&&(h[p]=d[p]);var y=this.getCount(u,h),g=void 0,v=void 0,m=void 0;if(y>0){g=this.getAll(u,d);var b=d.range?d.range[0]:0,O=d.range?Math.min(g.length-1+b,d.range[1]):g.length-1;v="items "+b+"-"+O+"/"+y,m=g.length==y?200:206}else g=[],v="items */0",m=200;return this.respond(g,{"Content-Range":v},e,m)}if("POST"==e.method){var x=this.addOne(u,e.json),w=this.baseUrl+"/"+u+"/"+x[this.getCollection(u).identifierName];return this.respond(x,{Location:w},e,201)}}}}catch(j){n=!0,r=j}finally{try{!t&&i["return"]&&i["return"]()}finally{if(n)throw r}}}},{key:"getHandler",value:function(){return this.handle.bind(this)}}]),e}();t["default"]=d,e.exports=t["default"]},function(e,t,n){"use strict";function r(e,t){if("function"==typeof t)return e.filter(t);if(t instanceof Object){var n=function(){var n=t.q?new RegExp(t.q,"i"):null;return{v:e.filter(function(e){for(var r in t){if("q"===r){for(var o in e)if(e[o]&&e[o].match&&null!==e[o].match(n))return!0;return!1}var i=t[r];if("[object Array]"==Object.prototype.toString.call(e[r])&&"string"==typeof t[r])return-1!==e[r].indexOf(i);if("boolean"==typeof e[r]&&"string"==typeof t[r]&&(i="true"===t[r]?!0:!1),e[r]!=i)return!1}return!0})}}();if("object"==typeof n)return n.v}throw new Error("Unsupported filter type")}function o(e,t){if("function"==typeof t)return e.sort(t);if("string"==typeof t)return e.sort(function(e,n){return e[t]>n[t]?1:e[t]<n[t]?-1:0});if(Array.isArray(t)){var n=function(){var n=t[0],r="asc"==t[1].toLowerCase()?1:-1;return{v:e.sort(function(e,t){return e[n]>t[n]?r:e[n]<t[n]?-1*r:0})}}();if("object"==typeof n)return n.v}throw new Error("Unsupported sort type")}function i(e,t){if(Array.isArray(t))return e.slice(t[0],void 0!==t[1]?t[1]+1:void 0);throw new Error("Unsupported range type")}var u=n(4)["default"],s=n(5)["default"];Object.defineProperty(t,"__esModule",{value:!0}),n(9);var a=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?[]:arguments[0],n=arguments.length<=1||void 0===arguments[1]?"id":arguments[1];if(s(this,e),!Array.isArray(t))throw new Error("Can't initialize a Collection with anything else than an array of items");this.sequence=0,this.identifierName=n,this.items=[],t.map(this.addOne.bind(this))}return u(e,[{key:"getCount",value:function(e){return this.getAll(e).length}},{key:"getAll",value:function(e){var t=this.items.map(function(e){return e});return e&&(e.filter&&(t=r(t,e.filter)),e.sort&&(t=o(t,e.sort)),e.range&&(t=i(t,e.range))),t}},{key:"getIndex",value:function(e){var t=this;return this.items.findIndex(function(n){return n[t.identifierName]==e})}},{key:"getOne",value:function(e){var t=this.getIndex(e);if(-1===t)throw new Error("No item with identifier "+e);return this.items[t]}},{key:"addOne",value:function(e){var t=e[this.identifierName];if(void 0!==t){if(-1!==this.getIndex(t))throw new Error("An item with the identifier "+t+" already exists");this.sequence=Math.max(this.sequence,t)+1}else e[this.identifierName]=this.sequence++;return this.items.push(e),e}},{key:"updateOne",value:function(e,t){var n=this.getIndex(e);if(-1===n)throw new Error("No item with identifier "+e);for(var r in t)this.items[n][r]=t[r];return this.items[n]}},{key:"removeOne",value:function(e){var t=this.getIndex(e);if(-1===t)throw new Error("No item with identifier "+e);var n=this.items[t];return this.items.splice(t,1),e==this.sequence-1&&this.sequence--,n}}]),e}();t["default"]=a,e.exports=t["default"]},function(e,t){"use strict";t["default"]=function(e){return e&&e.__esModule?e:{"default":e}},t.__esModule=!0},function(e,t,n){"use strict";var r=n(10)["default"];t["default"]=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),r(e,o.key,o)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),t.__esModule=!0},function(e,t){"use strict";t["default"]=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},t.__esModule=!0},function(e,t,n){"use strict";var r=n(8)["default"],o=n(11)["default"];t["default"]=function(){function e(e,t){var n=[],o=!0,i=!1,u=void 0;try{for(var s,a=r(e);!(o=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);o=!0);}catch(c){i=!0,u=c}finally{try{!o&&a["return"]&&a["return"]()}finally{if(i)throw u}}return n}return function(t,n){if(Array.isArray(t))return t;if(o(Object(t)))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),t.__esModule=!0},function(e,t,n){e.exports={"default":n(13),__esModule:!0}},function(e,t,n){e.exports={"default":n(12),__esModule:!0}},function(){!function(){if(!Array.prototype.findIndex){var e=function(e){var t=Object(this),n=Math.max(0,t.length)>>>0;if(0===n)return-1;if("function"!=typeof e||"[object Function]"!==Object.prototype.toString.call(e))throw new TypeError("Array#findIndex: predicate must be a function");for(var r=arguments.length>1?arguments[1]:void 0,o=0;n>o;o++)if(e.call(r,t[o],o,t))return o;return-1};if(Object.defineProperty)try{Object.defineProperty(Array.prototype,"findIndex",{value:e,configurable:!0,writable:!0})}catch(t){}Array.prototype.findIndex||(Array.prototype.findIndex=e)}}(this)},function(e,t,n){e.exports={"default":n(14),__esModule:!0}},function(e,t,n){e.exports={"default":n(15),__esModule:!0}},function(e,t,n){n(16),n(17),n(18),e.exports=n(19).core.getIterator},function(e,t,n){n(20),e.exports=n(19).core.Object.keys},function(e,t,n){var r=n(19);e.exports=function(e,t,n){return r.setDesc(e,t,n)}},function(e,t,n){n(16),n(17),n(18),e.exports=n(19).core.isIterable},function(e,t,n){n(21);var r=n(19),o=n(22).Iterators,i=n(23)("iterator"),u=o.Array,s=r.g.NodeList,a=r.g.HTMLCollection,c=s&&s.prototype,f=a&&a.prototype;r.FW&&(!s||i in c||r.hide(c,i,u),!a||i in f||r.hide(f,i,u)),o.NodeList=o.HTMLCollection=u},function(e,t,n){var r=n(19).set,o=n(24)(!0),i=n(25).safe("iter"),u=n(22),s=u.step;n(26)(String,"String",function(e){r(this,i,{o:String(e),i:0})},function(){var e,t=this[i],n=t.o,r=t.i;return r>=n.length?s(1):(e=o(n,r),t.i+=e.length,s(0,e))})},function(e,t,n){var r=n(19).core,o=n(22);r.isIterable=o.is,r.getIterator=o.get},function(e,t,n){"use strict";function r(e){return isNaN(e=+e)?0:(e>0?y:p)(e)}function o(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}function i(e,t,n){return e[t]=n,e}function u(e){return m?function(t,n,r){return O.setDesc(t,n,o(e,r))}:i}function s(e){return null!==e&&("object"==typeof e||"function"==typeof e)}function a(e){return"function"==typeof e}function c(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e}var f="undefined"!=typeof self?self:Function("return this")(),l={},d=Object.defineProperty,h={}.hasOwnProperty,p=Math.ceil,y=Math.floor,g=Math.max,v=Math.min,m=!!function(){try{return 2==d({},"a",{get:function(){return 2}}).a}catch(e){}}(),b=u(1),O=e.exports=n(27)({g:f,core:l,html:f.document&&document.documentElement,isObject:s,isFunction:a,that:function(){return this},toInteger:r,toLength:function(e){return e>0?v(r(e),9007199254740991):0},toIndex:function(e,t){return e=r(e),0>e?g(e+t,0):v(e,t)},has:function(e,t){return h.call(e,t)},create:Object.create,getProto:Object.getPrototypeOf,DESC:m,desc:o,getDesc:Object.getOwnPropertyDescriptor,setDesc:d,setDescs:Object.defineProperties,getKeys:Object.keys,getNames:Object.getOwnPropertyNames,getSymbols:Object.getOwnPropertySymbols,assertDefined:c,ES5Object:Object,toObject:function(e){return O.ES5Object(c(e))},hide:b,def:u(0),set:f.Symbol?i:b,each:[].forEach});"undefined"!=typeof __e&&(__e=l),"undefined"!=typeof __g&&(__g=f)},function(e,t,n){var r=n(19),o=n(28),i=r.isObject,u=r.toObject;r.each.call("freeze,seal,preventExtensions,isFrozen,isSealed,isExtensible,getOwnPropertyDescriptor,getPrototypeOf,keys,getOwnPropertyNames".split(","),function(e,t){var s=(r.core.Object||{})[e]||Object[e],a=0,c={};c[e]=0==t?function(e){return i(e)?s(e):e}:1==t?function(e){return i(e)?s(e):e}:2==t?function(e){return i(e)?s(e):e}:3==t?function(e){return i(e)?s(e):!0}:4==t?function(e){return i(e)?s(e):!0}:5==t?function(e){return i(e)?s(e):!1}:6==t?function(e,t){return s(u(e),t)}:7==t?function(e){return s(Object(r.assertDefined(e)))}:8==t?function(e){return s(u(e))}:n(29).get;try{s("z")}catch(f){a=1}o(o.S+o.F*a,"Object",c)})},function(e,t,n){var r=n(19),o=n(33),i=n(25).safe("iter"),u=n(22),s=u.step,a=u.Iterators;n(26)(Array,"Array",function(e,t){r.set(this,i,{o:r.toObject(e),i:0,k:t})},function(){var e=this[i],t=e.o,n=e.k,r=e.i++;return!t||r>=t.length?(e.o=void 0,s(1)):"keys"==n?s(0,r):"values"==n?s(0,t[r]):s(0,[r,t[r]])},"values"),a.Arguments=a.Array,o("keys"),o("values"),o("entries")},function(e,t,n){"use strict";function r(e,t){o.hide(e,c,t),f in[]&&o.hide(e,f,t)}var o=n(19),i=n(30),u=i.classof,s=n(31),a=s.obj,c=n(23)("iterator"),f="@@iterator",l=n(32)("iterators"),d={};r(d,o.that),e.exports={BUGGY:"keys"in[]&&!("next"in[].keys()),Iterators:l,step:function(e,t){return{value:t,done:!!e}},is:function(e){var t=Object(e),n=o.g.Symbol;return(n&&n.iterator||f)in t||c in t||o.has(l,u(t))},get:function(e){var t,n=o.g.Symbol;return void 0!=e&&(t=e[n&&n.iterator||f]||e[c]||l[u(e)]),s(o.isFunction(t),e," is not iterable!"),a(t.call(e))},set:r,create:function(e,t,n,r){e.prototype=o.create(r||d,{next:o.desc(1,n)}),i.set(e,t+" Iterator")}}},function(e,t,n){var r=n(19).g,o=n(32)("wks");e.exports=function(e){return o[e]||(o[e]=r.Symbol&&r.Symbol[e]||n(25).safe("Symbol."+e))}},function(e,t,n){var r=n(19);e.exports=function(e){return function(t,n){var o,i,u=String(r.assertDefined(t)),s=r.toInteger(n),a=u.length;return 0>s||s>=a?e?"":void 0:(o=u.charCodeAt(s),55296>o||o>56319||s+1===a||(i=u.charCodeAt(s+1))<56320||i>57343?e?u.charAt(s):o:e?u.slice(s,s+2):(o-55296<<10)+(i-56320)+65536)}}},function(e,t,n){function r(e){return"Symbol(".concat(void 0===e?"":e,")_",(++o+Math.random()).toString(36))}var o=0;r.safe=n(19).g.Symbol||r,e.exports=r},function(e,t,n){var r=n(28),o=n(34),i=n(19),u=n(30),s=n(22),a=n(23)("iterator"),c="@@iterator",f="keys",l="values",d=s.Iterators;e.exports=function(e,t,n,h,p,y,g){function v(e){function t(t){return new n(t,e)}switch(e){case f:return function(){return t(this)};case l:return function(){return t(this)}}return function(){return t(this)}}s.create(n,t,h);var m,b,O=t+" Iterator",x=e.prototype,w=x[a]||x[c]||p&&x[p],j=w||v(p);if(w){var k=i.getProto(j.call(new e));u.set(k,O,!0),i.FW&&i.has(x,c)&&s.set(k,i.that)}if((i.FW||g)&&s.set(x,j),d[t]=j,d[O]=i.that,p)if(m={keys:y?j:v(f),values:p==l?j:v(l),entries:p!=l?j:v("entries")},g)for(b in m)b in x||o(x,b,m[b]);else r(r.P+r.F*s.BUGGY,t,m)}},function(e){e.exports=function(e){return e.FW=!1,e.path=e.core,e}},function(e,t,n){function r(e,t){return function(){return e.apply(t,arguments)}}function o(e,t,n){var i,c,f,l,d=e&o.G,h=e&o.P,p=d?u:e&o.S?u[t]:(u[t]||{}).prototype,y=d?s:s[t]||(s[t]={});d&&(n=t);for(i in n)c=!(e&o.F)&&p&&i in p,c&&i in y||(f=c?p[i]:n[i],d&&!a(p[i])?l=n[i]:e&o.B&&c?l=r(f,u):e&o.W&&p[i]==f?!function(e){l=function(t){return this instanceof e?new e(t):e(t)},l.prototype=e.prototype}(f):l=h&&a(f)?r(Function.call,f):f,y[i]=l,h&&((y.prototype||(y.prototype={}))[i]=f))}var i=n(19),u=i.g,s=i.core,a=i.isFunction;o.F=1,o.G=2,o.S=4,o.P=8,o.B=16,o.W=32,e.exports=o},function(e,t,n){function r(e){try{return u(e)}catch(t){return s.slice()}}var o=n(19),i={}.toString,u=o.getNames,s="object"==typeof window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];e.exports.get=function(e){return s&&"[object Window]"==i.call(e)?r(e):u(o.toObject(e))}},function(e,t,n){function r(e){return u.call(e).slice(8,-1)}var o=n(19),i=n(23)("toStringTag"),u={}.toString;r.classof=function(e){var t,n;return void 0==e?void 0===e?"Undefined":"Null":"string"==typeof(n=(t=Object(e))[i])?n:r(t)},r.set=function(e,t,n){e&&!o.has(e=n?e:e.prototype,i)&&o.hide(e,i,t)},e.exports=r},function(e,t,n){function r(e,t,n){if(!e)throw TypeError(n?t+n:t)}var o=n(19);r.def=o.assertDefined,r.fn=function(e){if(!o.isFunction(e))throw TypeError(e+" is not a function!");return e},r.obj=function(e){if(!o.isObject(e))throw TypeError(e+" is not an object!");return e},r.inst=function(e,t,n){if(!(e instanceof t))throw TypeError(n+": use the 'new' operator!");return e},e.exports=r},function(e,t,n){var r=n(19),o="__core-js_shared__",i=r.g[o]||(r.g[o]={});e.exports=function(e){return i[e]||(i[e]={})}},function(e){e.exports=function(){}},function(e,t,n){e.exports=n(19).hide}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):"object"==typeof exports?exports.FakeRest=t():e.FakeRest=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";var r=n(3)["default"];Object.defineProperty(t,"__esModule",{value:!0});var o=n(1),i=r(o),u=n(2),s=r(u);t["default"]={Server:i["default"],Collection:s["default"]},e.exports=t["default"]},function(e,t,n){"use strict";function r(e){if(!e)return{};var t={},n=e.split("&");return n.map(function(e){if(-1===e.indexOf("="))t[e]=!0;else{var n=e.split("="),r=u(n,2),o=r[0],i=r[1];(0===i.indexOf("[")||0===i.indexOf("{"))&&(i=JSON.parse(i)),t[o.trim()]=i}}),t}var o=n(4)["default"],i=n(5)["default"],u=n(7)["default"],s=n(6)["default"],a=n(8)["default"],c=n(3)["default"];Object.defineProperty(t,"__esModule",{value:!0});var f=n(2),l=c(f),d=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?"":arguments[0];i(this,e),this.baseUrl=t,this.collections={},this.loggingEnabled=!1,this.requestInterceptors=[],this.responseInterceptors=[],this.batchUrl=null}return o(e,[{key:"init",value:function(e){for(var t in e)this.addCollection(t,new l["default"](e[t]))}},{key:"toggleLogging",value:function(){this.loggingEnabled=!this.loggingEnabled}},{key:"setBatch",value:function(e){this.batchUrl=e}},{key:"addCollection",value:function(e,t){this.collections[e]=t}},{key:"getCollection",value:function(e){return this.collections[e]}},{key:"getCollectionNames",value:function(){return s(this.collections)}},{key:"addRequestInterceptor",value:function(e){this.requestInterceptors.push(e)}},{key:"addResponseInterceptor",value:function(e){this.responseInterceptors.push(e)}},{key:"getCount",value:function(e,t){return this.collections[e].getCount(t)}},{key:"getAll",value:function(e,t){return this.collections[e].getAll(t)}},{key:"getOne",value:function(e,t){return this.collections[e].getOne(t)}},{key:"addOne",value:function(e,t){return this.collections[e].addOne(t)}},{key:"updateOne",value:function(e,t,n){return this.collections[e].updateOne(t,n)}},{key:"removeOne",value:function(e,t){return this.collections[e].removeOne(t)}},{key:"decode",value:function(e){if(e.queryString=decodeURIComponent(e.url.slice(e.url.indexOf("?")+1)),e.params=r(e.queryString),e.requestBody)try{e.json=JSON.parse(e.requestBody)}catch(t){}return this.requestInterceptors.reduce(function(e,t){return t(e)},e)}},{key:"respond",value:function(e,t,n){var r=arguments.length<=3||void 0===arguments[3]?200:arguments[3];t||(t={}),t["Content-Type"]||(t["Content-Type"]="application/json");var o={status:r,headers:t,body:e};return o=this.responseInterceptors.reduce(function(e,t){return t(e,n)},o),this.log(n,o),n.respond(o.status,o.headers,JSON.stringify(o.body))}},{key:"log",value:function(e,t){this.loggingEnabled&&(console.group?(console.groupCollapsed(e.method,e.url,"(FakeRest)"),console.group("request"),console.log(e.method,e.url),console.log("headers",e.requestHeaders),console.log("body ",e.requestBody),console.groupEnd(),console.group("response",t.status),console.log("headers",t.headers),console.log("body ",t.body),console.groupEnd(),console.groupEnd()):(console.log("FakeRest request ",e.method,e.url,"headers",e.requestHeaders,"body",e.requestBody),console.log("FakeRest response",t.status,"headers",t.headers,"body",t.body)))}},{key:"batch",value:function(e){var t=e.json,n=this.handle.bind(this),r=s(t).reduce(function(e,r){var o,i={url:t[r],method:"GET",params:{},respond:function(e,t,n){o={code:e,headers:s(t||{}).map(function(e){return{name:e,value:t[e]}}),body:n||{}}}};return n(i),e[r]=o||{code:404,headers:[],body:{}},e},{});return this.respond(r,{},e,200)}},{key:"handle",value:function(e){if(e=this.decode(e),this.batchUrl&&this.batchUrl===e.url&&"POST"===e.method)return this.batch(e);var t=!0,n=!1,r=void 0;try{for(var o,i=a(this.getCollectionNames());!(t=(o=i.next()).done);t=!0){var u=o.value,s=e.url.match(new RegExp("^"+this.baseUrl+"\\/("+u+")(\\/(\\d+))?(\\?.*)?$"));if(s)if(s[2]){var c=s[3];if("GET"==e.method)try{var f=this.getOne(u,c);return this.respond(f,null,e)}catch(l){return e.respond(404)}if("PUT"==e.method)try{var f=this.updateOne(u,c,e.json);return this.respond(f,null,e)}catch(l){return e.respond(404)}if("DELETE"==e.method)try{var f=this.removeOne(u,c);return this.respond(f,null,e)}catch(l){return e.respond(404)}}else{if("GET"==e.method){var d=e.params,h={};for(var p in d)"range"!==p&&(h[p]=d[p]);var y=this.getCount(u,h),v=void 0,g=void 0,b=void 0;if(y>0){v=this.getAll(u,d);var m=d.range?d.range[0]:0,O=d.range?Math.min(v.length-1+m,d.range[1]):v.length-1;g="items "+m+"-"+O+"/"+y,b=v.length==y?200:206}else v=[],g="items */0",b=200;return this.respond(v,{"Content-Range":g},e,b)}if("POST"==e.method){var x=this.addOne(u,e.json),j=this.baseUrl+"/"+u+"/"+x[this.getCollection(u).identifierName];return this.respond(x,{Location:j},e,201)}}}}catch(w){n=!0,r=w}finally{try{!t&&i["return"]&&i["return"]()}finally{if(n)throw r}}}},{key:"getHandler",value:function(){return this.handle.bind(this)}}]),e}();t["default"]=d,e.exports=t["default"]},function(e,t,n){"use strict";function r(e,t){if("function"==typeof t)return e.filter(t);if(t instanceof Object){var n=a(t).map(function(e){if("q"===e){var n=function(){var e=new RegExp(t.q,"i");return{v:function(t){for(var n in t)if(t[n]&&t[n].match&&null!==t[n].match(e))return!0;return!1}}}();if("object"==typeof n)return n.v}var r=t[e];if(-1!==e.indexOf("_lte")){var o=function(){var t=e.replace(/(_lte)$/,"");return{v:function(e){return e[t]<=r}}}();if("object"==typeof o)return o.v}if(-1!==e.indexOf("_gte")){var i=function(){var t=e.replace(/(_gte)$/,"");return{v:function(e){return e[t]>=r}}}();if("object"==typeof i)return i.v}if(-1!==e.indexOf("_lt")){var u=function(){var t=e.replace(/(_lt)$/,"");return{v:function(e){return e[t]<r}}}();if("object"==typeof u)return u.v}if(-1!==e.indexOf("_gt")){var s=function(){var t=e.replace(/(_gt)$/,"");return{v:function(e){return e[t]>r}}}();if("object"==typeof s)return s.v}return function(n){return"[object Array]"==Object.prototype.toString.call(n[e])&&"string"==typeof t[e]?-1!==n[e].indexOf(r):"boolean"==typeof n[e]&&"string"==typeof t[e]?n[e]==("true"===r?!0:!1):n[e]==r}});return e.filter(function(e){return n.reduce(function(t,n){return t&&n(e)},!0)})}throw new Error("Unsupported filter type")}function o(e,t){if("function"==typeof t)return e.sort(t);if("string"==typeof t)return e.sort(function(e,n){return e[t]>n[t]?1:e[t]<n[t]?-1:0});if(Array.isArray(t)){var n=function(){var n=t[0],r="asc"==t[1].toLowerCase()?1:-1;return{v:e.sort(function(e,t){return e[n]>t[n]?r:e[n]<t[n]?-1*r:0})}}();if("object"==typeof n)return n.v}throw new Error("Unsupported sort type")}function i(e,t){if(Array.isArray(t))return e.slice(t[0],void 0!==t[1]?t[1]+1:void 0);throw new Error("Unsupported range type")}var u=n(4)["default"],s=n(5)["default"],a=n(6)["default"];Object.defineProperty(t,"__esModule",{value:!0}),n(9);var c=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?[]:arguments[0],n=arguments.length<=1||void 0===arguments[1]?"id":arguments[1];if(s(this,e),!Array.isArray(t))throw new Error("Can't initialize a Collection with anything else than an array of items");this.sequence=0,this.identifierName=n,this.items=[],t.map(this.addOne.bind(this))}return u(e,[{key:"getCount",value:function(e){return this.getAll(e).length}},{key:"getAll",value:function(e){var t=this.items.map(function(e){return e});return e&&(e.filter&&(t=r(t,e.filter)),e.sort&&(t=o(t,e.sort)),e.range&&(t=i(t,e.range))),t}},{key:"getIndex",value:function(e){var t=this;return this.items.findIndex(function(n){return n[t.identifierName]==e})}},{key:"getOne",value:function(e){var t=this.getIndex(e);if(-1===t)throw new Error("No item with identifier "+e);return this.items[t]}},{key:"addOne",value:function(e){var t=e[this.identifierName];if(void 0!==t){if(-1!==this.getIndex(t))throw new Error("An item with the identifier "+t+" already exists");this.sequence=Math.max(this.sequence,t)+1}else e[this.identifierName]=this.sequence++;return this.items.push(e),e}},{key:"updateOne",value:function(e,t){var n=this.getIndex(e);if(-1===n)throw new Error("No item with identifier "+e);for(var r in t)this.items[n][r]=t[r];return this.items[n]}},{key:"removeOne",value:function(e){var t=this.getIndex(e);if(-1===t)throw new Error("No item with identifier "+e);var n=this.items[t];return this.items.splice(t,1),e==this.sequence-1&&this.sequence--,n}}]),e}();t["default"]=c,e.exports=t["default"]},function(e,t){"use strict";t["default"]=function(e){return e&&e.__esModule?e:{"default":e}},t.__esModule=!0},function(e,t,n){"use strict";var r=n(10)["default"];t["default"]=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),r(e,o.key,o)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),t.__esModule=!0},function(e,t){"use strict";t["default"]=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},t.__esModule=!0},function(e,t,n){e.exports={"default":n(13),__esModule:!0}},function(e,t,n){"use strict";var r=n(8)["default"],o=n(11)["default"];t["default"]=function(){function e(e,t){var n=[],o=!0,i=!1,u=void 0;try{for(var s,a=r(e);!(o=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);o=!0);}catch(c){i=!0,u=c}finally{try{!o&&a["return"]&&a["return"]()}finally{if(i)throw u}}return n}return function(t,n){if(Array.isArray(t))return t;if(o(Object(t)))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),t.__esModule=!0},function(e,t,n){e.exports={"default":n(12),__esModule:!0}},function(){!function(){if(!Array.prototype.findIndex){var e=function(e){var t=Object(this),n=Math.max(0,t.length)>>>0;if(0===n)return-1;if("function"!=typeof e||"[object Function]"!==Object.prototype.toString.call(e))throw new TypeError("Array#findIndex: predicate must be a function");for(var r=arguments.length>1?arguments[1]:void 0,o=0;n>o;o++)if(e.call(r,t[o],o,t))return o;return-1};if(Object.defineProperty)try{Object.defineProperty(Array.prototype,"findIndex",{value:e,configurable:!0,writable:!0})}catch(t){}Array.prototype.findIndex||(Array.prototype.findIndex=e)}}(this)},function(e,t,n){e.exports={"default":n(15),__esModule:!0}},function(e,t,n){e.exports={"default":n(14),__esModule:!0}},function(e,t,n){n(16),n(17),n(18),e.exports=n(19).core.getIterator},function(e,t,n){n(20),e.exports=n(19).core.Object.keys},function(e,t,n){n(16),n(17),n(18),e.exports=n(19).core.isIterable},function(e,t,n){var r=n(19);e.exports=function(e,t,n){return r.setDesc(e,t,n)}},function(e,t,n){n(25);var r=n(19),o=n(23).Iterators,i=n(26)("iterator"),u=o.Array,s=r.g.NodeList,a=r.g.HTMLCollection,c=s&&s.prototype,f=a&&a.prototype;r.FW&&(!s||i in c||r.hide(c,i,u),!a||i in f||r.hide(f,i,u)),o.NodeList=o.HTMLCollection=u},function(e,t,n){var r=n(19).set,o=n(21)(!0),i=n(22).safe("iter"),u=n(23),s=u.step;n(24)(String,"String",function(e){r(this,i,{o:String(e),i:0})},function(){var e,t=this[i],n=t.o,r=t.i;return r>=n.length?s(1):(e=o(n,r),t.i+=e.length,s(0,e))})},function(e,t,n){var r=n(19).core,o=n(23);r.isIterable=o.is,r.getIterator=o.get},function(e,t,n){"use strict";function r(e){return isNaN(e=+e)?0:(e>0?y:p)(e)}function o(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}function i(e,t,n){return e[t]=n,e}function u(e){return b?function(t,n,r){return O.setDesc(t,n,o(e,r))}:i}function s(e){return null!==e&&("object"==typeof e||"function"==typeof e)}function a(e){return"function"==typeof e}function c(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e}var f="undefined"!=typeof self?self:Function("return this")(),l={},d=Object.defineProperty,h={}.hasOwnProperty,p=Math.ceil,y=Math.floor,v=Math.max,g=Math.min,b=!!function(){try{return 2==d({},"a",{get:function(){return 2}}).a}catch(e){}}(),m=u(1),O=e.exports=n(27)({g:f,core:l,html:f.document&&document.documentElement,isObject:s,isFunction:a,that:function(){return this},toInteger:r,toLength:function(e){return e>0?g(r(e),9007199254740991):0},toIndex:function(e,t){return e=r(e),0>e?v(e+t,0):g(e,t)},has:function(e,t){return h.call(e,t)},create:Object.create,getProto:Object.getPrototypeOf,DESC:b,desc:o,getDesc:Object.getOwnPropertyDescriptor,setDesc:d,setDescs:Object.defineProperties,getKeys:Object.keys,getNames:Object.getOwnPropertyNames,getSymbols:Object.getOwnPropertySymbols,assertDefined:c,ES5Object:Object,toObject:function(e){return O.ES5Object(c(e))},hide:m,def:u(0),set:f.Symbol?i:m,each:[].forEach});"undefined"!=typeof __e&&(__e=l),"undefined"!=typeof __g&&(__g=f)},function(e,t,n){var r=n(19),o=n(28),i=r.isObject,u=r.toObject;r.each.call("freeze,seal,preventExtensions,isFrozen,isSealed,isExtensible,getOwnPropertyDescriptor,getPrototypeOf,keys,getOwnPropertyNames".split(","),function(e,t){var s=(r.core.Object||{})[e]||Object[e],a=0,c={};c[e]=0==t?function(e){return i(e)?s(e):e}:1==t?function(e){return i(e)?s(e):e}:2==t?function(e){return i(e)?s(e):e}:3==t?function(e){return i(e)?s(e):!0}:4==t?function(e){return i(e)?s(e):!0}:5==t?function(e){return i(e)?s(e):!1}:6==t?function(e,t){return s(u(e),t)}:7==t?function(e){return s(Object(r.assertDefined(e)))}:8==t?function(e){return s(u(e))}:n(29).get;try{s("z")}catch(f){a=1}o(o.S+o.F*a,"Object",c)})},function(e,t,n){var r=n(19);e.exports=function(e){return function(t,n){var o,i,u=String(r.assertDefined(t)),s=r.toInteger(n),a=u.length;return 0>s||s>=a?e?"":void 0:(o=u.charCodeAt(s),55296>o||o>56319||s+1===a||(i=u.charCodeAt(s+1))<56320||i>57343?e?u.charAt(s):o:e?u.slice(s,s+2):(o-55296<<10)+(i-56320)+65536)}}},function(e,t,n){function r(e){return"Symbol(".concat(void 0===e?"":e,")_",(++o+Math.random()).toString(36))}var o=0;r.safe=n(19).g.Symbol||r,e.exports=r},function(e,t,n){"use strict";function r(e,t){o.hide(e,c,t),f in[]&&o.hide(e,f,t)}var o=n(19),i=n(31),u=i.classof,s=n(32),a=s.obj,c=n(26)("iterator"),f="@@iterator",l=n(33)("iterators"),d={};r(d,o.that),e.exports={BUGGY:"keys"in[]&&!("next"in[].keys()),Iterators:l,step:function(e,t){return{value:t,done:!!e}},is:function(e){var t=Object(e),n=o.g.Symbol;return(n&&n.iterator||f)in t||c in t||o.has(l,u(t))},get:function(e){var t,n=o.g.Symbol;return void 0!=e&&(t=e[n&&n.iterator||f]||e[c]||l[u(e)]),s(o.isFunction(t),e," is not iterable!"),a(t.call(e))},set:r,create:function(e,t,n,r){e.prototype=o.create(r||d,{next:o.desc(1,n)}),i.set(e,t+" Iterator")}}},function(e,t,n){var r=n(28),o=n(30),i=n(19),u=n(31),s=n(23),a=n(26)("iterator"),c="@@iterator",f="keys",l="values",d=s.Iterators;e.exports=function(e,t,n,h,p,y,v){function g(e){function t(t){return new n(t,e)}switch(e){case f:return function(){return t(this)};case l:return function(){return t(this)}}return function(){return t(this)}}s.create(n,t,h);var b,m,O=t+" Iterator",x=e.prototype,j=x[a]||x[c]||p&&x[p],w=j||g(p);if(j){var _=i.getProto(w.call(new e));u.set(_,O,!0),i.FW&&i.has(x,c)&&s.set(_,i.that)}if((i.FW||v)&&s.set(x,w),d[t]=w,d[O]=i.that,p)if(b={keys:y?w:g(f),values:p==l?w:g(l),entries:p!=l?w:g("entries")},v)for(m in b)m in x||o(x,m,b[m]);else r(r.P+r.F*s.BUGGY,t,b)}},function(e,t,n){var r=n(19),o=n(34),i=n(22).safe("iter"),u=n(23),s=u.step,a=u.Iterators;n(24)(Array,"Array",function(e,t){r.set(this,i,{o:r.toObject(e),i:0,k:t})},function(){var e=this[i],t=e.o,n=e.k,r=e.i++;return!t||r>=t.length?(e.o=void 0,s(1)):"keys"==n?s(0,r):"values"==n?s(0,t[r]):s(0,[r,t[r]])},"values"),a.Arguments=a.Array,o("keys"),o("values"),o("entries")},function(e,t,n){var r=n(19).g,o=n(33)("wks");e.exports=function(e){return o[e]||(o[e]=r.Symbol&&r.Symbol[e]||n(22).safe("Symbol."+e))}},function(e){e.exports=function(e){return e.FW=!1,e.path=e.core,e}},function(e,t,n){function r(e,t){return function(){return e.apply(t,arguments)}}function o(e,t,n){var i,c,f,l,d=e&o.G,h=e&o.P,p=d?u:e&o.S?u[t]:(u[t]||{}).prototype,y=d?s:s[t]||(s[t]={});d&&(n=t);for(i in n)c=!(e&o.F)&&p&&i in p,c&&i in y||(f=c?p[i]:n[i],d&&!a(p[i])?l=n[i]:e&o.B&&c?l=r(f,u):e&o.W&&p[i]==f?!function(e){l=function(t){return this instanceof e?new e(t):e(t)},l.prototype=e.prototype}(f):l=h&&a(f)?r(Function.call,f):f,y[i]=l,h&&((y.prototype||(y.prototype={}))[i]=f))}var i=n(19),u=i.g,s=i.core,a=i.isFunction;o.F=1,o.G=2,o.S=4,o.P=8,o.B=16,o.W=32,e.exports=o},function(e,t,n){function r(e){try{return u(e)}catch(t){return s.slice()}}var o=n(19),i={}.toString,u=o.getNames,s="object"==typeof window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];e.exports.get=function(e){return s&&"[object Window]"==i.call(e)?r(e):u(o.toObject(e))}},function(e,t,n){e.exports=n(19).hide},function(e,t,n){function r(e){return u.call(e).slice(8,-1)}var o=n(19),i=n(26)("toStringTag"),u={}.toString;r.classof=function(e){var t,n;return void 0==e?void 0===e?"Undefined":"Null":"string"==typeof(n=(t=Object(e))[i])?n:r(t)},r.set=function(e,t,n){e&&!o.has(e=n?e:e.prototype,i)&&o.hide(e,i,t)},e.exports=r},function(e,t,n){function r(e,t,n){if(!e)throw TypeError(n?t+n:t)}var o=n(19);r.def=o.assertDefined,r.fn=function(e){if(!o.isFunction(e))throw TypeError(e+" is not a function!");return e},r.obj=function(e){if(!o.isObject(e))throw TypeError(e+" is not an object!");return e},r.inst=function(e,t,n){if(!(e instanceof t))throw TypeError(n+": use the 'new' operator!");return e},e.exports=r},function(e,t,n){var r=n(19),o="__core-js_shared__",i=r.g[o]||(r.g[o]={});e.exports=function(e){return i[e]||(i[e]={})}},function(e){e.exports=function(){}}])});
{
"name": "fakerest",
"version": "1.0.8",
"version": "1.0.9",
"repository": "https://github.com/marmelab/FakeRest",

@@ -5,0 +5,0 @@ "description": "Patch XMLHttpRequest to fake a REST server based on JSON data. ",

@@ -81,26 +81,45 @@ # FakeRest [![Build Status](https://travis-ci.org/marmelab/FakeRest.svg?branch=master)](https://travis-ci.org/marmelab/FakeRest)

```
GET /books?filter={author_id:1}&sort=['title','desc']&range=[0-9]
GET /books?filter={author_id:1}&sort=['title','desc']&range=[0-9]
HTTP 1.1 200 OK
Content-Range: items 0-1/2
Content-Type: application/json
[
{ id: 3, author_id: 1, title: 'Sense and Sensibility' },
{ id: 2, author_id: 1, title: 'Pride and Prejudice' }
]
HTTP 1.1 200 OK
Content-Range: items 0-1/2
Content-Type: application/json
[
{ id: 3, author_id: 1, title: 'Sense and Sensibility' },
{ id: 2, author_id: 1, title: 'Pride and Prejudice' }
]
// the special "q" filter makes a full-text search on all text fields
GET /books?filter={q:'and'}
The `filter` param must be a serialized object litteral describing the criteria to apply to the search query.
HTTP 1.1 200 OK
Content-Range: items 0-2/3
Content-Type: application/json
[
{ id: 1, author_id: 0, title: 'War and Peace' },
{ id: 2, author_id: 1, title: 'Pride and Prejudice' },
{ id: 3, author_id: 1, title: 'Sense and Sensibility' }
]
```
GET /books?filter={author_id:1} // return books where author_id is equal to 1
// use _gt, _gte, _lte, or _lt suffix on filter names to make range queries
GET /books?filter={price_lte:20} // return books where price is less than or equal to 20
GET /books?filter={price_gt:20} // return books where price is greater than 20
// use the special "q" filter to make a full-text search on all text fields
GET /books?filter={q:'and'} // return books where any of the book properties contains the string 'and'
HTTP 1.1 200 OK
Content-Range: items 0-2/3
Content-Type: application/json
[
{ id: 1, author_id: 0, title: 'War and Peace' },
{ id: 2, author_id: 1, title: 'Pride and Prejudice' },
{ id: 3, author_id: 1, title: 'Sense and Sensibility' }
]
// when the filter object contains more than one property, the criteria combine with an AND logic
GET /books?filter={published_at_gte:'2015-06-12',published_at_lte:'2015-06-15'} // return books published between two dates
The `sort` param must be a serialized array litteral defining first the property used for sorting, then the sorting direction.
GET /author?sort=['date_of_birth','asc'] // return authors, the oldest first
GET /author?sort=['date_of_birth','desc'] // return authors, the youngest first
The `range` param defines the number of results by specifying the rank of the first and last result. The first result is #0.
GET /books?range=[0-9] // return the first 10 books
GET /books?range=[10-19] // return the 10 next books
* `POST /foo` returns a status 201 with a `Location` header for the newly created resource, and the new resource in the body.

@@ -107,0 +126,0 @@

@@ -8,7 +8,8 @@ import 'array.prototype.findindex';

if (filter instanceof Object) {
let regex = filter.q ? new RegExp(filter.q, 'i') : null;
return items.filter(item => {
for (let key in filter) {
if (key === 'q') {
// full-text filter
// turn filter properties to functions
var filterFunctions = Object.keys(filter).map(key => {
if (key === 'q') {
let regex = new RegExp(filter.q, 'i');
// full-text filter
return item => {
for (let itemKey in item) {

@@ -18,15 +19,44 @@ if (item[itemKey] && item[itemKey].match && item[itemKey].match(regex) !== null) return true;

return false;
}
// simple filter
let value = filter[key];
};
}
let value = filter[key];
if (key.indexOf('_lte') !== -1) {
// less than or equal
let realKey = key.replace(/(_lte)$/, '');
return item => item[realKey] <= value;
}
if (key.indexOf('_gte') !== -1) {
// less than or equal
let realKey = key.replace(/(_gte)$/, '');
return item => item[realKey] >= value;
}
if (key.indexOf('_lt') !== -1) {
// less than or equal
let realKey = key.replace(/(_lt)$/, '');
return item => item[realKey] < value;
}
if (key.indexOf('_gt') !== -1) {
// less than or equal
let realKey = key.replace(/(_gt)$/, '');
return item => item[realKey] > value;
}
return item => {
if (Object.prototype.toString.call(item[key]) == '[object Array]' && typeof filter[key] == 'string') {
// simple filter but array item value: make that a where ... in
return item[key].indexOf(value) !== -1;
}
if (typeof item[key] == 'boolean' && typeof filter[key] == 'string') {
value = filter[key] === 'true' ? true : false;
// simple filter but boolean item value: make that a boolean where
return item[key] == (value === 'true' ? true : false);
}
if (item[key] != value) return false;
// simple filter
return item[key] == value;
}
return true;
});
// only the items matching all filters functions are in (AND logic)
return items.filter(item => {
return filterFunctions.reduce((selected, filterFunction) => {
return selected && filterFunction(item);
}, true);
})
}

@@ -33,0 +63,0 @@ throw new Error('Unsupported filter type');

@@ -155,2 +155,12 @@ /*global describe,it,expect,beforeEach,jasmine*/

it('should filter by range using _gte, _gt, _lte, and _lt', function() {
var collection = new Collection([{ v: 1 }, { v: 2 }, { v: 3 } ]);
expect(collection.getAll({filter: { v_gte: 2 } })).toEqual([ {v: 2, id: 1}, {v: 3, id: 2} ])
expect(collection.getAll({filter: { v_gt: 2 } })).toEqual([ {v: 3, id: 2} ])
expect(collection.getAll({filter: { v_gte: 4 } })).toEqual([]);
expect(collection.getAll({filter: { v_lte: 2 } })).toEqual([ {v: 1, id: 0}, {v: 2, id: 1} ])
expect(collection.getAll({filter: { v_lt: 2 } })).toEqual([ {v: 1, id: 0} ])
expect(collection.getAll({filter: { v_lte: 0 } })).toEqual([]);
});
it('should filter by the special q full-text filter', function() {

@@ -169,2 +179,7 @@ var collection = new Collection([

it('should combine all filters with an AND logic', function() {
var collection = new Collection([{ v: 1 }, { v: 2 }, { v: 3 } ]);
expect(collection.getAll({filter: { v_gte: 2, v_lte: 2 } })).toEqual([ {v: 2, id: 1} ]);
})
it('should not affect further requests', function() {

@@ -171,0 +186,0 @@ var collection = new Collection([{name: 'c'}, {name: 'a'}, {name: 'b'}]);

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