Parameters JS 🔑
Simply manage url parameters.
Install
npm install parameters-js
Usage
var Parameters = ; var parameters = ; parameterspost = 2;parametersstring;// => "post=2" parametersdate = '10/12/1997';parametersstring;// => "post=2&date=10%2F12%2F1997" parametersauthors = name: 'Marie' country: 'England' name: 'Marc' country: 'France';parametersstring;// => "post=2&date=10%2F12%2F1997&authors[][name]=Marie&authors[][country]=England&authors[][name]=Marc&authors[][country]=France" var otherParameters = ;otherParametersstring = "post=2&date=10%2F12%2F1997&authors[][name]=Marie&authors[][country]=England&authors[][name]=Marc&authors[][country]=France";otherParameters;// => Parameters {// post: '2',// date: '10/12/1997',// authors: [// {name: 'Marie', country: 'England'},// {name: 'Marc', country: 'France'}// ]// }
Parameters
Kind: global class
- Parameters
- new Parameters(...parameters)
- .keys :
Array.<string>
- .flattened :
Array.<FlatParameter>
- .string :
string
- .inputs :
FragmentDocument
|NodeList
|Array
- .formData :
FormData
- .form :
HTMLFormElement
|Element
- .json :
string
- .clone :
Parameters
- .empty :
boolean
- .any :
boolean
- .toString() ⇒
string
- .set(...parameters) ⇒
Parameters
- .unset(...keys) ⇒
Parameters
- .index(key, [callback]) ⇒
number
- .have(key, [callback]) ⇒
boolean
- .each(callback) ⇒
Parameters
- .map(callback) ⇒
Parameters
- .reset() ⇒
Parameters
- .clear() ⇒
Parameters
new Parameters(...parameters)
Create a Parameters object.
Param | Type | Description |
---|---|---|
...parameters | Object |
Same value as set's parameters. |
Array.<string>
parameters.keys : The parameters keys.
Kind: instance property of Parameters
Read only: true
Array.<FlatParameter>
parameters.flattened : A flat array corresponding to the parameters. When set, the given flattened parameters array will be parsed to replace the current parameters.
Kind: instance property of Parameters
string
parameters.string : A string corresponding to the parameters, ready to be used in a url. When set, the given string will be parsed to replace the current parameters.
Kind: instance property of Parameters
FragmentDocument
| NodeList
| Array
parameters.inputs : A set of inputs corresponding the parameters. When set, the given inputs will be parsed to replace the current parameters.
Kind: instance property of Parameters
FormData
parameters.formData : A FormData corresponding to the parameters.
Kind: instance property of Parameters
Read only: true
HTMLFormElement
| Element
parameters.form : A Form corresponding to the parameters. When set, the given form inputs be parsed to replace the current parameters.
Kind: instance property of Parameters
string
parameters.json : A json string corresponding to the parameters. When set, the given json string will be parsed to replace the current parameters.
Kind: instance property of Parameters
Parameters
parameters.clone : A clone of the current parameters.
Kind: instance property of Parameters
Read only: true
boolean
parameters.empty : true
if no value different from null
can be found in the parameters, false
in the other case.
Kind: instance property of Parameters
Read only: true
boolean
parameters.any : Opposite of empty.
Kind: instance property of Parameters
Read only: true
string
parameters.toString() ⇒ Kind: instance method of Parameters
Returns: string
- Value of string
Parameters
parameters.set(...parameters) ⇒ Set parameters.
Kind: instance method of Parameters
Returns: Parameters
- Itself.
Param | Type | Description |
---|---|---|
...parameters | string | Object |
The parameters to set. If string given the assumed value will be null . |
Parameters
parameters.unset(...keys) ⇒ Unset parameters.
Kind: instance method of Parameters
Returns: Parameters
- Itself.
Param | Type | Description |
---|---|---|
...keys | Object |
The parameter keys to unset. |
number
parameters.index(key, [callback]) ⇒ Looks for the index of the given key and call callback if it was found.
Kind: instance method of Parameters
Returns: number
- The index of the given key if it exists, null in the other case.
Param | Type | Description |
---|---|---|
key | string |
The parameter key whose index your looking for |
[callback] | indexCallback |
The function to call if an index has been found for this key. |
boolean
parameters.have(key, [callback]) ⇒ Checks that the given key exists and call a callback if it exists.
Kind: instance method of Parameters
Returns: boolean
- true
if the key exists, false in the other case.
Param | Type | Description |
---|---|---|
key | string |
The parameter key you want to check the existence. |
[callback] | haveCallback |
The function to call if the key exists. |
Parameters
parameters.each(callback) ⇒ Iterates through parameters.
Kind: instance method of Parameters
Returns: Parameters
- Itself.
Param | Type | Description |
---|---|---|
callback | eachCallback |
The function to call for each parameter. |
Parameters
parameters.map(callback) ⇒ Iterates through parameters and replaces values.
Kind: instance method of Parameters
Returns: Parameters
- Itself.
Param | Type | Description |
---|---|---|
callback | mapCallback |
The function to call for each parameter. |
Parameters
parameters.reset() ⇒ Set all parameter values to null
.
Kind: instance method of Parameters
Returns: Parameters
- Itself
Parameters
parameters.clear() ⇒ Removes all the parameters.
Kind: instance method of Parameters
Returns: Parameters
- Itself
Object
FlatParameter : Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
key | string |
The flattened key of the parameter. |
value | string | number | boolean |
The value of the parameter |
function
indexCallback : Kind: global typedef
Param | Type | Description |
---|---|---|
index | number |
The index of the key. |
function
haveCallback :
boolean
eachCallback ⇒ Kind: global typedef
Returns: boolean
- If strictly equal to false
, will stop iterating.
Param | Type | Description |
---|---|---|
key | string |
The current key. |
value | * |
The current value. |
*
mapCallback ⇒ Kind: global typedef
Returns: *
- The value that will replace the current value.
Param | Type | Description |
---|---|---|
key | string |
The current key. |
value | * |
The current value. |
Classes
Typedefs
- FlatParameter :
Object
- indexCallback :
function
- haveCallback :
function
- eachCallback ⇒
boolean
- mapCallback ⇒
*