https://github.com/kagawagao/filter-string
Parse and stringify RESTFul filter strting
https://github.com/kagawagao/filter-string
filter parse restful stringify
Last synced: 11 months ago
JSON representation
Parse and stringify RESTFul filter strting
- Host: GitHub
- URL: https://github.com/kagawagao/filter-string
- Owner: kagawagao
- License: mit
- Created: 2017-12-04T06:21:25.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T02:29:43.000Z (about 3 years ago)
- Last Synced: 2025-04-08T00:47:06.714Z (11 months ago)
- Topics: filter, parse, restful, stringify
- Language: TypeScript
- Size: 1.2 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# filter-string
[](https://www.npmjs.com/package/filter-string)
[](https://www.npmjs.com/package/filter-string)
[](https://github.com/kagawagao/filter-string/blob/master/LICENSE)
[](https://travis-ci.org/kagawagao/filter-string)
[](http://standardjs.com/)
[](https://coveralls.io/github/kagawagao/filter-string?branch=master)
Parse and stringify RESTFul filter string
## Install
```bash
npm install filter-string
```
## Use
### Stringify
```javascript
import { stringify } from 'filter-string'
const filters = [
{
key: 'a',
op: 'eq',
value: 'xxx',
},
{
key: 'b',
op: 'gt',
value: 'yyy',
},
]
const $filter = stringify(filters, {
op: 'and',
})
// output
// a eq xxx and b gt yyy
```
### Parse
```javascript
import { parse } from 'filter-string'
const $filter = 'a eq xxx and b gt yyy'
const filters = parse($filter)
// output
// [{
// key: 'a',
// op: 'eq',
// value: 'xxx'
// }, {
// key: 'b',
// op: 'gt',
// value: 'yyy'
// }]
```
### Needed polyfill
```javascript
Array.prototype.filter
```
```javascript
Array.prototype.find
```
> FYI: You should add polyfill by yourself if need
## Development
- Installation
```bash
npm install
```
- Build for publish
```bash
npm run build
```
- Run test
```bash
npm run test
```