queryencoder.euber.dev Open in urlscan Pro
76.76.21.241  Public Scan

URL: https://queryencoder.euber.dev/
Submission: On July 25 via automatic, source certstream-suspicious — Scanned from CA

Form analysis 0 forms found in the DOM

Text Content

Search
 * Preparing search index...
 * The search index is not available

queryencoder - v1.1.2
Options
All
 * Public
 * Public/Protected
 * All

Inherited
Menu


QUERYENCODER - V1.1.2


QUERYENCODER

An npm module to encode an object into query params of an url


INSTALL

To install queryencoder, run:

$ npm install queryencoder



USAGE


SIMPLE

const { encode } = require('queryencoder');

const object = {
    str: 'string',
    n: 23,
    truthy: true
};

// The result is '?str=string&n=23&truthy=true'
const queryUrl = encode(object);



WITH NESTED OBJECT

const { encode } = require('queryencoder');

const object = {
    str: 'string',
    nested: {
        a: 'ciao'
    }
};

// The result is '?str=string&nested=true&nested.a=ciao'
const queryUrl = encode(object);



WITH SOME OPTIONS

const { encode } = require('queryencoder');

const object = {
    str: 'string',
    shown: undefined,
    nested: {
        a: 'ciao'
    },
    vero: true
};

// The result is 'str=string&nested.a=ciao&vero'
const queryUrl = encode(object, {
    preserveUndefined: true,
    addQuestionMark: false,
    flagNestedParents: false,
    shortBoolean: true
});



WITH SOME DATES

const { encode } = require('queryencoder');

const object = {
    date: new Date('1999-04-23')
};

// The result is 'date=1999-04-23'
const queryUrl = encode(object, {
    dateParser: date => date.toISOString().slice(0, 10)
});



API

The documentation site is: queryencoder documentation

The documentation for development site is: queryencoder dev documentation


ENCODE

The function to encode an object into an url query param string.

Syntax:

const queryString = encode(object, options);

Parameters:

 * object: It is the object describing the parameters that should be encoded. It
   is an object that can be nested ad have values of type: string, number,
   boolean and Date.
 * options: Optional. It is the object containing the options.

Options parameters:

 * addQuestionMark: Optional. A boolean that says if the ? will be added to the
   begin of the result. Default value: true.
 * shortBoolean: Optional. If a value is of boolean type, it will be just
   declared if true while omitted if false. (e.g. &val) Default value: false.
 * flagNestedParents: Optional. A boolean that says if in case there is a nested
   object, a parameter with value true for each path to the parents will be
   added. Default value: true.
 * preserveNull: Optional. A boolean that says if all the null values will be
   kept and parsed as 'null'. Default value: true.
 * preserveUndefined: Optional. A boolean that says if all the undefined values
   will be kept and parsed as 'undefined'. Default value: false.
 * dateParser: Optional. The function used to parse the dates. Default value:
   value => value.toISOString().


DEVELOPMENT

To build the module make sure you have the dev dependencies installed.

The project is written in Typescript, bundled with Webpack and linted with
ESLint.


LINT

In order to lint the code:

$ npm run lint


In order to lint and fix the code:

$ npm run lint:fix


There are also the :source and :test suffix after lint in order to lint only the
source code or the test code.


TRANSPILE

To transpile both the source and the test code:

$ npm run transpile


The source and the test folders will be transpiled in the dist folder. Also the
type declarations will be generated.

To transpile only the source code:

$ npm run transpile:source


The source folder will be transpiled in the dist folder. Also the type
declarations will be generated.


TEST

After having transpiled the code, run:

$ npm test


in order to run the tests with mocha.

If a coverage report is to be generated, run:

$ npm run nyc



BUNDLE

$ npm run bundle


The source folder will be compiled in the bundled folder. It will contain the
bundled index.js and index.d.ts files.

 * Exports

 * InternalOptions
 * QueryParms
 * Options
 * QueryValue
 * encode


LEGEND

 * Property

Generated using TypeDoc