You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

flex-url

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flex-url - npm Package Compare versions

Comparing version

to
1.5.0

6

CHANGELOG.md

@@ -10,2 +10,8 @@ # Changelog

## [1.5.0] - 2022-11-23
### Changed
- `filters.all()` & `filters.get(key)` methods now returns an keyed by filter key (`filter[name]` changed to `name`) and possibly returning an array of objects including modifiers (`{'filter[name][modifier1][modifier2]': ['value1', 'value2'] ...}` to `name: {modifiers: ['modifier1', 'modifier2'], value: ['value1', 'value2']}`)
## [1.4.0] - 2022-11-23

@@ -12,0 +18,0 @@

11

dist/filter-params.d.ts
import { type FlexibleUrl } from './flex-url.js';
import { QueryParameterManipulator, type QueryParametersObject, type QueryParameterModifiers } from './query-params.js';
import { QueryParameterManipulator, type QueryParameterModifiers } from './query-params.js';
export type FilterParameterObjectValue = {
modifiers: string[];
value: string[];
};
export type FilterParametersObject = Record<string, FilterParameterObjectValue | FilterParameterObjectValue[]>;
export type FilterParameterConditional = 'and' | 'or' | undefined;

@@ -25,3 +30,3 @@ export declare class FilterParameterChecker {

*/
get(filterKey?: string, modifiers?: QueryParameterModifiers): QueryParametersObject;
get(filterKey?: string, modifiers?: QueryParameterModifiers): FilterParametersObject;
/**

@@ -32,3 +37,3 @@ * Get all filter parameters as an object.

*/
all(): QueryParametersObject;
all(): FilterParametersObject;
}

