Skip to content

Commit

Permalink
Updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
knowledgecode committed Jan 3, 2023
1 parent be9607b commit 1f34dfe
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,51 @@

## Installation

Node.js:
via npm:

```shell
npm install jquery-param --save
```

the browser:

```html
<script src="/path/to/jquery-param.min.js"></script>
npm i jquery-param
```

## Usage

CommonJS:

```javascript
const param = require('jquery-param');
import param from 'jquery-param';

const obj = { key1: { value1: [10, 20, 30] }, key2: '?a=b&c=d' };
const str = param(obj);
// => "key1[value1][]=10&key1[value1][]=20&key1[value1][]=30&key2=?a=b&c=d"
```

TypeScript:
CommonJS:

```javascript
import param from 'jquery-param';
const param = require('jquery-param');

const obj = { key1: { value1: [10, 20, 30] }, key2: '?a=b&c=d' };
const str = param(obj);
// => "key1[value1][]=10&key1[value1][]=20&key1[value1][]=30&key2=?a=b&c=d"
```

*You will need to add `"esModuleInterop": true` to the `"compilerOptions"` field in `tsconfig.json`.*

ES Modules:
ES Modules (Browser):

```html
<script type="module">
import param from './esm/jquery-param.es.js';
import param from '/path/to/jquery-param.js';
const obj = { key1: { value1: [10, 20, 30] }, key2: '?a=b&c=d' };
const str = param(obj);
// => "key1[value1][]=10&key1[value1][]=20&key1[value1][]=30&key2=?a=b&c=d"
</script>
```

Older browser:
Traditional (Browser):

```html
<script src="/path/to/jquery-param.js">
<script>
var obj = { key1: { value1: [10, 20, 30] }, key2: '?a=b&c=d' };
var str = window.param(obj); // global object
var str = window.param(obj);
// => "key1[value1][]=10&key1[value1][]=20&key1[value1][]=30&key2=?a=b&c=d"
</script>
```
Expand Down

0 comments on commit 1f34dfe

Please sign in to comment.