8000 Fix intersection (#541) · correct-js/js-data@b254811 · GitHub
[go: up one dir, main page]

Skip to content

Commit b254811

Browse files
authored
Fix intersection (js-data#541)
* fix(): intersection util ensure params always array * chore(): release 3.0.6
1 parent 50e89b3 commit b254811

File tree

9 files changed

+109
-36
lines changed

9 files changed

+109
-36
lines changed

AUTHORS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#
88
Alex <alexander.maznev@gmail.com>
99
antoinebrault <antoinebrault@gmail.com>
10+
Cory <coryrobinson42@gmail.com>
11+
Cory Robinson <coryrobinson42@gmail.com>
1012
Cory Robinson <crobinson42@users.noreply.github.com>
1113
David Madner <david.madner@gmx.net>
1214
Frans Krojegård <frans@krojegard.com>
@@ -17,9 +19,12 @@ Jeremy TRUFIER <jeremy@trufier.com>
1719
Ken Børge Viktil <ken.borge.viktil@evry.com>
1820
Kent C. Dodds <kent@doddsfamily.us>
1921
Kurt Van Delden <kurt@vandeldenassociates.com>
22+
lumimies <lumimies@gmail.com>
2023
Matt Lewis <matthew.lewis@socialsignin.co.uk>
24+
Matt Lewis <mattlewis92@users.noreply.github.com>
2125
Matt Winkler <matt@mattwinkler.com>
2226
Matthew Overall <matthew.overall@gmail.com>
27+
Michael Underwood <mike.underwood@gmail.com>
2328
Mitranim <me@mitranim.com>
2429
Nick Escallon <nickescallon@gmail.com>
2530
Nick Vahalik <nick@nickvahalik.com>

dist/js-data.es2015.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js-data.es2015.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js-data.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js-data.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js-data.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js-data.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "js-data",
33
"description": "Robust, framework-agnostic in-memory data store.",
4-
"version": "3.0.5",
4+
"version": "3.0.6",
55
"homepage": "http://www.js-data.io",
66
"repository": {
77
"type": "git",

src/utils.js

Lines changed: 91 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
const DOMAIN = 'utils'
1313

1414
const INFINITY = 1 / 0
15-
const MAX_INTEGER = 1.7976931348623157e+308
15+
const MAX_INTEGER = 1.7976931348623157e308
1616
const BOOL_TAG = '[object Boolean]'
1717
const DATE_TAG = '[object Date]'
1818
const FUNC_TAG = '[object Function]'
@@ -24,8 +24,14 @@ const objToString = Object.prototype.toString
2424
const PATH = /^(.+)\.(.+)$/
2525

2626
const ERRORS = {
27-
'400' () { return `expected: ${arguments[0]}, found: ${arguments[2] ? arguments[1] : typeof arguments[1]}` },
28-
'404' () { return `${arguments[0]} not found` }
27+
'400' () {
28+
return `expected: ${arguments[0]}, found: ${
29+
arguments[2] ? arguments[1] : typeof arguments[1]
30+
}`
31+
},
32+
'404' () {
33+
return `${arguments[0]} not found`
34+
}
2935
}
3036

3137
const toInteger = function (value) {
@@ -35,7 +41,7 @@ const toInteger = function (value) {
3541
// Coerce to number
3642
value = +value
3743
if (value === INFINITY || value === -INFINITY) {
38-
const sign = (value < 0 ? -1 : 1)
44+
const sign = value < 0 ? -1 : 1
3945
return sign * MAX_INTEGER
4046
}
4147
const remainder = value % 1
@@ -47,7 +53,7 @@ const toStr = function (value) {
4753
}
4854

4955
const isPlainObject = function (value) {
50-
return (!!value && typeof value === 'object' && value.constructor === Object)
56+
return !!value && typeof value === 'object' && value.constructor === Object
5157
}
5258

5359
const mkdirP = function (object, path) {
@@ -96,7 +102,12 @@ const utils = {
96102
*/
97103
_ (dest, src) {
98104
utils.forOwn(src, function (value, key) {
99-
if (key && dest[key] === undefined && !utils.isFunction(value) && key.indexOf('_') !== 0) {
105+
if (
106+
key &&
107+
dest[key] === undefined &&
108+
!utils.isFunction(value) &&
109+
key.indexOf('_') !== 0
110+
) {
100111
dest[key] = value
101112
}
102113
})
@@ -138,7 +149,12 @@ const utils = {
138149
optsCopy.with = opts.with.slice()
139150
optsCopy._activeWith = optsCopy.with.splice(index, 1)[0]
140151
optsCopy.with.forEach(function (relation, i) {
141-
if (relation && relation.indexOf(containedName) === 0 && relation.length >= containedName.length && relation[containedName.length] === '.') {
152+
if (
153+
relation &&
154+
relation.indexOf(containedName) === 0 &&
155+
relation.length >= containedName.length &&
156+
relation[containedName.length] === '.'
157+
) {
142158
optsCopy.with[i] = relation.substr(containedName.length + 1)
143159
} else {
144160
optsCopy.with[i] = ''
@@ -225,9 +241,10 @@ const utils = {
225241
areDifferent (newObject, oldObject, opts) {
226242
opts || (opts = {})
227243
const diff = utils.diffObjects(newObject, oldObject, opts)
228-
const diffCount = Object.keys(diff.added).length +
229-
Object.keys(diff.removed).length +
230-
Object.keys(diff.changed).length
244+
const diffCount =
245+
Object.keys(diff.added).length +
246+
Object.keys(diff.removed).length +
247+
Object.keys(diff.changed).length
231248
return diffCount > 0
232249
},
233250

@@ -293,13 +310,23 @@ const utils = {
293310
if (plain) {
294311
to = utils.copy(from, {}, stackFrom, stackTo, blacklist, plain)
295312
} else {
296-
to = utils.copy(from, Object.create(Object.getPrototypeOf(from)), stackFrom, stackTo, blacklist, plain)
313+
to = utils.copy(
314+
from,
315+
Object.create(Object.getPrototypeOf(from)),
316+
stackFrom,
317+
stackTo,
318+
blacklist,
319+
plain
320+
)
297321
}
298322
}
299323
}
300324
} else {
301325
if (from === to) {
302-
throw utils.err(`${DOMAIN}.copy`)(500, 'Cannot copy! Source and destination are identical.')
326+
throw utils.err(`${DOMAIN}.copy`)(
327+
500,
328+
'Cannot copy! Source and destination are identical.'
329+
)
303330
}
304331

305332
stackFrom = stackFrom || []
@@ -320,7 +347,14 @@ const utils = {
320347
let i
321348
to.length = 0
322349
for (i = 0; i < from.length; i++) {
323-
result = utils.copy(from[i], null, stackFrom, stackTo, blacklist, plain)
350+
result = utils.copy(
351+
from[i],
352+
null,
353+
stackFrom,
354+
stackTo,
355+
blacklist,
356+
plain
357+
)
324358
if (utils.isObject(from[i])) {
325359
stackFrom.push(from[i])
326360
stackTo.push(result)
@@ -340,7 +374,14 @@ const utils = {
340374
if (utils.isBlacklisted(key, blacklist)) {
341375
continue
342376
}
343-
result = utils.copy(from[key], null, stackFrom, stackTo, blacklist, plain)
377+
result = utils.copy(
378+
from[key],
379+
null,
380+
stackFrom,
381+
stackTo,
382+
blacklist,
383+
plain
384+
)
344385
if (utils.isObject(from[key])) {
345386
stackFrom.push(from[key])
346387
stackTo.push(result)
@@ -523,7 +564,10 @@ http://www.js-data.io/v3.0/docs/errors#400]
523564
err (domain, target) {
524565
return function (code) {
525566
const prefix = `[${domain}:${target}] `
526-
let message = ERRORS[code].apply(null, Array.prototype.slice.call(arguments, 1))
567+
let message = ERRORS[code].apply(
568+
null,
569+
Array.prototype.slice.call(arguments, 1)
570+
)
527571
message = `${prefix}${message}
528572
http://www.js-data.io/v3.0/docs/errors#${code}`
529573
return new Error(message)
@@ -552,8 +596,12 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
552596
target = target || this
553597
let _events = {}
554598
if (!getter && !setter) {
555-
getter = function () { return _events }
556-
setter = function (value) { _events = value }
599+
getter = function () {
600+
return _events
601+
}
602+
setter = function (value) {
603+
_events = value
604+
}
557605
}
558606
Object.defineProperties(target, {
559607
emit: {
@@ -831,16 +879,18 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
831879
* @see utils.set
832880
* @since 3.0.0
833881
*/
834-
'get': function (object, prop) {
882+
get: function (object, prop) {
835883
if (!prop) {
836884
return
837885
}
838886
const parts = prop.split('.')
839887
const last = parts.pop()
840888

841-
while (prop = parts.shift()) { // eslint-disable-line
889+
while ((prop = parts.shift())) {
890+
// eslint-disable-line
842891
object = object[prop]
843-
if (object == null) { // eslint-disable-line
892+
if (object == null) {
893+
// eslint-disable-line
844894
return
845895
}
846896
}
@@ -904,6 +954,8 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
904954
if (!array1 || !array2) {
905955
return []
906956
}
957+
array1 = Array.isArray(array1) ? array1 : [array1]
958+
array2 = Array.isArray(array2) ? array2 : [array2]
907959
const result = []
908960
let item
909961
let i
@@ -961,7 +1013,10 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
9611013
}
9621014
let matches
9631015
for (var i = 0; i < blacklist.length; i++) {
964-
if ((toStr(blacklist[i]) === REGEXP_TAG && blacklist[i].test(prop)) || blacklist[i] === prop) {
1016+
if (
1017+
(toStr(blacklist[i]) === REGEXP_TAG && blacklist[i].test(prop)) ||
1018+
blacklist[i] === prop
1019+
) {
9651020
matches = prop
9661021
return !!matches
9671022
}
@@ -1004,7 +1059,7 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
10041059
* @since 3.0.0
10051060
*/
10061061
isDate (value) {
1007-
return (value && typeof value === 'object' && toStr(value) === DATE_TAG)
1062+
return value && typeof value === 'object' && toStr(value) === DATE_TAG
10081063
},
10091064

10101065
/**
@@ -1085,7 +1140,10 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
10851140
*/
10861141
isNumber (value) {
10871142
const type = typeof value
1088-
return type === 'number' || (value && type === 'object' && toStr(value) === NUMBER_TAG)
1143+
return (
1144+
type === 'number' ||
1145+
(value && type === 'object' && toStr(value) === NUMBER_TAG)
1146+
)
10891147
},
10901148

10911149
/**
@@ -1164,7 +1222,10 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
11641222
* @since 3.0.0
11651223
*/
11661224
isString (value) {
1167-
return typeof value === 'string' || (value && typeof value === 'object' && toStr(value) === STRING_TAG)
1225+
return (
1226+
typeof value === 'string' ||
1227+
(value && typeof value === 'object' && toStr(value) === STRING_TAG)
1228+
)
11681229
},
11691230

11701231
/**
@@ -1223,7 +1284,8 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
12231284
if (level === 'debug' && !this.debug) {
12241285
return
12251286
}
1226-
const prefix = `${level.toUpperCase()}: (${this.name || this.constructor.name})`
1287+
const prefix = `${level.toUpperCase()}: (${this.name ||
1288+
this.constructor.name})`
12271289
if (utils.isFunction(console[level])) {
12281290
console[level](prefix, ...args)
12291291
} else {
@@ -1575,9 +1637,11 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
15751637
const parts = path.split('.')
15761638
const last = parts.pop()
15771639

1578-
while (path = parts.shift()) { // eslint-disable-line
1640+
while ((path = parts.shift())) {
1641+
// eslint-disable-line
15791642
object = object[path]
1580-
if (object == null) { // eslint-disable-line
1643+
if (object == null) {
1644+
// eslint-disable-line
15811645
return
15821646
}
15831647
}

0 commit comments

Comments
 (0)
0