Comparing version
@@ -10,2 +10,12 @@ # Changelog | ||
## [1.0.4] - 2022-11-20 | ||
### Added | ||
- Filters toggle method | ||
### Changed | ||
- Add return types everywhere | ||
## [1.0.3] - 2022-11-20 | ||
@@ -12,0 +22,0 @@ |
@@ -21,2 +21,3 @@ import { type FlexibleUrl } from './flex-url.js'; | ||
remove(value: string, modifiers?: QueryParameterModifiers): FlexibleUrl; | ||
toggle(value: string, modifiers?: QueryParameterModifiers): FilterParameterManipulator; | ||
} |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).flexUrl={})}(this,function(t){function e(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function n(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}var i=0;function r(t){return"__private_"+i+++"_"+t}function o(t,e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var a=/*#__PURE__*/function(){function t(t){this.flexUrl=void 0,this.flexUrl=t,this.flexUrl=t}return t.prototype.has=function(t,e,n){return void 0===n&&(n=[]),this.flexUrl.queryParams.has("filter",e,[t].concat(n))},t}(),s=/*#__PURE__*/function(){function t(t,e){this.manipulator=void 0,this.filterKey=void 0,this.conditional=void 0,this.manipulator=t,this.filterKey=e,this.manipulator=t,this.filterKey=e}t.fromUrl=function(e,n){return new t(e.queryParam("filter"),n)};var e=t.prototype;return e.add=function(e,n){return void 0===n&&(n=[]),new t(this.manipulator.add(e,[this.filterKey].concat(n)),this.filterKey)},e.set=function(e,n){return void 0===n&&(n=[]),new t(this.manipulator.set(e,[this.filterKey].concat(n)),this.filterKey)},e.append=function(e){return new t(this.manipulator.append(e),this.filterKey)},e.remove=function(t,e){return void 0===e&&(e=[]),this.manipulator.remove(t,[this.filterKey].concat(e))},n(t,[{key:"or",get:function(){return this.conditional="or",this}},{key:"and",get:function(){return this.conditional="and",this}}]),t}();function u(t,e,n){var i=-1;for(i=0;i<t.length;i++)e.includes(i)&&(t[i]="function"==typeof n?n(t[i]):n)}var f=/*#__PURE__*/r("name"),l=/*#__PURE__*/r("value"),h=/*#__PURE__*/r("modifiers"),d=/*#__PURE__*/function(){function t(t,e,n){void 0===n&&(n=[]),Object.defineProperty(this,f,{writable:!0,value:void 0}),Object.defineProperty(this,l,{writable:!0,value:void 0}),Object.defineProperty(this,h,{writable:!0,value:void 0}),o(this,f)[f]=t,o(this,l)[l]=e,o(this,h)[h]=n}t.queryParamKey=function(t,e){return void 0===e&&(e=[]),""+t+e.map(function(t){return"["+t+"]"}).join("")};var e=t.prototype;return e.setValue=function(t){return o(this,l)[l]=t,this},e.setModifiers=function(t){return o(this,h)[h]=t,this},e.toString=function(){return this.queryParamKey+"="+this.value},t.fromString=function(e){var n=decodeURIComponent(e).split("="),i=n[0],r=n[1],o=i,a=[];if(i.includes("[")){var s=i.split(/\[|\|/);o=s.shift(),a=s.map(function(t){return t.replace("]","")})}return o?new t(o,r,a):null},n(t,[{key:"name",get:function(){return encodeURIComponent(o(this,f)[f])}},{key:"value",get:function(){return encodeURIComponent(o(this,l)[l])}},{key:"modifiers",get:function(){return o(this,h)[h].map(function(t){return encodeURIComponent(t)})}},{key:"queryParamKey",get:function(){return t.queryParamKey(this.name,this.modifiers)}}]),t}(),c=/*#__PURE__*/function(){function t(t){this.flexUrl=void 0,this.flexUrl=t,this.flexUrl=t}return t.find=function(t,e,n,i){return t.params.findIndex(function(t){return t.queryParamKey===d.queryParamKey(e,i)&&(!n||t.value===n)})},t.prototype.has=function(e,n,i){return-1!==t.find(this.flexUrl,e,n,i)},t}(),p=/*#__PURE__*/function(){function t(t,e,n,i,r){void 0===i&&(i=[]),void 0===r&&(r=[]),this.flexUrl=void 0,this.name=void 0,this.value=void 0,this.indexes=void 0,this.flexUrl=t,this.name=e,this.value=n,this.indexes=r,this.flexUrl=t,this.name=e,this.value=n,this.indexes=r.length>0?r:function(t,e){var n=[],i=-1;for(i=0;i<t.length;i++)e(t[i])&&n.push(i);return n}(t.params,function(t){return t.queryParamKey===d.queryParamKey(e,i)&&(!n||t.value===n)})}t.fromIndexes=function(e,n,i){return new t(e,n,void 0,[],i)};var e=t.prototype;return e.set=function(t,e){return void 0===e&&(e=[]),u(this.flexUrl.params,this.indexes,new d(this.name,t,e)),this},e.add=function(e,n){void 0===n&&(n=[]);var i=c.find(this.flexUrl,this.name,e,n);return-1!==i?t.fromIndexes(this.flexUrl,this.name,[i]):(this.flexUrl.params.push(new d(this.name,e,n)),new t(this.flexUrl,this.name,e,n))},e.append=function(t){var e;if(!(this.value||null!=(e=this.indexes)&&e.length))throw new Error("Query parameter value must be provided to append to the right parameter.");return u(this.flexUrl.params,this.indexes,function(e){return e.setValue(""+e.value+t)}),this},e.toggle=function(t,e){void 0===e&&(e=[]);var n=c.find(this.flexUrl,this.name,t,e);return-1!==n?(this.remove(t,e,n),this):this.add(t,e)},e.remove=function(t,e,n){void 0===e&&(e=[]);var i=null!=n?n:c.find(this.flexUrl,this.name,t,e);return-1!==i&&(delete this.flexUrl.params[i],this.flexUrl.params=this.flexUrl.params.filter(Boolean)),this.flexUrl},e.withModifiers=function(t){return u(this.flexUrl.params,this.indexes,function(e){return e.setModifiers(t)}),this},t}(),m=/*#__PURE__*/function(){function t(t){this.params=[],this.baseUrl=void 0,this.hashFragment=void 0;var e="string"==typeof t?new URL(t):t;if(e||"undefined"==typeof window||(e=window.location),!e)throw new Error("Need to provide a valid URL");this.hashFragment=e.hash,this.baseUrl=e.origin;for(var n=e.search.replace("?","").split("&"),i=0;i<n.length;i++){var r=d.fromString(n[i]);r&&this.params.push(r)}}var e=t.prototype;return e.queryParam=function(t,e){return new p(this,t,e)},e.filter=function(t){return s.fromUrl(this,t)},e.clear=function(){return this.params=[],this},e.toString=function(){return[this.baseUrl,this.params.map(function(t){return t.toString()}).join("&")].filter(Boolean).join("?")+this.hashFragment},n(t,[{key:"queryParams",get:function(){return new c(this)}},{key:"filters",get:function(){return new a(this)}}]),t}();t.FlexibleUrl=m,t.flexUrl=function(t){return new m(t)}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).flexUrl={})}(this,function(t){function e(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function n(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}var i=0;function r(t){return"__private_"+i+++"_"+t}function o(t,e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var a=/*#__PURE__*/function(){function t(t){this.flexUrl=void 0,this.flexUrl=t,this.flexUrl=t}return t.prototype.has=function(t,e,n){return void 0===n&&(n=[]),this.flexUrl.queryParams.has("filter",e,[t].concat(n))},t}(),s=/*#__PURE__*/function(){function t(t,e){this.manipulator=void 0,this.filterKey=void 0,this.conditional=void 0,this.manipulator=t,this.filterKey=e,this.manipulator=t,this.filterKey=e}t.fromUrl=function(e,n){return new t(e.queryParam("filter"),n)};var e=t.prototype;return e.add=function(e,n){return void 0===n&&(n=[]),new t(this.manipulator.add(e,[this.filterKey].concat(n)),this.filterKey)},e.set=function(e,n){return void 0===n&&(n=[]),new t(this.manipulator.set(e,[this.filterKey].concat(n)),this.filterKey)},e.append=function(e){return new t(this.manipulator.append(e),this.filterKey)},e.remove=function(t,e){return void 0===e&&(e=[]),this.manipulator.remove(t,[this.filterKey].concat(e))},e.toggle=function(e,n){return void 0===n&&(n=[]),new t(this.manipulator.toggle(e,[this.filterKey].concat(n)),this.filterKey)},n(t,[{key:"or",get:function(){return this.conditional="or",this}},{key:"and",get:function(){return this.conditional="and",this}}]),t}();function u(t,e,n){var i=-1;for(i=0;i<t.length;i++)e.includes(i)&&(t[i]="function"==typeof n?n(t[i]):n)}var f=/*#__PURE__*/r("name"),l=/*#__PURE__*/r("value"),h=/*#__PURE__*/r("modifiers"),d=/*#__PURE__*/function(){function t(t,e,n){void 0===n&&(n=[]),Object.defineProperty(this,f,{writable:!0,value:void 0}),Object.defineProperty(this,l,{writable:!0,value:void 0}),Object.defineProperty(this,h,{writable:!0,value:void 0}),o(this,f)[f]=t,o(this,l)[l]=e,o(this,h)[h]=n}t.queryParamKey=function(t,e){return void 0===e&&(e=[]),""+t+e.map(function(t){return"["+t+"]"}).join("")};var e=t.prototype;return e.setValue=function(t){return o(this,l)[l]=t,this},e.setModifiers=function(t){return o(this,h)[h]=t,this},e.toString=function(){return this.queryParamKey+"="+this.value},t.fromString=function(e){var n=decodeURIComponent(e).split("="),i=n[0],r=n[1],o=i,a=[];if(i.includes("[")){var s=i.split(/\[|\|/);o=s.shift(),a=s.map(function(t){return t.replace("]","")})}if(o)return new t(o,r,a)},n(t,[{key:"name",get:function(){return encodeURIComponent(o(this,f)[f])}},{key:"value",get:function(){return encodeURIComponent(o(this,l)[l])}},{key:"modifiers",get:function(){return o(this,h)[h].map(function(t){return encodeURIComponent(t)})}},{key:"queryParamKey",get:function(){return t.queryParamKey(this.name,this.modifiers)}}]),t}(),c=/*#__PURE__*/function(){function t(t){this.flexUrl=void 0,this.flexUrl=t,this.flexUrl=t}return t.find=function(t,e,n,i){return t.params.findIndex(function(t){return t.queryParamKey===d.queryParamKey(e,i)&&(!n||t.value===n)})},t.prototype.has=function(e,n,i){return-1!==t.find(this.flexUrl,e,n,i)},t}(),p=/*#__PURE__*/function(){function t(t,e,n,i,r){void 0===i&&(i=[]),void 0===r&&(r=[]),this.flexUrl=void 0,this.name=void 0,this.value=void 0,this.indexes=void 0,this.flexUrl=t,this.name=e,this.value=n,this.indexes=r,this.flexUrl=t,this.name=e,this.value=n,this.indexes=r.length>0?r:function(t,e){var n=[],i=-1;for(i=0;i<t.length;i++)e(t[i])&&n.push(i);return n}(t.params,function(t){return t.queryParamKey===d.queryParamKey(e,i)&&(!n||t.value===n)})}t.fromIndexes=function(e,n,i){return new t(e,n,void 0,[],i)};var e=t.prototype;return e.set=function(t,e){return void 0===e&&(e=[]),u(this.flexUrl.params,this.indexes,new d(this.name,t,e)),this},e.add=function(e,n){void 0===n&&(n=[]);var i=c.find(this.flexUrl,this.name,e,n);return-1!==i?t.fromIndexes(this.flexUrl,this.name,[i]):(this.flexUrl.params.push(new d(this.name,e,n)),new t(this.flexUrl,this.name,e,n))},e.append=function(t){var e;if(!(this.value||null!=(e=this.indexes)&&e.length))throw new Error("Query parameter value must be provided to append to the right parameter.");return u(this.flexUrl.params,this.indexes,function(e){return e.setValue(""+e.value+t)}),this},e.toggle=function(t,e){void 0===e&&(e=[]);var n=c.find(this.flexUrl,this.name,t,e);return-1!==n?(this.remove(t,e,n),this):this.add(t,e)},e.remove=function(t,e,n){void 0===e&&(e=[]);var i=null!=n?n:c.find(this.flexUrl,this.name,t,e);return-1!==i&&(delete this.flexUrl.params[i],this.flexUrl.params=this.flexUrl.params.filter(Boolean)),this.flexUrl},e.withModifiers=function(t){return u(this.flexUrl.params,this.indexes,function(e){return e.setModifiers(t)}),this},t}(),m=/*#__PURE__*/function(){function t(t){this.params=[],this.baseUrl=void 0,this.hashFragment=void 0;var e="string"==typeof t?new URL(t):t;if(e||"undefined"==typeof window||(e=window.location),!e)throw new Error("Need to provide a valid URL");this.hashFragment=e.hash,this.baseUrl=e.origin;for(var n=e.search.replace("?","").split("&"),i=0;i<n.length;i++){var r=d.fromString(n[i]);r&&this.params.push(r)}}var e=t.prototype;return e.queryParam=function(t,e){return new p(this,t,e)},e.filter=function(t){return s.fromUrl(this,t)},e.clear=function(){return this.params=[],this},e.toString=function(){return[this.baseUrl,this.params.map(function(t){return t.toString()}).join("&")].filter(Boolean).join("?")+this.hashFragment},n(t,[{key:"queryParams",get:function(){return new c(this)}},{key:"filters",get:function(){return new a(this)}}]),t}();t.FlexibleUrl=m,t.flexUrl=function(t){return new m(t)}}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -14,3 +14,3 @@ import { type FlexibleUrl } from './flex-url.js'; | ||
toString(): string; | ||
static fromString(fragment: string): QueryParameter | null; | ||
static fromString(fragment: string): undefined | QueryParameter; | ||
} | ||
@@ -17,0 +17,0 @@ export declare class QueryParameterChecker { |
{ | ||
"name": "flex-url", | ||
"description": "Zero-dependency utility for parsing and modifying URL params", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "source": "src/index.ts", |
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
86470
3.72%211
0.96%