From bf6caae5df81258afec81c12fa45f23d78321322 Mon Sep 17 00:00:00 2001 From: SianLoong Date: Wed, 22 Jan 2020 17:03:14 +0800 Subject: [PATCH] feat: support like and not like operator --- __tests__/index.test.ts | 15 +++++++++++++-- package.json | 2 +- src/expression.ts | 6 ++++++ src/index.ts | 40 +--------------------------------------- 4 files changed, 21 insertions(+), 42 deletions(-) diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index 0419f3a..6c367fd 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -1,4 +1,14 @@ -import { filter, ne, or, eq, includes, notIncludes, gte, lte } from '../src'; +import { + filter, + ne, + or, + eq, + includes, + notIncludes, + gte, + lte, + like, +} from '../src'; test('Query String', () => { const qs = filter( @@ -6,11 +16,12 @@ test('Query String', () => { ne('flag', true), includes('status', ['A', 'B', 'C']), notIncludes('status', ['A', 'B', 'C']), + like('test', 'xxx%'), ) .sort('a', 'b', 'c') .qs(); expect(qs).toBe( - `filter=(name==1;flag=ne=true;status=in=A,B,C;status=nin=A,B,C)&sort=a,b,c&limit=100`, + `filter=(name==1;flag=ne=true;status=in=A,B,C;status=nin=A,B,C;test=like='xxx%')&sort=a,b,c&limit=100`, ); expect(filter(ne('b', 'value'), or(eq('c', 'v2'), eq('d', 'v4'))).qs()).toBe( diff --git a/package.json b/package.json index 31e708a..deb5567 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rsql", - "version": "1.0.6", + "version": "1.0.7", "description": "RSQL query string generator", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/expression.ts b/src/expression.ts index cbd92b2..191ffe3 100644 --- a/src/expression.ts +++ b/src/expression.ts @@ -34,6 +34,12 @@ export class Expression implements IStringer { case Operator.NotIn: str += '=nin='; break; + case Operator.Like: + str += '=like='; + break; + case Operator.NotLike: + str += '=nlike='; + break; default: throw new Error('unsupported Operator'); } diff --git a/src/index.ts b/src/index.ts index 3031318..a38910e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,39 +1 @@ -import { - and, - eq, - filter, - gt, - gte, - includes, - like, - limit, - lt, - lte, - ne, - notIncludes, - notLike, - or, - select, - sort, -} from './query'; - -export { - and, - eq, - eq as equal, - filter, - gt, - gte, - includes, - like, - limit, - lt, - lte, - ne, - ne as notEqual, - notIncludes, - notLike, - or, - select, - sort, -}; +export * from './query';