Skip to content

Commit 4a92c47

Browse files
bryanmikaelianhbrls
authored andcommitted
Replace @ndhoule/includes with lodash.includes (segmentio#211)
1 parent d23606d commit 4a92c47

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
- Fix Potential DOM-based XSS via prototype pollution
1212

13+
# 4.1.4 / 2020-09-16
14+
15+
- Replace `@ndhoule/includes` with `lodash.includes`
16+
1317
# 4.1.3 / 2020-09-16
1418

1519
- Replace `@ndhoule/pick` with `lodash.pick`

lib/normalize.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
'use strict';
2-
31
import { Message } from './types';
2+
import includes from 'lodash.includes'
43

54
/**
65
* Module Dependencies.
76
*/
87

98
var debug = require('debug')('analytics.js:normalize');
109
var defaults = require('@ndhoule/defaults');
11-
var includes = require('@ndhoule/includes');
1210
var type = require('component-type');
1311
var uuid = require('uuid/v4');
1412
var md5 = require('spark-md5').hash;
@@ -43,14 +41,14 @@ interface NormalizedMessage {
4341
}
4442

4543
function normalize(msg: Message, list: Array<any>): NormalizedMessage {
46-
var lower = list?.map(function(s) {
44+
const lower = list?.map(function(s) {
4745
return s.toLowerCase();
4846
});
49-
var opts: Message = msg.options || {};
50-
var integrations = opts.integrations || {};
51-
var providers = opts.providers || {};
52-
var context = opts.context || {};
53-
var ret: {
47+
const opts: Message = msg.options || {};
48+
const integrations = opts.integrations || {};
49+
const providers = opts.providers || {};
50+
const context = opts.context || {};
51+
let ret: {
5452
integrations?: { [key: string]: string };
5553
context?: unknown;
5654
} = {};
@@ -76,7 +74,7 @@ function normalize(msg: Message, list: Array<any>): NormalizedMessage {
7674
// move all toplevel options to msg
7775
// and the rest to context.
7876
Object.keys(opts).forEach(key => {
79-
if (includes(key, toplevel)) {
77+
if (includes(toplevel, key)) {
8078
ret[key] = opts[key];
8179
} else {
8280
context[key] = opts[key];
@@ -96,9 +94,9 @@ function normalize(msg: Message, list: Array<any>): NormalizedMessage {
9694

9795
function integration(name: string) {
9896
return !!(
99-
includes(name, list) ||
97+
includes(list, name) ||
10098
name.toLowerCase() === 'all' ||
101-
includes(name.toLowerCase(), lower)
99+
includes(lower, name.toLowerCase())
102100
);
103101
}
104102
}

lib/pageDefaults.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
'use strict';
2-
31
import { PageDefaults } from './types';
4-
5-
/*
6-
* Module dependencies.
7-
*/
8-
9-
var canonical = require('@segment/canonical');
10-
var includes = require('@ndhoule/includes');
11-
var url = require('component-url');
2+
import includes from 'lodash.includes'
3+
import canonical from '@segment/canonical'
4+
import url from 'component-url'
125

136
/**
147
* Return a default `options.context.page` object.
@@ -31,9 +24,9 @@ function pageDefaults(): PageDefaults {
3124
*/
3225

3326
function canonicalPath(): string {
34-
var canon = canonical();
27+
const canon = canonical();
3528
if (!canon) return window.location.pathname;
36-
var parsed = url.parse(canon);
29+
const parsed = url.parse(canon);
3730
return parsed.pathname;
3831
}
3932

@@ -43,10 +36,10 @@ function canonicalPath(): string {
4336
*/
4437

4538
function canonicalUrl(search: string): string {
46-
var canon = canonical();
47-
if (canon) return includes('?', canon) ? canon : canon + search;
48-
var url = window.location.href;
49-
var i = url.indexOf('#');
39+
const canon = canonical();
40+
if (canon) return includes(canon, '?') ? canon : canon + search;
41+
const url = window.location.href;
42+
const i = url.indexOf('#');
5043
return i === -1 ? url : url.slice(0, i);
5144
}
5245

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"homepage": "https://github.com/segmentio/analytics.js-core#readme",
3232
"dependencies": {
3333
"@ndhoule/defaults": "^2.0.1",
34-
"@ndhoule/includes": "^2.0.1",
3534
"@segment/canonical": "^1.0.0",
3635
"@segment/cookie": "^1.1.5",
3736
"@segment/is-meta": "^1.0.0",
@@ -53,6 +52,7 @@
5352
"is": "^3.1.0",
5453
"lodash.assignin": "^4.2.0",
5554
"lodash.clonedeep": "^4.5.0",
55+
"lodash.includes": "^4.3.0",
5656
"lodash.pick": "^4.4.0",
5757
"new-date": "^1.0.0",
5858
"next-tick": "^0.2.2",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6032,6 +6032,11 @@ lodash.has@^4.5.2:
60326032
resolved "https://registry.yarnpkg.com/lodash.has/-/lodash.has-4.5.2.tgz#d19f4dc1095058cccbe2b0cdf4ee0fe4aa37c862"
60336033
integrity sha1-0Z9NwQlQWMzL4rDN9O4P5Ko3yGI=
60346034

6035+
lodash.includes@^4.3.0:
6036+
version "4.3.0"
6037+
resolved "https://registry.yarnpkg.com/lodash.includes/-/lodash.includes-4.3.0.tgz#60bb98a87cb923c68ca1e51325483314849f553f"
6038+
integrity sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8=
6039+
60356040
lodash.isarray@^4.0.0:
60366041
version "4.0.0"
60376042
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-4.0.0.tgz#2aca496b28c4ca6d726715313590c02e6ea34403"

0 commit comments

Comments
 (0)