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

Commit 1e1b187

Browse files
author
Julio Farah
authored
Move third party dependencies ndhoule/map and ndhoule/each into ajs-core (#144)
* docs: add .nvmrc file * refactor: remove third party dependency map * docs: bump history * refactor: remove ndhoule/each dep * force build
1 parent 18eb947 commit 1e1b187

File tree

9 files changed

+557
-5
lines changed

9 files changed

+557
-5
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.17.0

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 3.13.1 / 2020-05-04
2+
3+
- refactor: remove third party dependency ndhoule/each
4+
- refactor: remove third party dependency ndhoule/map
5+
16
# 3.13.0 / 2020-05-04
27

38
- refactor: remove third party dependency ndhoule/clone

lib/analytics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var cookie = require('./cookie');
2323
var metrics = require('./metrics');
2424
var debug = require('debug');
2525
var defaults = require('@ndhoule/defaults');
26-
var each = require('@ndhoule/each');
26+
var each = require('./utils/each');
2727
var foldl = require('@ndhoule/foldl');
2828
var group = require('./group');
2929
var is = require('is');

lib/normalize.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
var debug = require('debug')('analytics.js:normalize');
88
var defaults = require('@ndhoule/defaults');
9-
var each = require('@ndhoule/each');
9+
var each = require('./utils/each');
1010
var includes = require('@ndhoule/includes');
11-
var map = require('@ndhoule/map');
11+
var map = require('./utils/map');
1212
var type = require('component-type');
1313
var uuid = require('uuid/v4');
1414
var md5 = require('spark-md5').hash;

lib/utils/each.js

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
'use strict';
2+
3+
/*
4+
* The MIT License (MIT)
5+
* Copyright (c) 2015 Nathan Houle
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
24+
/*
25+
* Module dependencies.
26+
*/
27+
28+
var keys = require('@ndhoule/keys');
29+
30+
var objToString = Object.prototype.toString;
31+
32+
/**
33+
* Tests if a value is a number.
34+
*
35+
* @name isNumber
36+
* @api private
37+
* @param {*} val The value to test.
38+
* @return {boolean} Returns `true` if `val` is a number, otherwise `false`.
39+
*/
40+
41+
var isNumber = function isNumber(val) {
42+
var type = typeof val;
43+
return (
44+
type === 'number' ||
45+
(type === 'object' && objToString.call(val) === '[object Number]')
46+
);
47+
};
48+
49+
/**
50+
* Tests if a value is an array.
51+
*
52+
* @name isArray
53+
* @api private
54+
* @param {*} val The value to test.
55+
* @return {boolean} Returns `true` if the value is an array, otherwise `false`.
56+
*/
57+
58+
var isArray =
59+
typeof Array.isArray === 'function'
60+
? Array.isArray
61+
: function isArray(val) {
62+
return objToString.call(val) === '[object Array]';
63+
};
64+
65+
/**
66+
* Tests if a value is array-like. Array-like means the value is not a function and has a numeric
67+
* `.length` property.
68+
*
69+
* @name isArrayLike
70+
* @api private
71+
* @param {*} val
72+
* @return {boolean}
73+
*/
74+
75+
var isArrayLike = function isArrayLike(val) {
76+
return (
77+
val != null &&
78+
(isArray(val) || (val !== 'function' && isNumber(val.length)))
79+
);
80+
};
81+
82+
/**
83+
* Internal implementation of `each`. Works on arrays and array-like data structures.
84+
*
85+
* @name arrayEach
86+
* @api private
87+
* @param {Function(value, key, collection)} iterator The function to invoke per iteration.
88+
* @param {Array} array The array(-like) structure to iterate over.
89+
* @return {undefined}
90+
*/
91+
var arrayEach = function arrayEach(iterator, array) {
92+
for (var i = 0; i < array.length; i += 1) {
93+
// Break iteration early if `iterator` returns `false`
94+
if (iterator(array[i], i, array) === false) {
95+
break;
96+
}
97+
}
98+
};
99+
100+
/**
101+
* Internal implementation of `each`. Works on objects.
102+
*
103+
* @name baseEach
104+
* @api private
105+
* @param {Function(value, key, collection)} iterator The function to invoke per iteration.
106+
* @param {Object} object The object to iterate over.
107+
* @return {undefined}
108+
*/
109+
var baseEach = function baseEach(iterator, object) {
110+
var ks = keys(object);
111+
112+
for (var i = 0; i < ks.length; i += 1) {
113+
// Break iteration early if `iterator` returns `false`
114+
if (iterator(object[ks[i]], ks[i], object) === false) {
115+
break;
116+
}
117+
}
118+
};
119+
120+
/**
121+
* Iterate over an input collection, invoking an `iterator` function for each element in the
122+
* collection and passing to it three arguments: `(value, index, collection)`. The `iterator`
123+
* function can end iteration early by returning `false`.
124+
*
125+
* @name each
126+
* @api public
127+
* @param {Function(value, key, collection)} iterator The function to invoke per iteration.
128+
* @param {Array|Object|string} collection The collection to iterate over.
129+
* @return {undefined} Because `each` is run only for side effects, always returns `undefined`.
130+
* @example
131+
* var log = console.log.bind(console);
132+
*
133+
* each(log, ['a', 'b', 'c']);
134+
* //-> 'a', 0, ['a', 'b', 'c']
135+
* //-> 'b', 1, ['a', 'b', 'c']
136+
* //-> 'c', 2, ['a', 'b', 'c']
137+
* //=> undefined
138+
*
139+
* each(log, 'tim');
140+
* //-> 't', 2, 'tim'
141+
* //-> 'i', 1, 'tim'
142+
* //-> 'm', 0, 'tim'
143+
* //=> undefined
144+
*
145+
* // Note: Iteration order not guaranteed across environments
146+
* each(log, { name: 'tim', occupation: 'enchanter' });
147+
* //-> 'tim', 'name', { name: 'tim', occupation: 'enchanter' }
148+
* //-> 'enchanter', 'occupation', { name: 'tim', occupation: 'enchanter' }
149+
* //=> undefined
150+
*/
151+
var each = function each(iterator, collection) {
152+
return (isArrayLike(collection) ? arrayEach : baseEach).call(
153+
this,
154+
iterator,
155+
collection
156+
);
157+
};
158+
159+
/*
160+
* Exports.
161+
*/
162+
163+
module.exports = each;

lib/utils/map.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use strict';
2+
3+
/*
4+
* The MIT License (MIT)
5+
* Copyright (c) 2015 Nathan Houle
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
24+
/*
25+
* Module dependencies.
26+
*/
27+
28+
var each = require('./each');
29+
30+
/**
31+
* Produce a new array by passing each value in the input `collection` through a transformative
32+
* `iterator` function. The `iterator` function is passed three arguments:
33+
* `(value, index, collection)`.
34+
*
35+
* @name map
36+
* @api public
37+
* @param {Function} iterator The transformer function to invoke per iteration.
38+
* @param {Array} collection The collection to iterate over.
39+
* @return {Array} A new array containing the results of each `iterator` invocation.
40+
* @example
41+
* var square = function(x) { return x * x; };
42+
*
43+
* map(square, [1, 2, 3]);
44+
* //=> [1, 4, 9]
45+
*/
46+
var map = function map(iterator, collection) {
47+
if (typeof iterator !== 'function') {
48+
throw new TypeError(
49+
'Expected a function but received a ' + typeof iterator
50+
);
51+
}
52+
53+
var result = [];
54+
55+
each(function(val, i, collection) {
56+
result.push(iterator(val, i, collection));
57+
}, collection);
58+
59+
return result;
60+
};
61+
62+
/*
63+
* Exports.
64+
*/
65+
66+
module.exports = map;

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@
3030
"homepage": "https://github.com/segmentio/analytics.js-core#readme",
3131
"dependencies": {
3232
"@ndhoule/defaults": "^2.0.1",
33-
"@ndhoule/each": "^2.0.1",
3433
"@ndhoule/extend": "^2.0.0",
3534
"@ndhoule/foldl": "^2.0.1",
3635
"@ndhoule/includes": "^2.0.1",
3736
"@ndhoule/keys": "^2.0.0",
38-
"@ndhoule/map": "^2.0.1",
3937
"@ndhoule/pick": "^2.0.0",
4038
"@segment/canonical": "^1.0.0",
4139
"@segment/cookie": "^1.1.5",

0 commit comments

Comments
 (0)