1.3.0 • Published 2 years ago

@gjax/uri v1.3.0

Weekly downloads
22
License
ISC
Repository
github
Last release
2 years ago

NpmVersion npm Build Status Coverage Status NodeVersion npm type definitions

Convenient URI API

Installation

Using npm:

npm install @gjax/uri

API

See API Documentation for full list of methods and modules.

Uri - high-level API

Provides methods for safe URL manipulation.

Example:

const { Uri } = require('@gjax/uri');

const code = 'john/doe';
const url = Uri.appendSegments('/my/sample/', 'collection', code); // '/my/sample/collection/john%2Fdoe'  

uri - low-level API

Provides methods which are used by Uri implematation but can also be used directly. (like: decompising/recomposing components, encoding single URI parts, etc.)

Example:

const { uri } = require('@gjax/uri');
const res = uri.encodeQuery('foo#bar'); // 'foo%23bar'

URI builder tags

ES6 template literal tags & utils used for building URL strings with correct encoding.

Example:

const { uriBuilder } = require('@gjax/uri');
const p1 = 'a/b?c', p2 = 'a#b', p3 = 'a b';  
const url = uriBuilder`/foo/${p1}/bar/?x=${p2}#/baz/${p3}`; // '/foo/a%2Fb%3Fc/bar/?x=a%23b#/baz/a%20b'

Using with webpack and babel

This module is written using latest ES features (supported in node>=8.6.0) and also requires native node module querystring.

If this module is going to be used in older node or in browser it needs to be compiled (e.g. using babel) and a polyfill for querystring needs to be provided.

Sample configuration for webpack

Install dependencies:

npm i -D babel-core babel-loader babel-preset-es2015 babel-plugin-transform-object-rest-spread

Configure querystring polyfill in webpack config: (https://webpack.js.org/configuration/node/)

node: {
  querystring: true
}

Configure babel compilation:

module: {
  rules: [
    {
      test: /node_modules[\/\\]@gjax.*\.js$/,
      loader: 'babel-loader',
      query: {
        presets: ['es2015'],
        plugins: [require('babel-plugin-transform-object-rest-spread')]
      }
    }
    ...
1.3.0

2 years ago

1.2.9

4 years ago

1.2.8

4 years ago

1.2.7

5 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago