0.0.17 • Published 9 months ago

url-validation-query v0.0.17

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

URL Validation Query URL Validation Query is a utility library providing a range of functions for managing query strings in web applications. It offers features for validating, decoding, and parsing query string parameters, as well as inspecting the current environment and extracting the search query from the URL.

Installation You can install the package using npm or yarn:

npm install url-validation-query

or

yarn add url-validation-query
pnpm install url-validation-query

Usage Import the desired functions from the package:

import { validateParams, toQueryString, parseBoolean, isClient, getSearchQuery } from 'url-validation-query';

Functions 1. validateParams Validates query string parameters by removing any keys with falsy values.

import { validateParams } from 'url-validation-query';

const validParams = validateParams({ foo: 'bar', abc: '', def: null });
// { foo: 'bar' }
  1. toQueryString Decodes query string values by removing any keys with falsy values and decoding the resulting query string.

    import { toQueryString } from 'url-validation-query';
    
    const decodedQueryString = toQueryString({ foo: 'bar', abc: 'xyz' });
    // 'foo=bar&abc=xyz'
  2. parseBoolean Parses boolean values from query strings. It returns true for any non-falsy string value, and false for falsy string values (case-insensitive "f", "false", "n", "no", and "0").

    import { parseBoolean } from 'url-validation-query';
    
    const isTrue = parseBoolean('true'); // true
    const isFalse = parseBoolean('false'); // false
  3. isClient Checks if the current environment is a client-side environment (browser).

    import { isClient } from 'url-validation-query';
    
    if (isClient()) {
      // Client-side code
    } else {
      // Server-side code
    }
  4. getSearchQuery Retrieves the search query from the current URL and parses it using the query-string library. It accepts options for configuring the parsing behavior.

    import { getSearchQuery } from 'url-validation-query';

const URL = "?foo=bar&abc=xyz&isSort=true&categoryId=1,2,3" // or window.location.search const searchQuery = getSearchQuery({ searchParams: search || URL },{ parseNumbers: true , parseBooleans: true , arrayFormat:"comma" }); // {foo: "bar", abc:"xyz", isSort:true, categoryId: 1,2,3}

**Support**
If you encounter any issues or have questions, please feel free to reach out to us at garmabi.mohammad73@gmail.com.
0.0.17

9 months ago

0.0.16

9 months ago

0.0.15

9 months ago

0.0.14

9 months ago

0.0.13

9 months ago

0.0.12

9 months ago

0.0.11

9 months ago

0.0.10

9 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago