How to use urijs

Comprehensive urijs code examples:

How to use urijs.js:

99
100
101
102
103
104
105
106
107
### Node.js and NPM ###

Install with `npm install urijs` or add `"urijs"` to the dependencies in your `package.json`.

```javascript
// load URI.js
var URI = require('urijs');
// load an optional module (e.g. URITemplate)
var URITemplate = require('urijs/src/URITemplate');

How to use urijs.min:

92
93
94
95
96
97
98
99
100
101
npm install urijs
```

### Browser ###

I guess you'll manage to use the [build tool](http://medialize.github.io/URI.js/build.html) or follow the [instructions below](#minify) to combine and minify the various files into URI.min.js - and I'm fairly certain you know how to `<script src=".../URI.min.js"></script>` that sucker, too.

### Node.js and NPM ###

Install with `npm install urijs` or add `"urijs"` to the dependencies in your `package.json`.

How to use urijs.parseQuery:

4
5
6
7
8
9
10
11
12
13
const URI = require('urijs');

const validModes = ['utf8', 'utf16', 'utf32'];

const { query } = URI.parse(decodeURIComponent(window.location.href));
const MODE = ((left = URI.parseQuery(query).mode) != null ? left : 'utf8').toLowerCase();

if (!Array.from(validModes).includes(MODE)) {
    // Ensure the mode is an actualy encoding
    alert('Mode must be in #{validModes}');

How to use urijs.parse:

3
4
5
6
7
8
9
10
11
12
const s = require('underscore.string');
const URI = require('urijs');

const validModes = ['utf8', 'utf16', 'utf32'];

const { query } = URI.parse(decodeURIComponent(window.location.href));
const MODE = ((left = URI.parseQuery(query).mode) != null ? left : 'utf8').toLowerCase();

if (!Array.from(validModes).includes(MODE)) {
    // Ensure the mode is an actualy encoding