parameters-js v1.0.33
Parameters JS 🔑
Simply manage url parameters.
Install
npm install parameters-js
Usage
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'}
// ]
// }
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. |
parameters.keys : Array.<string>
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
parameters.string : 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
parameters.inputs : FragmentDocument | NodeList | Array
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
parameters.formData : FormData
A FormData corresponding to the parameters.
Kind: instance property of Parameters
Read only: true
parameters.form : HTMLFormElement | Element
A Form corresponding to the parameters. When set, the given form inputs be parsed to replace the current parameters.
Kind: instance property of Parameters
parameters.json : string
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
parameters.empty : boolean
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
parameters.any : boolean
Opposite of empty.
Kind: instance property of Parameters
Read only: true
parameters.toString() ⇒ string
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. |
parameters.index(key, callback) ⇒ number
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. |
parameters.have(key, callback) ⇒ boolean
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
FlatParameter : Object
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
key | string | The flattened key of the parameter. |
value | string | number | boolean | The value of the parameter |
indexCallback : function
Kind: global typedef
Param | Type | Description |
---|---|---|
index | number | The index of the key. |
haveCallback : function
Kind: global typedef
eachCallback ⇒ boolean
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
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago