underscore-source 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  module Underscore
2
2
  module Source
3
- VERSION = "0.5.1"
3
+ VERSION = "0.5.2"
4
4
  end
5
5
  end
@@ -8,7 +8,7 @@
8
8
 
9
9
  (function() {
10
10
 
11
- /*------------------------- Baseline setup ---------------------------------*/
11
+ // ------------------------- Baseline setup ---------------------------------
12
12
 
13
13
  // Establish the root object, "window" in the browser, or "global" on the server.
14
14
  var root = this;
@@ -38,9 +38,9 @@
38
38
  propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
39
39
 
40
40
  // Current version.
41
- _.VERSION = '0.5.1';
41
+ _.VERSION = '0.5.2';
42
42
 
43
- /*------------------------ Collection Functions: ---------------------------*/
43
+ // ------------------------ Collection Functions: ---------------------------
44
44
 
45
45
  // The cornerstone, an each implementation.
46
46
  // Handles objects implementing forEach, arrays, and raw objects.
@@ -234,7 +234,7 @@
234
234
  return _.toArray(obj).length;
235
235
  };
236
236
 
237
- /*-------------------------- Array Functions: ------------------------------*/
237
+ // -------------------------- Array Functions: ------------------------------
238
238
 
239
239
  // Get the first element of an array. Passing "n" will return the first N
240
240
  // values in the array. Aliased as "head". The "guard" check allows it to work
@@ -340,7 +340,7 @@
340
340
  }
341
341
  };
342
342
 
343
- /* ----------------------- Function Functions: -----------------------------*/
343
+ // ----------------------- Function Functions: ------------------------------
344
344
 
345
345
  // Create a function bound to a given object (assigning 'this', and arguments,
346
346
  // optionally). Binding with arguments is also known as 'curry'.
@@ -396,7 +396,7 @@
396
396
  };
397
397
  };
398
398
 
399
- /* ------------------------- Object Functions: ---------------------------- */
399
+ // ------------------------- Object Functions: ------------------------------
400
400
 
401
401
  // Retrieve the names of an object's properties.
402
402
  _.keys = function(obj) {
@@ -428,6 +428,13 @@
428
428
  return _.extend({}, obj);
429
429
  };
430
430
 
431
+ // Invokes interceptor with the obj, and then returns obj.
432
+ // The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
433
+ _.tap = function(obj, interceptor) {
434
+ interceptor(obj);
435
+ return obj;
436
+ };
437
+
431
438
  // Perform a deep comparison to check if two objects are equal.
432
439
  _.isEqual = function(a, b) {
433
440
  // Check object identity.
@@ -474,11 +481,41 @@
474
481
  return !!(obj && obj.nodeType == 1);
475
482
  };
476
483
 
484
+ // Is a given value an array?
485
+ _.isArray = function(obj) {
486
+ return obj && obj.concat && obj.unshift;
487
+ };
488
+
477
489
  // Is a given variable an arguments object?
478
490
  _.isArguments = function(obj) {
479
491
  return obj && _.isNumber(obj.length) && !_.isArray(obj) && !propertyIsEnumerable.call(obj, 'length');
480
492
  };
481
493
 
494
+ // Is a given value a function?
495
+ _.isFunction = function(obj) {
496
+ return obj && obj.constructor && obj.call && obj.apply;
497
+ };
498
+
499
+ // Is a given value a string?
500
+ _.isString = function(obj) {
501
+ return obj === '' || (obj && obj.charCodeAt && obj.substr);
502
+ };
503
+
504
+ // Is a given value a number?
505
+ _.isNumber = function(obj) {
506
+ return toString.call(obj) === '[object Number]';
507
+ };
508
+
509
+ // Is a given value a date?
510
+ _.isDate = function(obj) {
511
+ return obj && obj.getTimezoneOffset && obj.setUTCFullYear;
512
+ };
513
+
514
+ // Is the given value a regular expression?
515
+ _.isRegExp = function(obj) {
516
+ return obj && obj.test && obj.exec && (obj.ignoreCase || obj.ignoreCase === false);
517
+ };
518
+
482
519
  // Is the given value NaN -- this one is interesting. NaN != NaN, and
483
520
  // isNaN(undefined) == true, so we make sure it's a number first.
484
521
  _.isNaN = function(obj) {
@@ -495,17 +532,7 @@
495
532
  return typeof obj == 'undefined';
496
533
  };
497
534
 
498
- // Define the isArray, isDate, isFunction, isNumber, isRegExp, and isString
499
- // functions based on their toString identifiers.
500
- var types = ['Array', 'Date', 'Function', 'Number', 'RegExp', 'String'];
501
- for (var i=0, l=types.length; i<l; i++) {
502
- (function() {
503
- var identifier = '[object ' + types[i] + ']';
504
- _['is' + types[i]] = function(obj) { return toString.call(obj) == identifier; };
505
- })();
506
- }
507
-
508
- /* -------------------------- Utility Functions: -------------------------- */
535
+ // -------------------------- Utility Functions: ----------------------------
509
536
 
510
537
  // Run Underscore.js in noConflict mode, returning the '_' variable to its
511
538
  // previous owner. Returns a reference to the Underscore object.
@@ -550,7 +577,7 @@
550
577
  return data ? fn(data) : fn;
551
578
  };
552
579
 
553
- /*------------------------------- Aliases ----------------------------------*/
580
+ // ------------------------------- Aliases ----------------------------------
554
581
 
555
582
  _.forEach = _.each;
556
583
  _.foldl = _.inject = _.reduce;
@@ -562,7 +589,7 @@
562
589
  _.tail = _.rest;
563
590
  _.methods = _.functions;
564
591
 
565
- /*------------------------ Setup the OOP Wrapper: --------------------------*/
592
+ // ------------------------ Setup the OOP Wrapper: --------------------------
566
593
 
567
594
  // Helper function to continue chaining intermediate results.
568
595
  var result = function(obj, chain) {
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: underscore-source
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.1
5
+ version: 0.5.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Daniel X. Moore