@@ -35,0 +40,0 @@ export declare class 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 r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function r(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}function i(t,e){var r=[],i=-1;for(i=0;i<t.length;i++)("function"==typeof e?e(t[i]):e)&&r.push(i);return r}function n(t,e,r){var i=-1;for(i=0;i<t.length;i++)e.includes(i)&&(t[i]="function"==typeof r?r(t[i]):r)}var o=/*#__PURE__*/function(){function t(t,e,r){void 0===r&&(r=[]),this.name=void 0,this.value=void 0,this.modifiers=void 0,this.name=t,this.value=e,this.modifiers=r}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 this.value=t,this},e.setModifiers=function(t){return this.modifiers=t,this},e.toString=function(){return t.queryParamKey(encodeURIComponent(this.name),this.modifiers.map(function(t){return encodeURIComponent(t)}))+"="+encodeURIComponent(this.value)},t.fromString=function(e){var r=decodeURIComponent(e).split("="),i=r[0],n=r[1],o=i,s=[];if(i.includes("[")){var a=i.split(/\[|\|/);o=a.shift(),s=a.map(function(t){return t.replace("]","")})}if(o)return new t(o,n,s)},r(t,[{key:"queryParamKey",get:function(){return t.queryParamKey(this.name,this.modifiers)}}]),t}(),s=/*#__PURE__*/function(){function t(t){this.flexUrl=void 0,this.flexUrl=t,this.flexUrl=t}t.find=function(t,e,r,i,n){return void 0===n&&(n=!0),t.params.findIndex(function(t){return t.queryParamKey===o.queryParamKey(e,i)&&(n?!r||t.value.toLocaleLowerCase()===r.toLocaleLowerCase():!r||t.value.includes(r))})};var e=t.prototype;return e.includes=function(t,e,r){return this.has(t,e,r,!1)},e.has=function(e,r,i,n){return void 0===n&&(n=!0),-1!==t.find(this.flexUrl,e,r,i,n)},e.all=function(){for(var t={},e=0;e<this.flexUrl.params.length;e++){var r=this.flexUrl.params[e];t[r.queryParamKey]=r.value.split(",")}return t},e.get=function(e,r){var i=t.find(this.flexUrl,e,void 0,r);if(-1!==i){var n=this.flexUrl.params[i];return{key:n.queryParamKey,value:n.value.split(",")}}},t}(),a=/*#__PURE__*/function(){function t(t,e,r,n,s){void 0===n&&(n=[]),void 0===s&&(s=[]),this.flexUrl=void 0,this.name=void 0,this.value=void 0,this.modifiers=void 0,this.indexes=void 0,this.flexUrl=t,this.name=e,this.value=r,this.modifiers=n,this.indexes=s,0===s.length&&(this.indexes=i(t.params,function(t){return t.queryParamKey===o.queryParamKey(e,n)&&(!r||t.value===r)}))}t.fromIndexes=function(e,r,i,n){return void 0===n&&(n=[]),new t(e,r,void 0,n,i)};var e=t.prototype;return e.set=function(t,e){return void 0===e&&(e=[]),n(this.flexUrl.params,this.indexes,new o(this.name,t,e)),this},e.add=function(e,r){void 0===r&&(r=[]);var i=s.find(this.flexUrl,this.name,e,r);return-1!==i?t.fromIndexes(this.flexUrl,this.name,[i]):(this.flexUrl.params.push(new o(this.name,e,r)),new t(this.flexUrl,this.name,e,r))},e.replace=function(t){var e;if(null==(e=this.indexes)||!e.length)throw new Error("Query parameter must be provided to replace to the right parameter.");return n(this.flexUrl.params,this.indexes,function(e){return e.setValue("function"==typeof t?t(e.value):t)}),this},e.append=function(t){return this.replace(function(e){return""+e+t})},e.toggle=function(t,e){void 0===e&&(e=[]);var r=s.find(this.flexUrl,this.name,t,e);return-1!==r?(this.remove(t,e,r),this):this.add(t,e)},e.remove=function(t,e,r){var i=this;return void 0===e&&(e=[]),this.flexUrl.params=this.flexUrl.params.filter(function(n,s){return r?r===s:n.queryParamKey!==o.queryParamKey(i.name,e)||!!t&&!n.value.includes(t)}),this.flexUrl},e.withModifiers=function(t){return n(this.flexUrl.params,this.indexes,function(e){return e.setModifiers(t)}),this},r(t,[{key:"url",get:function(){return this.flexUrl}},{key:"exists",get:function(){var t=this;return this.indexes.length>0&&this.indexes.every(function(e,r){var i;return Boolean(null==(i=t.flexUrl.params)?void 0:i[r])})}}]),t}(),u=/*#__PURE__*/function(){function t(t){this.flexUrl=void 0,this.flexUrl=t}t.find=function(t,e,r,n,s){void 0===n&&(n=[]),void 0===s&&(s=!1);var a=r.join(",").toLocaleLowerCase().split(",");return i(t.params,function(t){if(!t.value.includes(","))return!1;if(t.queryParamKey===o.queryParamKey("filter",[e].concat(n))){var r=t.value.toLocaleLowerCase().split(",");return s?r.every(function(t){return a.includes(t)}):r.some(function(t){return a.includes(t)})}return!1})};var e=t.prototype;return e.includes=function(t,e,r){return void 0===r&&(r=[]),this.has(t,e,r,!1)},e.has=function(e,r,i,n){return void 0===i&&(i=[]),void 0===n&&(n=!0),Array.isArray(r)?t.find(this.flexUrl,e,r,i,n).length>0:this.flexUrl.queryParams.has("filter",r,[e].concat(i),n)},e.get=function(t,e){void 0===e&&(e=[]);for(var r={},i=this.flexUrl.params.filter(function(r){return"filter"===r.name&&(!t||r.modifiers.includes(t))&&(!(e.length>0)||1===r.modifiers.filter(function(t){return e.includes(t)}).length)}),n=0;n<i.length;n++){var o=i[n];r[o.queryParamKey]=o.value.split(",")}return r},e.all=function(){return this.get()},t}(),l=/*#__PURE__*/function(){function t(t,e){this.manipulator=void 0,this.filterKey=void 0,this.conditional="and",this.manipulator=t,this.filterKey=e}t.fromUrl=function(e,r){return new t(e.queryParam("filter"),r)};var e=t.prototype;return e.add=function(e,r){return void 0===r&&(r=[]),"or"===this.conditional&&this.manipulator.url.filters.has(this.filterKey)&&!this.manipulator.url.filters.includes(this.filterKey,[e],r)?this.append(","+e):new t(this.manipulator.add(e,[this.filterKey].concat(r)),this.filterKey)},e.set=function(e,r){return void 0===r&&(r=[]),new t(this.manipulator.set(e,[this.filterKey].concat(r)),this.filterKey)},e.replace=function(e){return new t(this.manipulator.replace(e),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,r){if(void 0===r&&(r=[]),"or"===this.conditional){var i=u.find(this.manipulator.url,this.filterKey,[e],r,!0);return i.length>0?this.set(this.manipulator.url.params[i[0]].value.split(",").filter(function(t){return t!==e}).join(",")):this.manipulator.url.filters.has(this.filterKey)?(this.manipulator.exists?this:new t(a.fromIndexes(this.manipulator.url,"filter",i,[this.filterKey].concat(r)),this.filterKey)).replace(function(t){var r=t?t.split(","):[];return r.includes(e)?r.filter(function(t){return t.toLocaleLowerCase()!==e.toLocaleLowerCase()}).join(","):(r.push(e),r.join(","))}):this.add(e)}return new t(this.manipulator.toggle(e,[this.filterKey].concat(r)),this.filterKey)},r(t,[{key:"or",get:function(){return this.conditional="or",this}},{key:"and",get:function(){return this.conditional="and",this}}]),t}(),f=/*#__PURE__*/function(){function t(t){this.flexUrl=void 0,this.flexUrl=t}var e=t.prototype;return e.has=function(t,e){return void 0===e&&(e="asc"),this.flexUrl.queryParams.has("sort","asc"===e?t:"-"+t)},e.byAsc=function(t){return this.has(t)},e.byDesc=function(t){return this.has(t,"desc")},e.all=function(){for(var t,e,r={},i=null!=(t=null==(e=this.flexUrl.queryParams.get("sort"))?void 0:e.value)?t:[],n=0;n<i.length;n++){var o=i[n],s="asc";o.startsWith("-")&&(o=o.slice(1),s="desc"),r[o]=s}return r},t}(),h=/*#__PURE__*/function(){function t(t){this.sortParameter=void 0,this.direction="asc",this.sortParameter=t}return t.fromUrl=function(e){return new t(e.queryParam("sort"))},t.prototype.toggle=function(e,r){var i=e,n="-"+e;return"desc"===(null!=r?r:this.direction)&&(i="-"+i,n=e),new t(this.sortParameter.exists?this.sortParameter.replace(function(t){var e=t.split(","),r=e.indexOf(n);return-1!==r&&delete e[r],e.push(i),e.join(",")}):this.sortParameter.add(i))},r(t,[{key:"asc",get:function(){return this.direction="asc",this}},{key:"desc",get:function(){return this.direction="desc",this}}]),t}(),c=/*#__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 r=e.search.replace("?","").split("&"),i=0;i<r.length;i++){var n=o.fromString(r[i]);n&&this.params.push(n)}}var e=t.prototype;return e.queryParam=function(t,e){return new a(this,t,e)},e.filter=function(t){return l.fromUrl(this,t)},e.sort=function(){return h.fromUrl(this)},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},r(t,[{key:"queryParams",get:function(){return new s(this)}},{key:"filters",get:function(){return new u(this)}},{key:"sorts",get:function(){return new f(this)}}]),t}();t.FlexibleUrl=c,t.flexUrl=function(t){return new c(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 r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function r(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}function i(t,e){var r=[],i=-1;for(i=0;i<t.length;i++)("function"==typeof e?e(t[i]):e)&&r.push(i);return r}function n(t,e,r){var i=-1;for(i=0;i<t.length;i++)e.includes(i)&&(t[i]="function"==typeof r?r(t[i]):r)}var o=/*#__PURE__*/function(){function t(t,e,r){void 0===r&&(r=[]),this.name=void 0,this.value=void 0,this.modifiers=void 0,this.name=t,this.value=e,this.modifiers=r}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 this.value=t,this},e.setModifiers=function(t){return this.modifiers=t,this},e.toString=function(){return t.queryParamKey(encodeURIComponent(this.name),this.modifiers.map(function(t){return encodeURIComponent(t)}))+"="+encodeURIComponent(this.value)},t.fromString=function(e){var r=decodeURIComponent(e).split("="),i=r[0],n=r[1],o=i,s=[];if(i.includes("[")){var a=i.split(/\[|\|/);o=a.shift(),s=a.map(function(t){return t.replace("]","")})}if(o)return new t(o,n,s)},r(t,[{key:"queryParamKey",get:function(){return t.queryParamKey(this.name,this.modifiers)}}]),t}(),s=/*#__PURE__*/function(){function t(t){this.flexUrl=void 0,this.flexUrl=t,this.flexUrl=t}t.find=function(t,e,r,i,n){return void 0===n&&(n=!0),t.params.findIndex(function(t){return t.queryParamKey===o.queryParamKey(e,i)&&(n?!r||t.value.toLocaleLowerCase()===r.toLocaleLowerCase():!r||t.value.includes(r))})};var e=t.prototype;return e.includes=function(t,e,r){return this.has(t,e,r,!1)},e.has=function(e,r,i,n){return void 0===n&&(n=!0),-1!==t.find(this.flexUrl,e,r,i,n)},e.all=function(){for(var t={},e=0;e<this.flexUrl.params.length;e++){var r=this.flexUrl.params[e];t[r.queryParamKey]=r.value.split(",")}return t},e.get=function(e,r){var i=t.find(this.flexUrl,e,void 0,r);if(-1!==i){var n=this.flexUrl.params[i];return{key:n.queryParamKey,value:n.value.split(",")}}},t}(),a=/*#__PURE__*/function(){function t(t,e,r,n,s){void 0===n&&(n=[]),void 0===s&&(s=[]),this.flexUrl=void 0,this.name=void 0,this.value=void 0,this.modifiers=void 0,this.indexes=void 0,this.flexUrl=t,this.name=e,this.value=r,this.modifiers=n,this.indexes=s,0===s.length&&(this.indexes=i(t.params,function(t){return t.queryParamKey===o.queryParamKey(e,n)&&(!r||t.value===r)}))}t.fromIndexes=function(e,r,i,n){return void 0===n&&(n=[]),new t(e,r,void 0,n,i)};var e=t.prototype;return e.set=function(t,e){return void 0===e&&(e=[]),n(this.flexUrl.params,this.indexes,new o(this.name,t,e)),this},e.add=function(e,r){void 0===r&&(r=[]);var i=s.find(this.flexUrl,this.name,e,r);return-1!==i?t.fromIndexes(this.flexUrl,this.name,[i]):(this.flexUrl.params.push(new o(this.name,e,r)),new t(this.flexUrl,this.name,e,r))},e.replace=function(t){var e;if(null==(e=this.indexes)||!e.length)throw new Error("Query parameter must be provided to replace to the right parameter.");return n(this.flexUrl.params,this.indexes,function(e){return e.setValue("function"==typeof t?t(e.value):t)}),this},e.append=function(t){return this.replace(function(e){return""+e+t})},e.toggle=function(t,e){void 0===e&&(e=[]);var r=s.find(this.flexUrl,this.name,t,e);return-1!==r?(this.remove(t,e,r),this):this.add(t,e)},e.remove=function(t,e,r){var i=this;return void 0===e&&(e=[]),this.flexUrl.params=this.flexUrl.params.filter(function(n,s){return r?r===s:n.queryParamKey!==o.queryParamKey(i.name,e)||!!t&&!n.value.includes(t)}),this.flexUrl},e.withModifiers=function(t){return n(this.flexUrl.params,this.indexes,function(e){return e.setModifiers(t)}),this},r(t,[{key:"url",get:function(){return this.flexUrl}},{key:"exists",get:function(){var t=this;return this.indexes.length>0&&this.indexes.every(function(e,r){var i;return Boolean(null==(i=t.flexUrl.params)?void 0:i[r])})}}]),t}(),u=/*#__PURE__*/function(){function t(t){this.flexUrl=void 0,this.flexUrl=t}t.find=function(t,e,r,n,s){void 0===n&&(n=[]),void 0===s&&(s=!1);var a=r.join(",").toLocaleLowerCase().split(",");return i(t.params,function(t){if(!t.value.includes(","))return!1;if(t.queryParamKey===o.queryParamKey("filter",[e].concat(n))){var r=t.value.toLocaleLowerCase().split(",");return s?r.every(function(t){return a.includes(t)}):r.some(function(t){return a.includes(t)})}return!1})};var e=t.prototype;return e.includes=function(t,e,r){return void 0===r&&(r=[]),this.has(t,e,r,!1)},e.has=function(e,r,i,n){return void 0===i&&(i=[]),void 0===n&&(n=!0),Array.isArray(r)?t.find(this.flexUrl,e,r,i,n).length>0:this.flexUrl.queryParams.has("filter",r,[e].concat(i),n)},e.get=function(t,e){void 0===e&&(e=[]);for(var r={},i=this.flexUrl.params.filter(function(r){return"filter"===r.name&&(!t||r.modifiers.includes(t))&&(!(e.length>0)||1===r.modifiers.filter(function(t){return e.includes(t)}).length)}),n=0;n<i.length;n++){var o=i[n],s=o.modifiers[0],a={modifiers:o.modifiers.slice(1),value:o.value.split(",")};s in r&&(a=[].concat(r[s],a)),r[s]=a}return r},e.all=function(){return this.get()},t}(),l=/*#__PURE__*/function(){function t(t,e){this.manipulator=void 0,this.filterKey=void 0,this.conditional="and",this.manipulator=t,this.filterKey=e}t.fromUrl=function(e,r){return new t(e.queryParam("filter"),r)};var e=t.prototype;return e.add=function(e,r){return void 0===r&&(r=[]),"or"===this.conditional&&this.manipulator.url.filters.has(this.filterKey)&&!this.manipulator.url.filters.includes(this.filterKey,[e],r)?this.append(","+e):new t(this.manipulator.add(e,[this.filterKey].concat(r)),this.filterKey)},e.set=function(e,r){return void 0===r&&(r=[]),new t(this.manipulator.set(e,[this.filterKey].concat(r)),this.filterKey)},e.replace=function(e){return new t(this.manipulator.replace(e),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,r){if(void 0===r&&(r=[]),"or"===this.conditional){var i=u.find(this.manipulator.url,this.filterKey,[e],r,!0);return i.length>0?this.set(this.manipulator.url.params[i[0]].value.split(",").filter(function(t){return t!==e}).join(",")):this.manipulator.url.filters.has(this.filterKey)?(this.manipulator.exists?this:new t(a.fromIndexes(this.manipulator.url,"filter",i,[this.filterKey].concat(r)),this.filterKey)).replace(function(t){var r=t?t.split(","):[];return r.includes(e)?r.filter(function(t){return t.toLocaleLowerCase()!==e.toLocaleLowerCase()}).join(","):(r.push(e),r.join(","))}):this.add(e)}return new t(this.manipulator.toggle(e,[this.filterKey].concat(r)),this.filterKey)},r(t,[{key:"or",get:function(){return this.conditional="or",this}},{key:"and",get:function(){return this.conditional="and",this}}]),t}(),f=/*#__PURE__*/function(){function t(t){this.flexUrl=void 0,this.flexUrl=t}var e=t.prototype;return e.has=function(t,e){return void 0===e&&(e="asc"),this.flexUrl.queryParams.has("sort","asc"===e?t:"-"+t)},e.byAsc=function(t){return this.has(t)},e.byDesc=function(t){return this.has(t,"desc")},e.all=function(){for(var t,e,r={},i=null!=(t=null==(e=this.flexUrl.queryParams.get("sort"))?void 0:e.value)?t:[],n=0;n<i.length;n++){var o=i[n],s="asc";o.startsWith("-")&&(o=o.slice(1),s="desc"),r[o]=s}return r},t}(),h=/*#__PURE__*/function(){function t(t){this.sortParameter=void 0,this.direction="asc",this.sortParameter=t}return t.fromUrl=function(e){return new t(e.queryParam("sort"))},t.prototype.toggle=function(e,r){var i=e,n="-"+e;return"desc"===(null!=r?r:this.direction)&&(i="-"+i,n=e),new t(this.sortParameter.exists?this.sortParameter.replace(function(t){var e=t.split(","),r=e.indexOf(n);return-1!==r&&delete e[r],e.push(i),e.join(",")}):this.sortParameter.add(i))},r(t,[{key:"asc",get:function(){return this.direction="asc",this}},{key:"desc",get:function(){return this.direction="desc",this}}]),t}(),c=/*#__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 r=e.search.replace("?","").split("&"),i=0;i<r.length;i++){var n=o.fromString(r[i]);n&&this.params.push(n)}}var e=t.prototype;return e.queryParam=function(t,e){return new a(this,t,e)},e.filter=function(t){return l.fromUrl(this,t)},e.sort=function(){return h.fromUrl(this)},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},r(t,[{key:"queryParams",get:function(){return new s(this)}},{key:"filters",get:function(){return new u(this)}},{key:"sorts",get:function(){return new f(this)}}]),t}();t.FlexibleUrl=c,t.flexUrl=function(t){return new c(t)}});
//# sourceMappingURL=index.umd.js.map
{
"name": "flex-url",
"version": "1.4.0",
"version": "1.5.0",
"description": "Zero-dependency utility for parsing and modifying URL params",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/open-southeners/flex-url#readme",

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