Comparing version 1.5.1 to 1.5.2
@@ -17,4 +17,4 @@ @function can-set.Algebra Algebra | ||
```js | ||
var set = require("can-set"); | ||
var defaultAlgebra = new set.Algebra(); | ||
import set from "can-set"; | ||
const defaultAlgebra = new set.Algebra(); | ||
``` | ||
@@ -26,10 +26,10 @@ | ||
// `{id: 2, ownerId: 5}` belongs to ``.getList({ownerId: 5})` | ||
defaultAlgebra.has({ownerId: 5}, {id: 2, ownerId: 5}) //-> true | ||
defaultAlgebra.has( { ownerId: 5 }, { id: 2, ownerId: 5 } ); //-> true | ||
defaultAlgebra.getSubset({ownerId: 5}, {}, | ||
[ | ||
{id: 1, ownerId: 2}, | ||
{id: 2, ownerId: 5}, | ||
{id: 3, ownerId: 12} | ||
]) //-> [{id: 2, ownerId: 5}] | ||
defaultAlgebra.getSubset( { ownerId: 5 }, {}, | ||
[ | ||
{ id: 1, ownerId: 2 }, | ||
{ id: 2, ownerId: 5 }, | ||
{ id: 3, ownerId: 12 } | ||
] ); //-> [{id: 2, ownerId: 5}] | ||
``` | ||
@@ -42,15 +42,15 @@ | ||
```js | ||
var set = require("can-set"); | ||
var todoAlgebra = new set.Algebra( | ||
set.props.boolean("completed"), | ||
set.props.id("_id"), | ||
set.props.offsetLimit("offset","limit") | ||
import set from "can-set"; | ||
const todoAlgebra = new set.Algebra( | ||
set.props.boolean( "completed" ), | ||
set.props.id( "_id" ), | ||
set.props.offsetLimit( "offset", "limit" ) | ||
); | ||
defaultAlgebra.getSubset({limit: 2, offset: 1}, {}, | ||
[ | ||
{id: 1, ownerId: 2}, | ||
{id: 2, ownerId: 5}, | ||
{id: 3, ownerId: 12} | ||
]) //-> [{id: 2, ownerId: 5},{id: 3, ownerId: 12}] | ||
defaultAlgebra.getSubset( { limit: 2, offset: 1 }, {}, | ||
[ | ||
{ id: 1, ownerId: 2 }, | ||
{ id: 2, ownerId: 5 }, | ||
{ id: 3, ownerId: 12 } | ||
] ); //-> [{id: 2, ownerId: 5},{id: 3, ownerId: 12}] | ||
``` | ||
@@ -57,0 +57,0 @@ |
@@ -28,10 +28,10 @@ @typedef {function} can-set.prop Prop | ||
{ | ||
union: ["Red","Blue","Green","Yellow"], | ||
intersection: ["Blue"], | ||
difference: ["Red"], | ||
count: 2000 | ||
} | ||
``` | ||
union: [ "Red", "Blue", "Green", "Yellow" ], | ||
intersection: [ "Blue" ], | ||
difference: [ "Red" ], | ||
count: 2000 | ||
} | ||
``` | ||
The count is `2000` because there might be 2000 items represented by colors "Red" and "Blue". Often | ||
the real number can not be known. |
@@ -9,6 +9,7 @@ @typedef {Object<String,can-set.prop>} can-set.compares Compares | ||
{ | ||
// return `true` if the values should be considered the same: | ||
lastName: function(aValue, bValue){ | ||
return (""+aValue).toLowerCase() === (""+bValue).toLowerCase(); | ||
} | ||
// return `true` if the values should be considered the same: | ||
lastName: function( aValue, bValue ) { | ||
return ( "" + aValue ).toLowerCase() === ( "" + bValue ).toLowerCase(); | ||
} | ||
} | ||
@@ -15,0 +16,0 @@ ``` |
@@ -17,22 +17,28 @@ @module {{}} can-set | ||
```js | ||
var set = require('can-set'); | ||
import set from "can-set"; | ||
// create an algebra | ||
var algebra = new set.Algebra( | ||
// specify the unique identifier on data | ||
set.props.id("_id"), | ||
// specify that completed can be true, false or undefined | ||
set.props.boolean("completed"), | ||
// specify properties that define pagination | ||
set.props.rangeInclusive("start","end"), | ||
// specify the property that controls sorting | ||
set.props.sort("orderBy"), | ||
) | ||
const algebra = new set.Algebra( | ||
// specify the unique identifier on data | ||
set.props.id( "_id" ), | ||
// specify that completed can be true, false or undefined | ||
set.props.boolean( "completed" ), | ||
// specify properties that define pagination | ||
set.props.rangeInclusive( "start", "end" ), | ||
// specify the property that controls sorting | ||
set.props.sort( "orderBy" ), | ||
); | ||
// compare two sets | ||
algebra.subset({start: 2, end: 3}, {start: 1, end: 4}) //-> true | ||
algebra.difference({} , {completed: true}) //-> {completed: false} | ||
algebra.subset( { start: 2, end: 3 }, { start: 1, end: 4 } ); //-> true | ||
algebra.difference( {}, { completed: true } ); //-> {completed: false} | ||
// perform operations on sets | ||
algebra.getSubset({start: 2,end: 3},{start: 1,end: 4}, | ||
[{id: 1},{id: 2},{id: 3},{id: 4}]) | ||
algebra.getSubset( { start: 2, end: 3 }, { start: 1, end: 4 }, | ||
[ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 } ] ); | ||
//-> [{id: 2},{id: 3}] | ||
@@ -75,3 +81,3 @@ ``` | ||
```js | ||
todoAlgebra.difference({}, {complete: false}) //-> {complete: true} | ||
todoAlgebra.difference( {}, { complete: false } ); //-> {complete: true} | ||
``` | ||
@@ -83,26 +89,26 @@ | ||
```js | ||
var cacheConnection = connect([ | ||
require("can-connect/data/memory-cache/memory-cache") | ||
],{ | ||
algebra: todoAlgebra | ||
}); | ||
const cacheConnection = connect( [ | ||
require( "can-connect/data/memory-cache/memory-cache" ) | ||
], { | ||
algebra: todoAlgebra | ||
} ); | ||
var todoConnection = connect([ | ||
require("can-connect/data/url/url"), | ||
require("can-connect/cache-requests/cache-requests") | ||
],{ | ||
cacheConnection: cacheConnection, | ||
url: "/todos", | ||
algebra: todoAlgebra | ||
}); | ||
const todoConnection = connect( [ | ||
require( "can-connect/data/url/url" ), | ||
require( "can-connect/cache-requests/cache-requests" ) | ||
], { | ||
cacheConnection: cacheConnection, | ||
url: "/todos", | ||
algebra: todoAlgebra | ||
} ); | ||
``` | ||
```js | ||
var todoStore = fixture.store([ | ||
{ _id : 1, name : 'Do the dishes', complete: true }, | ||
{ _id : 2, name : 'Walk the dog', complete: false } | ||
], | ||
todoAlgebra ); | ||
const todoStore = fixture.store( [ | ||
{ _id: 1, name: "Do the dishes", complete: true }, | ||
{ _id: 2, name: "Walk the dog", complete: false } | ||
], | ||
todoAlgebra ); | ||
fixture("/todos/{_id}", todoStore); | ||
fixture( "/todos/{_id}", todoStore ); | ||
``` | ||
@@ -126,4 +132,4 @@ | ||
```js | ||
var algebra = new set.Algebra(); | ||
algebra.has({sort: "name asc"}, {id: 1, name: "do dishes"}) //-> false | ||
const algebra = new set.Algebra(); | ||
algebra.has( { sort: "name asc" }, { id: 1, name: "do dishes" } ); //-> false | ||
``` | ||
@@ -134,6 +140,8 @@ | ||
```js | ||
var algebra = new set.Algebra({ | ||
sort: function() { return true; } | ||
}); | ||
algebra.has({sort: "name asc"}, {id: 1, name: "do dishes"}) //-> false | ||
const algebra = new set.Algebra( { | ||
sort: function() { | ||
return true; | ||
} | ||
} ); | ||
algebra.has( { sort: "name asc" }, { id: 1, name: "do dishes" } ); //-> false | ||
``` | ||
@@ -144,6 +152,6 @@ | ||
```js | ||
var algebra = new set.Algebra( | ||
set.props.sort("sort") | ||
const algebra = new set.Algebra( | ||
set.props.sort( "sort" ) | ||
); | ||
algebra.has({sort: "name asc"}, {id: 1, name: "do dishes"}) //-> true | ||
algebra.has( { sort: "name asc" }, { id: 1, name: "do dishes" } ); //-> true | ||
``` | ||
@@ -156,10 +164,12 @@ | ||
```js | ||
var algebra = new set.Algebra(); | ||
const algebra = new set.Algebra(); | ||
algebra.getSubset( | ||
{offset: 1, limit: 2}, | ||
{}, | ||
[ | ||
{id: 1, name: "do dishes"} | ||
{id: 2, name: "mow lawn"}, | ||
{id: 3, name: "trash"}]) //-> [] | ||
{ offset: 1, limit: 2 }, | ||
{}, | ||
[ | ||
{ id: 1, name: "do dishes" }, | ||
{ id: 2, name: "mow lawn" }, | ||
{ id: 3, name: "trash" } | ||
] | ||
); //-> [] | ||
``` | ||
@@ -171,15 +181,17 @@ | ||
```js | ||
var algebra = new set.Algebra( | ||
set.props.offsetLimit("offset","limit") | ||
const algebra = new set.Algebra( | ||
set.props.offsetLimit( "offset", "limit" ) | ||
); | ||
algebra.getSubset( | ||
{offset: 1, limit: 2}, | ||
{}, | ||
[ | ||
{id: 1, name: "do dishes"} | ||
{id: 2, name: "mow lawn"}, | ||
{id: 3, name: "trash"}]) //-> [ | ||
// {id: 2, name: "mow lawn"}, | ||
// {id: 3, name: "trash"} | ||
// ] | ||
{ offset: 1, limit: 2 }, | ||
{}, | ||
[ | ||
{ id: 1, name: "do dishes" }, | ||
{ id: 2, name: "mow lawn" }, | ||
{ id: 3, name: "trash" } | ||
] | ||
); //-> [ | ||
// {id: 2, name: "mow lawn"}, | ||
// {id: 3, name: "trash"} | ||
// ] | ||
``` |
@@ -9,11 +9,14 @@ @property {{}} can-set.props props | ||
```js | ||
var set = require("can-set"); | ||
var algebra = new set.Algebra( | ||
{ | ||
// ignore this property in set algebra | ||
sessionId: function(){ return true } | ||
}, | ||
set.props.boolean("completed"), | ||
set.props.rangeInclusive("start","end") | ||
import set from "can-set"; | ||
const algebra = new set.Algebra( | ||
{ | ||
// ignore this property in set algebra | ||
sessionId: function() { | ||
return true; | ||
} | ||
}, | ||
set.props.boolean( "completed" ), | ||
set.props.rangeInclusive( "start", "end" ) | ||
); | ||
``` |
{ | ||
"name": "can-set", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"description": "Set logic for CanJS", | ||
@@ -5,0 +5,0 @@ "main": "src/set.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
139542
1