# url-obj-parse

> Convert objects to a query string

Latest version **1.0.2** (published 2022-04-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install url-obj-parse
pnpm add url-obj-parse
yarn add url-obj-parse
bun add url-obj-parse
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-04-18 |
| First published | 2022-04-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Leonardo Alegre |
| Maintainers | leodreco |

## Links

- npm: https://www.npmjs.com/package/url-obj-parse
- Repository: https://github.com/leodreco/url-obj-parse
- Homepage: https://github.com/leodreco/url-obj-parse#readme
- Issues: https://github.com/leodreco/url-obj-parse/issues
- npm.io page: https://npm.io/package/url-obj-parse

## Recent versions

- 1.0.2 (latest) — 2022-04-18
- 1.0.1 — 2022-04-16
- 1.0.0 — 2022-04-15

## README

# url-obj-parse

> Convert javascript objects to a supported url query string

## Install

```
$ npm install url-obj-parse
```

## Example
> In frontend app
```js
const UrlObjParse = require('url-obj-parse');

const data = {
  filters: {
    name: {
      value: 'john',
      mode: 'contains'
    },
    AND: {
      name: {
        value: 'xina',
        mode: 'endsWith'
      },
    }
  },
  sortField: 'createdAt',
  sortOrder: 'desc'
};

const urlQuery = UrlObjParse(data);
const apiEndpoint = `https://localhost:3000/some-api/users?${urlQuery}`;

console.log(apiEndpoint);
// https://localhost:3000/some-api/users?filters[name][value]=john&filters[name][mode]=contains&filters[AND][name][value]=xina&filters[AND][name][mode]=endsWith&sortField=createdAt&sortOrder=desc

// Just an example...
// const response = await axios.get(apiEndpoint);
```

> Then in back, express for this example
```js
router.get('/users', (req, res) => {
    console.log(req.query);
    return res.json(req.query);
});

// {
//   filters: {
//     name: {
//       value: 'john',
//       mode: 'contains'
//     },
//     AND: {
//       name: {
//         value: 'xina',
//         mode: 'endsWith'
//       },
//     }
//   },
//   sortField: 'createdAt',
//   sortOrder: 'desc'
// }
```

---
_Source: https://npm.io/package/url-obj-parse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
