Skip to content

Commit bc7c646

Browse files
authored
Remove lodash dependency (#923)
1 parent c68379a commit bc7c646

File tree

8 files changed

+66
-36
lines changed

8 files changed

+66
-36
lines changed

packages/neo4j-driver/package-lock.json

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

packages/neo4j-driver/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"karma-jasmine": "^4.0.2",
7474
"karma-source-map-support": "^1.4.0",
7575
"karma-spec-reporter": "^0.0.33",
76-
"lodash": "^4.17.21",
7776
"lolex": "^6.0.0",
7877
"minimist": "^1.2.6",
7978
"mustache": "^4.2.0",

packages/neo4j-driver/test/session.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import neo4j from '../src'
2121
import { READ } from '../src/driver'
2222
import sharedNeo4j from './internal/shared-neo4j'
23-
import _ from 'lodash'
2423
import testUtils from './internal/test-utils'
2524
import {
2625
newError,
@@ -846,8 +845,8 @@ describe('#integration session', () => {
846845
allBookmarks.push(bookmarks)
847846
}
848847

849-
expect(_.uniq(allBookmarks).length).toEqual(nodeCount)
850-
allBookmarks.forEach(bookmarks => expect(_.isArray(bookmarks)).toBeTruthy())
848+
expect(new Set(allBookmarks).size).toEqual(nodeCount)
849+
allBookmarks.forEach(bookmarks => expect(Array.isArray(bookmarks)).toBeTruthy())
851850

852851
const session = driver.session({
853852
defaultAccessMode: READ,

packages/neo4j-driver/test/spatial-types.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import neo4j, { int } from '../src'
2121
import sharedNeo4j from './internal/shared-neo4j'
2222
import { isPoint, Point } from 'neo4j-driver-core'
23-
import _ from 'lodash'
2423

2524
const WGS_84_2D_CRS_CODE = neo4j.int(4326)
2625
const CARTESIAN_2D_CRS_CODE = neo4j.int(7203)
@@ -198,7 +197,7 @@ describe('#integration spatial-types', () => {
198197
'RETURN point({x: 42.231, y: 176.938123})',
199198
point => {
200199
expect(isPoint(point)).toBeTruthy()
201-
expect(_.isNumber(point.srid)).toBeTruthy()
200+
expect(typeof point.srid).toEqual('number')
202201
expect(point.srid).toEqual(CARTESIAN_2D_CRS_CODE.toNumber())
203202
}
204203
)

packages/neo4j-driver/test/stress-test.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import neo4j from '../src'
2121
import { READ, WRITE } from '../src/driver'
2222
import parallelLimit from 'async/parallelLimit'
23-
import _ from 'lodash'
2423
import sharedNeo4j from './internal/shared-neo4j'
2524

2625
const TEST_MODES = {
@@ -158,10 +157,12 @@ function isCluster () {
158157

159158
function createCommands (context) {
160159
const uniqueCommands = createUniqueCommands(context)
161-
160+
function sample (arr) {
161+
return arr[Math.floor(Math.random() * arr.length)]
162+
}
162163
const commands = []
163164
for (let i = 0; i < TEST_MODE.commandsCount; i++) {
164-
const randomCommand = _.sample(uniqueCommands)
165+
const randomCommand = sample(uniqueCommands)
165166
commands.push(randomCommand)
166167
}
167168

@@ -455,9 +456,9 @@ function verifyRecord (record) {
455456
return new Error(`Unexpected labels in node: ${JSON.stringify(node)}`)
456457
}
457458

458-
const propertyKeys = _.keys(node.properties)
459+
const propertyKeys = Object.keys(node.properties)
459460
if (
460-
!_.isEmpty(propertyKeys) &&
461+
propertyKeys.length > 0 &&
461462
!arraysEqual(['name', 'salary'], propertyKeys)
462463
) {
463464
return new Error(
@@ -584,7 +585,8 @@ function fromEnvOrDefault (envVariableName, defaultValue = undefined) {
584585
}
585586

586587
function arraysEqual (array1, array2) {
587-
return _.difference(array1, array2).length === 0
588+
const resultant = array1.filter(item => !array2.find(item2 => item2.valueOf() === item.valueOf()))
589+
return resultant.length === 0
588590
}
589591

590592
class Context {

packages/neo4j-driver/test/stress.test.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import neo4j from '../src'
2121
import { READ, WRITE } from '../src/driver'
2222
import parallelLimit from 'async/parallelLimit'
23-
import _ from 'lodash'
2423
import sharedNeo4j from './internal/shared-neo4j'
2524

2625
describe('#integration stress tests', () => {
@@ -120,11 +119,14 @@ describe('#integration stress tests', () => {
120119
)
121120

122121
function createCommands (context) {
122+
function sample (arr) {
123+
return arr[Math.floor(Math.random() * arr.length)]
124+
}
123125
const uniqueCommands = createUniqueCommands(context)
124126

125127
const commands = []
126128
for (let i = 0; i < TEST_MODE.commandsCount; i++) {
127-
const randomCommand = _.sample(uniqueCommands)
129+
const randomCommand = sample(uniqueCommands)
128130
commands.push(randomCommand)
129131
}
130132

@@ -427,9 +429,9 @@ describe('#integration stress tests', () => {
427429
return new Error(`Unexpected labels in node: ${JSON.stringify(node)}`)
428430
}
429431

430-
const propertyKeys = _.keys(node.properties)
432+
const propertyKeys = Object.keys(node.properties)
431433
if (
432-
!_.isEmpty(propertyKeys) &&
434+
propertyKeys.length > 0 &&
433435
!arraysEqual(['name', 'salary'], propertyKeys)
434436
) {
435437
return new Error(
@@ -550,19 +552,19 @@ describe('#integration stress tests', () => {
550552
}
551553

552554
function addressesForMultiDb (records, role, db = 'neo4j') {
553-
return _.uniq(
555+
return [...new Set(
554556
records
555557
.filter(record => record.get('databases')[db] === role)
556558
.map(record => record.get('addresses')[0].replace('bolt://', ''))
557-
)
559+
)]
558560
}
559561

560562
function addressesWithRole (records, role) {
561-
return _.uniq(
563+
return [...new Set(
562564
records
563565
.filter(record => record.get('role') === role)
564566
.map(record => record.get('addresses')[0].replace('bolt://', ''))
565-
)
567+
)]
566568
}
567569

568570
function assertAllAddressesServedReadQueries (addresses, readQueriesByServer) {
@@ -641,7 +643,8 @@ describe('#integration stress tests', () => {
641643
}
642644

643645
function arraysEqual (array1, array2) {
644-
return _.difference(array1, array2).length === 0
646+
const resultant = array1.filter(item => !array2.find(item2 => item2.valueOf() === item.valueOf()))
647+
return resultant.length === 0
645648
}
646649

647650
class Context {

packages/neo4j-driver/test/temporal-types.test.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import neo4j from '../src'
2121
import sharedNeo4j from './internal/shared-neo4j'
2222
import { toNumber, internal } from 'neo4j-driver-core'
2323
import timesSeries from 'async/timesSeries'
24-
import _ from 'lodash'
2524
import testUtils from './internal/test-utils'
2625

2726
const {
@@ -1423,11 +1422,11 @@ describe('#integration temporal-types', () => {
14231422
}
14241423

14251424
async function testSendAndReceiveArrayOfRandomTemporalValues (valueGenerator) {
1426-
const arrayLength = _.random(
1425+
const arrayLength = random(
14271426
MIN_TEMPORAL_ARRAY_LENGTH,
14281427
MAX_TEMPORAL_ARRAY_LENGTH
14291428
)
1430-
const values = _.range(arrayLength).map(() => valueGenerator())
1429+
const values = range(arrayLength).map(() => valueGenerator())
14311430

14321431
await testSendReceiveTemporalValue(values)
14331432
}
@@ -1486,12 +1485,12 @@ describe('#integration temporal-types', () => {
14861485
}
14871486

14881487
function randomDuration () {
1489-
const sign = _.sample([-1, 1]) // duration can be negative
1488+
const sign = sample([-1, 1]) // duration can be negative
14901489
return duration(
1491-
sign * _.random(0, MAX_DURATION_COMPONENT),
1492-
sign * _.random(0, MAX_DURATION_COMPONENT),
1493-
sign * _.random(0, MAX_DURATION_COMPONENT),
1494-
_.random(0, MAX_NANO_OF_SECOND)
1490+
sign * random(0, MAX_DURATION_COMPONENT),
1491+
sign * random(0, MAX_DURATION_COMPONENT),
1492+
sign * random(0, MAX_DURATION_COMPONENT),
1493+
random(0, MAX_NANO_OF_SECOND)
14951494
)
14961495
}
14971496

@@ -1600,7 +1599,24 @@ describe('#integration temporal-types', () => {
16001599
}
16011600

16021601
function randomZoneId () {
1603-
return _.sample(ZONE_IDS)
1602+
return sample(ZONE_IDS)
1603+
}
1604+
1605+
function random (lower, upper) {
1606+
const interval = upper - lower
1607+
return lower + Math.floor(Math.random() * interval)
1608+
}
1609+
1610+
function range (size) {
1611+
const arr = []
1612+
for (let i; i < size; i++) {
1613+
arr.push(i)
1614+
}
1615+
return arr
1616+
}
1617+
1618+
function sample (arr) {
1619+
return arr[Math.floor(Math.random() * arr.length)]
16041620
}
16051621

16061622
function duration (months, days, seconds, nanoseconds) {
@@ -1698,7 +1714,7 @@ describe('#integration temporal-types', () => {
16981714
}
16991715

17001716
function randomInt (lower, upper) {
1701-
return neo4j.int(_.random(lower, upper))
1717+
return neo4j.int(random(lower, upper))
17021718
}
17031719

17041720
function testStandardDateToLocalTimeConversion (date, nanosecond) {

packages/neo4j-driver/test/types.test.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import neo4j from '../src'
2121
import sharedNeo4j from './internal/shared-neo4j'
22-
import _ from 'lodash'
2322

2423
describe('#integration null value', () => {
2524
it('should support null', testValue(null))
@@ -246,13 +245,26 @@ function runReturnQuery (driver, actual, expected) {
246245
}
247246

248247
function randomByteArrays (count, minLength, maxLength) {
249-
return _.range(count).map(() => {
250-
const length = _.random(minLength, maxLength)
248+
return range(count).map(() => {
249+
const length = random(minLength, maxLength)
251250
return randomByteArray(length)
252251
})
253252
}
254253

255254
function randomByteArray (length) {
256-
const array = _.range(length).map(() => _.random(-128, 127))
255+
const array = range(length).map(() => random(-128, 127))
257256
return new Int8Array(array)
258257
}
258+
259+
function range (size) {
260+
const arr = []
261+
for (let i; i < size; i++) {
262+
arr.push(i)
263+
}
264+
return arr
265+
}
266+
267+
function random (lower, upper) {
268+
const interval = upper - lower
269+
return lower + Math.floor(Math.random() * interval)
270+
}

0 commit comments

Comments
 (0)