Simply manage url parameters.
npm install parameters-js
var Parameters = require('parameters-js');
var parameters = new Parameters();
parameters.post = 2;
parameters.string;
// => "post=2"
parameters.date = '10/12/1997';
parameters.string;
// => "post=2&date=10%2F12%2F1997"
parameters.authors = [
{name: 'Marie', country: 'England'},
{name: 'Marc', country: 'France'}
];
parameters.string;
// => "post=2&date=10%2F12%2F1997&authors[][name]=Marie&authors[][country]=England&authors[][name]=Marc&authors[][country]=France"
var otherParameters = new Parameters();
otherParameters.string = "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'}
// ]
// }
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
Create a Parameters object.
Param | Type | Description |
---|---|---|
...parameters | Object |
Same value as set's parameters. |
The parameters keys.
Kind: instance property of Parameters
Read only: true
parameters.flattened : Array.<FlatParameter>
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
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
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
A FormData corresponding to the parameters.
Kind: instance property of Parameters
Read only: true
A Form corresponding to the parameters. When set, the given form inputs be parsed to replace the current parameters.
Kind: instance property of Parameters
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.clone : Parameters
A clone of the current parameters.
Kind: instance property of Parameters
Read only: true
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
Opposite of empty.
Kind: instance property of Parameters
Read only: true
Kind: instance method of Parameters
Returns: string
- Value of string
parameters.set(...parameters) ⇒ 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.unset(...keys) ⇒ Parameters
Unset parameters.
Kind: instance method of Parameters
Returns: Parameters
- Itself.
Param | Type | Description |
---|---|---|
...keys | Object |
The parameter keys to unset. |
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. |
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.each(callback) ⇒ Parameters
Iterates through parameters.
Kind: instance method of Parameters
Returns: Parameters
- Itself.
Param | Type | Description |
---|---|---|
callback | eachCallback |
The function to call for each parameter. |
parameters.map(callback) ⇒ Parameters
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.reset() ⇒ Parameters
Set all parameter values to null
.
Kind: instance method of Parameters
Returns: Parameters
- Itself
parameters.clear() ⇒ Parameters
Removes all the parameters.
Kind: instance method of Parameters
Returns: Parameters
- Itself
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
key | string |
The flattened key of the parameter. |
value | string | number | boolean |
The value of the parameter |
Kind: global typedef
Param | Type | Description |
---|---|---|
index | number |
The index of the key. |
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. |
Kind: global typedef
Returns: *
- The value that will replace the current value.
Param | Type | Description |
---|---|---|
key | string |
The current key. |
value | * |
The current value. |
- FlatParameter :
Object
- indexCallback :
function
- haveCallback :
function
- eachCallback ⇒
boolean
- mapCallback ⇒
*