Skip to content

Commit 9e37556

Browse files
New Feature: stringify (#46)
* Implement stringify, the reverse transform of parse * Properly JSON encode the attrValues when calling stringify, added tests * Remove unused file to fix watch * Ensure that logical operators are stringified correctly if they have more than 2 filters * Remove nested template literal * Add stringify to readme / minor cleanup * GH markdown requires space after the sharps Co-authored-by: Thomas Poignant <[email protected]>
1 parent 5eaeae6 commit 9e37556

30 files changed

+1472
-728
lines changed

README.md

+38-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ This is a fork https://www.npmjs.com/package/scim2-filter version 0.2.0 with bug
1212

1313
usage
1414
-----
15-
15+
### parse
1616
You can parse filter query and get ast.
17-
1817
```javascript
1918
import {parse} from 'scim2-parse-filter';
2019

@@ -50,7 +49,7 @@ assert.deepEqual(f, {
5049
});
5150
```
5251

53-
52+
### filter
5453
and You can use filter in json.
5554

5655
```javascript
@@ -65,5 +64,41 @@ const ret = users.filter(f);
6564
assert.deepEqual(ret, [users[0]]);
6665
```
6766

67+
### stringify
68+
and you can convert an AST back into a SCIM query.
69+
70+
```typescript
71+
import { Filter, stringify } from 'scim2-parse-filter';
6872

73+
const ast: Filter = {
74+
op:"and",
75+
filters:[
76+
{
77+
op:"eq",
78+
attrPath:"userType",
79+
compValue:"Employee"
80+
},
81+
{
82+
op:"[]",
83+
attrPath:"emails",
84+
valFilter:{
85+
op:"and",
86+
filters:[
87+
{
88+
op:"eq",
89+
attrPath:"type",
90+
compValue:"work"
91+
},
92+
{
93+
op:"co",
94+
attrPath:"value",
95+
compValue:"@example.com"
96+
}
97+
]
98+
}
99+
}
100+
]
101+
};
69102

103+
assert.deepEqual(stringify(ast), 'userType eq "Employee" and emails[type eq "work" and value co "@example.com"]');
104+
```

0 commit comments

Comments
 (0)