1.0.33 • Published 6 years ago

parameters-js v1.0.33

Weekly downloads
4
License
MIT
Repository
-
Last release
6 years ago

Parameters JS 🔑

npm version Maintainability

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

new Parameters(...parameters)

Create a Parameters object.

ParamTypeDescription
...parametersObjectSame 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.

ParamTypeDescription
...parametersstring | ObjectThe 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.

ParamTypeDescription
...keysObjectThe 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.

ParamTypeDescription
keystringThe parameter key whose index your looking for
callbackindexCallbackThe 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.

ParamTypeDescription
keystringThe parameter key you want to check the existence.
callbackhaveCallbackThe function to call if the key exists.

parameters.each(callback) ⇒ Parameters

Iterates through parameters.

Kind: instance method of Parameters
Returns: Parameters - Itself.

ParamTypeDescription
callbackeachCallbackThe function to call for each parameter.

parameters.map(callback) ⇒ Parameters

Iterates through parameters and replaces values.

Kind: instance method of Parameters
Returns: Parameters - Itself.

ParamTypeDescription
callbackmapCallbackThe 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

NameTypeDescription
keystringThe flattened key of the parameter.
valuestring | number | booleanThe value of the parameter

indexCallback : function

Kind: global typedef

ParamTypeDescription
indexnumberThe index of the key.

haveCallback : function

Kind: global typedef

eachCallback ⇒ boolean

Kind: global typedef
Returns: boolean - If strictly equal to false, will stop iterating.

ParamTypeDescription
keystringThe current key.
value*The current value.

mapCallback ⇒ *

Kind: global typedef
Returns: * - The value that will replace the current value.

ParamTypeDescription
keystringThe current key.
value*The current value.

Classes

Typedefs

1.0.33

6 years ago

1.0.32

6 years ago

1.0.31

6 years ago

1.0.30

6 years ago

1.0.29

6 years ago

1.0.28

6 years ago

1.0.27

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago