Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chopping Underscore into lots of tiny modules #2849

Merged
merged 26 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bff2d2a
Modularize (split the index module into lots of tiny modules)
jgonggrijp Mar 30, 2020
21e0271
Fix the circular imports
jgonggrijp Mar 30, 2020
3aa35b5
Merge latest changes from master
jgonggrijp Apr 14, 2020
5e541a0
Merge latest changes from 'master'
jgonggrijp May 6, 2020
4a90899
Replace uglify-js by terser
jgonggrijp May 7, 2020
bfd1828
Upgrade Rollup
jgonggrijp May 8, 2020
6f5b07f
Run `npm install -D docco` again
jgonggrijp May 8, 2020
97eabb9
Create a monolithic ESM bundle for client side usage
jgonggrijp May 7, 2020
ed8d5b1
Create modular AMD and CommonJS builds
jgonggrijp May 8, 2020
0dc6947
Add a modular, hyperlinked version of the annotated source
jgonggrijp May 8, 2020
4fd0386
Fix an outdated module reference
jgonggrijp May 8, 2020
9e3117e
Polish the literate source
jgonggrijp May 8, 2020
cb5f6fc
Add missing .js extensions in imports
jgonggrijp Jun 13, 2020
8d38be6
Optimize the import order for a more natural single read
jgonggrijp Jun 19, 2020
99b6969
Make the comments more self-sufficient
jgonggrijp Jun 19, 2020
109f36d
It is no longer true that _.bind defers to ES5 Function.prototype.bind
jgonggrijp Jun 19, 2020
0ee7b22
Consistently write "pass a truth test" in predicate-based functions
jgonggrijp Jun 19, 2020
2b9741f
Polish
jgonggrijp Jun 19, 2020
eacfc4d
Support anonymous imports in the linked Docco rendering
jgonggrijp Jun 19, 2020
817a58b
Move _.pick next to _.omit
jgonggrijp Jun 22, 2020
0aaa374
Revisit the sections in the index.js
jgonggrijp Jun 22, 2020
803795e
Fix the footer comments in the monolithic bundles
jgonggrijp Jun 22, 2020
f7511d2
Wrap the exports in the index.js
jgonggrijp Jun 22, 2020
443bcc0
Consistently prefix references to public functions with _.
jgonggrijp Jun 22, 2020
dcd63f2
Small words tweaks to index.js
jashkenas Jun 22, 2020
a9243da
Merge pull request #1 from jashkenas/modularized-words
jgonggrijp Jun 23, 2020
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
Prev Previous commit
Next Next commit
Polish
  • Loading branch information
jgonggrijp committed Jun 19, 2020
commit 2b9741ffeb207648888f929a14331311a0945bec
2 changes: 1 addition & 1 deletion modules/debounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import restArguments from './restArguments.js';
import delay from './delay.js';

// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// be triggered. The function will be triggered after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
export default function debounce(func, wait, immediate) {
Expand Down
3 changes: 2 additions & 1 deletion modules/extendOwn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import createAssigner from './_createAssigner.js';
import keys from './keys.js';

// Assigns a given object with all the own properties in the passed-in object(s).
// Assigns a given object with all the own properties in the passed-in
// object(s).
// (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
export default createAssigner(keys);
2 changes: 1 addition & 1 deletion modules/index-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { mixin } from './index.js';

// Add all of the Underscore functions to the wrapper object.
var _ = mixin(allExports);
// Legacy Node.js API
// Legacy Node.js API.
_._ = _;
// Export the Underscore API.
export default _;
4 changes: 2 additions & 2 deletions modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export { VERSION } from './_setup.js';
export { default as restArguments } from './restArguments.js';

// Object Functions (except for findKey and omit).
// Object Functions (except for `findKey` and `omit`).
jgonggrijp marked this conversation as resolved.
Show resolved Hide resolved
export { default as isObject } from './isObject.js';
export { default as isNull } from './isNull.js';
export { default as isUndefined } from './isUndefined.js';
Expand Down Expand Up @@ -95,7 +95,7 @@ export { default as lastIndexOf } from './lastIndexOf.js';
export { default as find, default as detect } from './find.js';
export { default as findWhere } from './findWhere.js';

// Collection Functions (plus omit).
// Collection Functions (plus `omit`).
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps: "Collection functions work on both arrays and objects" (and Maps and Sets if/when we choose to support them)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have specified what I was unhappy about. I'm fine with the "Collection Functions" part but not with the "(plus omit)" part. I felt compelled to append that because omit is out of place here, but it feels ugly.

I do like your suggestions to clarify the section titles a bit, though. I'll follow up on them.

export { default as each, default as forEach } from './each.js';
export { default as map, default as collect } from './map.js';
export { default as reduce, default as foldl, default as inject } from './reduce.js';
Expand Down
1 change: 1 addition & 0 deletions modules/isArguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import tagTester from './_tagTester.js';
import has from './_has.js';

var isArguments = tagTester('Arguments');

// Define a fallback version of the method in browsers (ahem, IE < 9), where
// there isn't any inspectable "Arguments" type.
(function() {
Expand Down
2 changes: 1 addition & 1 deletion modules/isArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { nativeIsArray } from './_setup.js';
import tagTester from './_tagTester.js';

// Is a given value an array?
// Delegates to ECMA5's native Array.isArray
// Delegates to ECMA5's native `Array.isArray`.
export default nativeIsArray || tagTester('Array');
5 changes: 3 additions & 2 deletions modules/isFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import tagTester from './_tagTester.js';
import { root } from './_setup.js';

var isFunction = tagTester('Function');
// Optimize `isFunction` if appropriate. Work around some typeof bugs in old v8,
// IE 11 (#1621), Safari 8 (#1929), and PhantomJS (#2236).

// Optimize `isFunction` if appropriate. Work around some `typeof` bugs in old
// v8, IE 11 (#1621), Safari 8 (#1929), and PhantomJS (#2236).
var nodelist = root.document && root.document.childNodes;
if (typeof /./ != 'function' && typeof Int8Array != 'object' && typeof nodelist != 'function') {
isFunction = function(obj) {
Expand Down
3 changes: 2 additions & 1 deletion modules/isTypedArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var typedArrayPattern = /\[object ((I|Ui)nt(8|16|32)|Float(32|64)|Uint8Clamped|B
function isTypedArray(obj) {
// `ArrayBuffer.isView` is the most future-proof, so use it when available.
// Otherwise, fall back on the above regular expression.
return nativeIsView ? (nativeIsView(obj) && !isDataView(obj)) : isBufferLike(obj) && typedArrayPattern.test(toString.call(obj));
return nativeIsView ? (nativeIsView(obj) && !isDataView(obj)) :
isBufferLike(obj) && typedArrayPattern.test(toString.call(obj));
}

export default supportsArrayBuffer ? isTypedArray : constant(false);
4 changes: 2 additions & 2 deletions modules/mapObject.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import cb from './_cb.js';
import keys from './keys.js';

// Returns the results of applying the iteratee to each element of the object.
// In contrast to map it returns an object.
// Returns the results of applying the `iteratee` to each element of `obj`.
// In contrast to `map` it returns an object.
export default function mapObject(obj, iteratee, context) {
iteratee = cb(iteratee, context);
var _keys = keys(obj),
Expand Down
2 changes: 1 addition & 1 deletion modules/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import getLength from './_getLength.js';

// Converts lists into objects. Pass either a single array of `[key, value]`
// pairs, or two parallel arrays of the same length -- one of keys, and one of
// the corresponding values. Passing by pairs is the reverse of pairs.
// the corresponding values. Passing by pairs is the reverse of `pairs`.
export default function object(list, values) {
var result = {};
for (var i = 0, length = getLength(list); i < length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion modules/partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import executeBound from './_executeBound.js';
import _ from './underscore.js';

// Partially apply a function by creating a version that has had some of its
// arguments pre-filled, without changing its dynamic `this` context. _ acts
// arguments pre-filled, without changing its dynamic `this` context. `_` acts
// as a placeholder by default, allowing any combination of arguments to be
// pre-filled. Set `partial.placeholder` for a custom placeholder argument.
var partial = restArguments(function(func, boundArgs) {
Expand Down
2 changes: 1 addition & 1 deletion modules/property.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import shallowProperty from './_shallowProperty.js';
import deepGet from './_deepGet.js';

// Creates a function that, when passed an object, will traverse that object’s
// properties down the given `path`, specified as an array of keys or indexes.
// properties down the given `path`, specified as an array of keys or indices.
export default function property(path) {
if (!isArray(path)) {
return shallowProperty(path);
Expand Down
2 changes: 1 addition & 1 deletion modules/random.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Return a random integer between min and max (inclusive).
// Return a random integer between `min` and `max` (inclusive).
export default function random(min, max) {
if (max == null) {
max = min;
Expand Down
6 changes: 3 additions & 3 deletions modules/rest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { slice } from './_setup.js';

// Returns everything but the first entry of the array. Especially useful on
// the arguments object. Passing an **n** will return the rest N values in the
// array.
// Returns everything but the first entry of the `array`. Especially useful on
// the `arguments` object. Passing an **n** will return the rest N values in the
// `array`.
export default function rest(array, n, guard) {
return slice.call(array, n == null || guard ? 1 : n);
}
2 changes: 1 addition & 1 deletion modules/size.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import isArrayLike from './_isArrayLike.js';
import keys from './keys.js';

// Return the number of elements in an object.
// Return the number of elements in a collection.
export default function size(obj) {
if (obj == null) return 0;
return isArrayLike(obj) ? obj.length : keys(obj).length;
Expand Down
2 changes: 1 addition & 1 deletion modules/tap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Invokes `interceptor` with the `obj`, and then returns `obj`.
// Invokes `interceptor` with the `obj` and then returns `obj`.
// The primary purpose of this method is to "tap into" a method chain, in
// order to perform operations on intermediate results within the chain.
export default function tap(obj, interceptor) {
Expand Down
2 changes: 1 addition & 1 deletion modules/templateSettings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from './underscore.js';

// By default, Underscore uses ERB-style template delimiters, change the
// By default, Underscore uses ERB-style template delimiters. Change the
// following template settings to use alternative delimiters.
export default _.templateSettings = {
evaluate: /<%([\s\S]+?)%>/g,
Expand Down
4 changes: 2 additions & 2 deletions modules/toArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import map from './map.js';
import identity from './identity.js';
import values from './values.js';

var reStrSymbol = /[^\ud800-\udfff]|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;
// Safely create a real, live array from anything iterable.
var reStrSymbol = /[^\ud800-\udfff]|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;
export default function toArray(obj) {
if (!obj) return [];
if (isArray(obj)) return slice.call(obj);
if (isString(obj)) {
// Keep surrogate pair characters together
// Keep surrogate pair characters together.
return obj.match(reStrSymbol);
}
if (isArrayLike(obj)) return map(obj, identity);
Expand Down
6 changes: 3 additions & 3 deletions modules/underscore-oop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import each from './each.js';
import { ArrayProto } from './_setup.js';
import chainResult from './_chainResult.js';

// Add all mutator Array functions to the wrapper.
// Add all mutator `Array` functions to the wrapper.
each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
var method = ArrayProto[name];
_.prototype[name] = function() {
Expand All @@ -18,7 +18,7 @@ each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(
};
});

// Add all accessor Array functions to the wrapper.
// Add all accessor `Array` functions to the wrapper.
each(['concat', 'join', 'slice'], function(name) {
var method = ArrayProto[name];
_.prototype[name] = function() {
Expand All @@ -33,7 +33,7 @@ _.prototype.value = function() {
return this._wrapped;
};

// Provide unwrapping proxy for some methods used in engine operations
// Provide unwrapping proxies for some methods used in engine operations
// such as arithmetic and JSON stringification.
_.prototype.valueOf = _.prototype.toJSON = _.prototype.value;

Expand Down
52 changes: 28 additions & 24 deletions underscore-esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion underscore-esm.js.map

Large diffs are not rendered by default.

Loading