1.0.9 • Published 5 years ago

querystringme v1.0.9

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

querystringme

Library to process querystring parameters

  1. Install
npm install querystringme
  1. Usage
var querquerystringmeyme = require('querystringme');

// You can load inital parameters with load()
querystringme.load({
    localStorage: true
});

querystringme.getParameters();
querystringme.getParameter('foo', { force: true });
querystringme.updateParameters({ foo: 'bar', other: 'boo' }, { localStorage: true });
  1. Development
npm run dev

This watches files and compiles them

  1. Run tests
npm run dev
npm start // or node server.js
npm test

npm run dev should be running to watch and recompile files.

  1. Options

All methods receive at least one optional object that can have the following options:

  • force: boolean. When true parses URL every time instead of using stored values. Default: false.
  • updateUrl: boolean. When true updates browser's URL after each parameter change. Default: true.
  • localStorage: boolean. When true uses localStorage to store parameters and to restore them when the page is loaded. URL parameters overwrite stored values. Default: false.
  • defaultValues: object. Key-value object to specify default values. Those values are overwritten by browser's URL. If these values are not present in URL they are added. Default: {}.
    • default: default value.
    • validator: function to validate value. Default value is assigned when false is returned.
querystringme.load({ 
    defaultValues: {
        second: { default: '1', validator: (v) => parseInt(v) !== 0 },
        third: { default: '2', validator: (v) => v === null },
        fourth: { default: '4', validator: (v) => v !== null },
    } 
});
  1. List of methods
  • load(options): overwrites default options. Process URL and localStorage parameters and updates the browser URL. The parameter options is optional.
  • getParameters(options): Return all the processed parameters after processing browser URL and localStorage. Browser's URL parameters overwrite localStorage ones. The parameter options is optional.
  • getParameter(key, options): Returns the parameter with name key. The parameter options is optional.
  • updateParameters(values, options): Receives an object with the parameters to update and sets those values. It updates the browser's URL and localStorage when enabled. The parameter options is optional.
1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 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