Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Replace @ndhoule/includes with lodash.includes #211

Merged
merged 2 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 4.1.4 / 2020-09-16

- Replace `@ndhoule/includes` with `lodash.includes`

# 4.1.3 / 2020-09-16

- Replace `@ndhoule/pick` with `lodash.pick`
Expand Down
22 changes: 10 additions & 12 deletions lib/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict';

import { Message } from './types';
import includes from 'lodash.includes'

/**
* Module Dependencies.
*/

var debug = require('debug')('analytics.js:normalize');
var defaults = require('@ndhoule/defaults');
var includes = require('@ndhoule/includes');
var type = require('component-type');
var uuid = require('uuid/v4');
var md5 = require('spark-md5').hash;
Expand Down Expand Up @@ -43,14 +41,14 @@ interface NormalizedMessage {
}

function normalize(msg: Message, list: Array<any>): NormalizedMessage {
var lower = list?.map(function(s) {
const lower = list?.map(function(s) {
return s.toLowerCase();
});
var opts: Message = msg.options || {};
var integrations = opts.integrations || {};
var providers = opts.providers || {};
var context = opts.context || {};
var ret: {
const opts: Message = msg.options || {};
const integrations = opts.integrations || {};
const providers = opts.providers || {};
const context = opts.context || {};
let ret: {
integrations?: { [key: string]: string };
context?: unknown;
} = {};
Expand All @@ -76,7 +74,7 @@ function normalize(msg: Message, list: Array<any>): NormalizedMessage {
// move all toplevel options to msg
// and the rest to context.
Object.keys(opts).forEach(key => {
if (includes(key, toplevel)) {
if (includes(toplevel, key)) {
ret[key] = opts[key];
} else {
context[key] = opts[key];
Expand All @@ -96,9 +94,9 @@ function normalize(msg: Message, list: Array<any>): NormalizedMessage {

function integration(name: string) {
return !!(
includes(name, list) ||
includes(list, name) ||
name.toLowerCase() === 'all' ||
includes(name.toLowerCase(), lower)
includes(lower, name.toLowerCase())
);
}
}
25 changes: 9 additions & 16 deletions lib/pageDefaults.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
'use strict';

import { PageDefaults } from './types';

/*
* Module dependencies.
*/

var canonical = require('@segment/canonical');
var includes = require('@ndhoule/includes');
var url = require('component-url');
import includes from 'lodash.includes'
import canonical from '@segment/canonical'
import url from 'component-url'

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

function canonicalPath(): string {
var canon = canonical();
const canon = canonical();
if (!canon) return window.location.pathname;
var parsed = url.parse(canon);
const parsed = url.parse(canon);
return parsed.pathname;
}

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

function canonicalUrl(search: string): string {
var canon = canonical();
if (canon) return includes('?', canon) ? canon : canon + search;
var url = window.location.href;
var i = url.indexOf('#');
const canon = canonical();
if (canon) return includes(canon, '?') ? canon : canon + search;
const url = window.location.href;
const i = url.indexOf('#');
return i === -1 ? url : url.slice(0, i);
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@segment/analytics.js-core",
"author": "Segment <[email protected]>",
"version": "4.1.3",
"version": "4.1.4",
"description": "The hassle-free way to integrate analytics into any web application.",
"types": "lib/index.d.ts",
"keywords": [
Expand Down Expand Up @@ -31,7 +31,6 @@
"homepage": "https://github.com/segmentio/analytics.js-core#readme",
"dependencies": {
"@ndhoule/defaults": "^2.0.1",
"@ndhoule/includes": "^2.0.1",
"@segment/canonical": "^1.0.0",
"@segment/cookie": "^1.1.5",
"@segment/is-meta": "^1.0.0",
Expand All @@ -54,6 +53,7 @@
"is": "^3.1.0",
"lodash.assignin": "^4.2.0",
"lodash.clonedeep": "^4.5.0",
"lodash.includes": "^4.3.0",
"lodash.pick": "^4.4.0",
"new-date": "^1.0.0",
"next-tick": "^0.2.2",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6049,6 +6049,11 @@ lodash.has@^4.5.2:
resolved "https://registry.yarnpkg.com/lodash.has/-/lodash.has-4.5.2.tgz#d19f4dc1095058cccbe2b0cdf4ee0fe4aa37c862"
integrity sha1-0Z9NwQlQWMzL4rDN9O4P5Ko3yGI=

lodash.includes@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/lodash.includes/-/lodash.includes-4.3.0.tgz#60bb98a87cb923c68ca1e51325483314849f553f"
integrity sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8=

lodash.isarray@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-4.0.0.tgz#2aca496b28c4ca6d726715313590c02e6ea34403"
Expand Down