Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
crcn committed Jan 13, 2020
1 parent f9a0142 commit a7d5841
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ coverage
sift.csp.*
sift.min.*
lib/
esm/
es5m/
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,22 @@ Not expression:
["craig", "tim", "jake"].filter(sift({ $not: { $size: 5 } })); //['tim','jake']
```

### Date comparison

Mongodb allows you to do date comparisons like so:

```javascript
db.collection.find({ createdAt: { $gte: "2018-03-22T06:00:00Z" } });
```

In Sift, you'll need to specify a Date object:

```javascript
collection.find(
sift({ createdAt: { $gte: new Date("2018-03-22T06:00:00Z") } })
);
```

## Custom behavior

Sift works like MongoDB out of the box, but you're also able to modify the behavior to suite your needs.
Expand Down Expand Up @@ -423,33 +439,21 @@ var filter = sift(
[1, 2, 3, 4, 5].filter(filter); // 1, 3, 5
```

If you're looking to create a filter _without_ the standard operations, you can also do that:
#### Omitting builtin operations

You can create a filter function that omits the builtin operations like so:

```javascript
import { createQueryTester } from "sift/lib/core";
import * as operations from "sift/lib/operations";
import { createQueryTester } from "sift";
import { $in, $all, $nin, $lt } from "sift/operations";
const test = createQueryTester(
{
$eq: 10
},
{ operations }
{ $in, $all, $nin, $lt }
);

[1, 2, 3, 4, 10].filter(test);
```

#### Date comparison

Mongodb allows you to do date comparisons like so:

```javascript
db.collection.find({ createdAt: { $gte: "2018-03-22T06:00:00Z" } });
```

In Sift, you'll need to specify a Date object:

```javascript
collection.find(
sift({ createdAt: { $gte: new Date("2018-03-22T06:00:00Z") } })
);
```
For bundlers like Webpack and Rollup, operations that aren't used are omitted from application bundles via tree-shaking.
Empty file removed benchmark/index.js
Empty file.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const lib = require("./lib");

module.exports = lib.default;
Object.assign(module.exports, lib);
1 change: 1 addition & 0 deletions operations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./es5m/operations";
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "sift",
"description": "mongodb query style array filtering",
"version": "11.0.2",
"version": "11.0.7",
"repository": "crcn/sift.js",
"sideEffects": false,
"author": {
"name": "Craig Condon",
"email": "craig.j.condon@gmail.com",
"url": "http://crcn.io"
"email": "craig.j.condon@gmail.com"
},
"license": "MIT",
"engines": {},
Expand Down Expand Up @@ -35,13 +34,13 @@
"webpack": "^4.41.5",
"webpack-cli": "^3.1.2"
},
"main": "./lib/index.js",
"module": "./lib/index.js",
"es2015": "./lib/index.js",
"main": "./index.js",
"module": "./es5m/index.js",
"es2015": "./es5m/index.js",
"scripts": {
"build": "npm run build:lib && npm run build:esm && npm run build:min && npm run build:csp",
"build": "npm run build:lib && npm run build:es5m && npm run build:min && npm run build:csp",
"build:lib": "tsc",
"build:esm": "tsc",
"build:es5m": "tsc --build tsconfig.es5m.json",
"build:min": "webpack",
"build:csp": "CSP_ENABLED=1 webpack",
"build:watch": "tsc --watch",
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const createDefaultQueryTester = (
});
};

module.exports = createDefaultQueryTester;

export { Query, EqualsOperation };
export { Query, EqualsOperation, createQueryTester };

export default createDefaultQueryTester;
14 changes: 14 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createQueryTester, EqualsOperation } from "./es5m";
import * as operations from "./operations";

const tester = createQueryTester(
{ $test: 1 },
{
operations: {
$where: defaultOperations.$where,
$test: (params, ownertQuery) => {
return new EqualsOperation(params, ownertQuery);
}
}
}
);
File renamed without changes.
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
devtool: "source-map",
mode: "production",
entry: {
index: [__dirname + "/src/index.ts"]
index: [__dirname + "/test.js"]
},
output: {
path: __dirname,
Expand Down

0 comments on commit a7d5841

Please sign in to comment.