logo

URL

This is a collection of functions for working with URLs.

Append search params

The appendSearchParamsToURL function appends the search params to a URL.

import { appendSearchParamsToURL } from '@aracna/core';

// will log "https://dummyjson.com/products?a=0"
console.log(
  appendSearchParamsToURL('https://dummyjson.com/products', '?a=0')
);

Remove search params

The removeSearchParamsFromURL functions removes the search params from an URL.

import { removeSearchParamsFromURL } from '@aracna/core';

// will log "https://dummyjson.com/products"
console.log(
  removeSearchParamsFromURL('https://dummyjson.com/products?a=0')
);

Concatenate URL pathnames

The concatURL function concatenates a URL with pathnames.

import { concatURL } from '@aracna/core';

// will log "https://dummyjson.com/products"
console.log(concatURL('https://dummyjson.com/', 'products'));

Deserialize URL search params

The deserializeURLSearchParams function deserializes an array, string, plain object or URLSearchParams to an array, string or plain object.

import { deserializeURLSearchParams } from '@aracna/core';

// will log "a=0&b=1"
console.log(
  deserializeURLSearchParams(
    [
      ['a', '0'],
      ['b', '1']
    ],
    'string'
  )
);

// will log { a: "0", b: "1" }
console.log(deserializeURLSearchParams('?a=0&b=1'));

// will log [["a", "0"], ["b", "1"]]
console.log(deserializeURLSearchParams({ a: '0', b: '1' }, 'array'));

Serialize URL search params

The serializeURLSearchParams function serializes an array, string or plain object to URLSearchParams.

import { serializeURLSearchParams } from '@aracna/core';

// will log URLSearchParams
console.log(
  serializeURLSearchParams([
    ['a', '0'],
    ['b', '1']
  ])
);

// will log URLSearchParams
console.log(serializeURLSearchParams('?a=0&b=1'));

// will log URLSearchParams
console.log(serializeURLSearchParams({ a: '0', b: '1' }));

Check if an unknown value is an URL

The isURL function checks if an unknown value is an URL.

import { isURL } from '@aracna/core';

// will log true
console.log(isURL('https://aracna.dariosechi.it'));