Version 1
[yaffs-website] / node_modules / uncss / node_modules / lodash / wrapperLodash.js
1 var LazyWrapper = require('./internal/LazyWrapper'),
2     LodashWrapper = require('./internal/LodashWrapper'),
3     baseLodash = require('./internal/baseLodash'),
4     isArray = require('./isArray'),
5     isObjectLike = require('./isObjectLike'),
6     wrapperClone = require('./internal/wrapperClone');
7
8 /** Used for built-in method references. */
9 var objectProto = global.Object.prototype;
10
11 /** Used to check objects for own properties. */
12 var hasOwnProperty = objectProto.hasOwnProperty;
13
14 /**
15  * Creates a `lodash` object which wraps `value` to enable implicit method
16  * chaining. Methods that operate on and return arrays, collections, and
17  * functions can be chained together. Methods that retrieve a single value or
18  * may return a primitive value will automatically end the chain sequence and
19  * return the unwrapped value. Otherwise, the value must be unwrapped with
20  * `_#value`.
21  *
22  * Explicit chaining, which must be unwrapped with `_#value` in all cases,
23  * may be enabled using `_.chain`.
24  *
25  * The execution of chained methods is lazy, that is, it's deferred until
26  * `_#value` is implicitly or explicitly called.
27  *
28  * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
29  * fusion is an optimization to merge iteratee calls; this avoids the creation
30  * of intermediate arrays and can greatly reduce the number of iteratee executions.
31  * Sections of a chain sequence qualify for shortcut fusion if the section is
32  * applied to an array of at least two hundred elements and any iteratees
33  * accept only one argument. The heuristic for whether a section qualifies
34  * for shortcut fusion is subject to change.
35  *
36  * Chaining is supported in custom builds as long as the `_#value` method is
37  * directly or indirectly included in the build.
38  *
39  * In addition to lodash methods, wrappers have `Array` and `String` methods.
40  *
41  * The wrapper `Array` methods are:
42  * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
43  *
44  * The wrapper `String` methods are:
45  * `replace` and `split`
46  *
47  * The wrapper methods that support shortcut fusion are:
48  * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
49  * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
50  * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
51  *
52  * The chainable wrapper methods are:
53  * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`,
54  * `at`, `before`, `bind`, `bindAll`, `bindKey`, `chain`, `chunk`, `commit`,
55  * `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, `curry`,
56  * `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`,
57  * `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`,
58  * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flip`, `flow`,
59  * `flowRight`, `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial`,
60  * `intersection`, `intersectionBy`, `intersectionWith`, `invert`, `invokeMap`,
61  * `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`,
62  * `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, `method`,
63  * `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, `orderBy`,
64  * `over`, `overArgs`, `overEvery`, `overSome`, `partial`, `partialRight`,
65  * `partition`, `pick`, `pickBy`, `plant`, `property`, `propertyOf`, `pull`,
66  * `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`,
67  * `reject`, `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`,
68  * `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`,
69  * `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`,
70  * `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`,
71  * `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`,
72  * `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `without`,
73  * `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`, and `zipWith`
74  *
75  * The wrapper methods that are **not** chainable by default are:
76  * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
77  * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`,
78  * `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
79  * `findLast`, `findLastIndex`, `findLastKey`, `floor`, `forEach`, `forEachRight`,
80  * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
81  * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
82  * `isArguments`, `isArray`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`,
83  * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`,
84  * `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMatch`, `isMatchWith`,
85  * `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`, `isObject`, `isObjectLike`,
86  * `isPlainObject`, `isRegExp`, `isSafeInteger`, `isString`, `isUndefined`,
87  * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`,
88  * `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `min`, `minBy`,
89  * `noConflict`, `noop`, `now`, `pad`, `padEnd`, `padStart`, `parseInt`,
90  * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`,
91  * `runInContext`, `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`,
92  * `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`, `startCase`,
93  * `startsWith`, `subtract`, `sum`, `sumBy`, `template`, `times`, `toLower`,
94  * `toInteger`, `toLength`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`,
95  * `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`,
96  * `upperCase`, `upperFirst`, `value`, and `words`
97  *
98  * @name _
99  * @constructor
100  * @category Seq
101  * @param {*} value The value to wrap in a `lodash` instance.
102  * @returns {Object} Returns the new `lodash` wrapper instance.
103  * @example
104  *
105  * function square(n) {
106  *   return n * n;
107  * }
108  *
109  * var wrapped = _([1, 2, 3]);
110  *
111  * // returns an unwrapped value
112  * wrapped.reduce(_.add);
113  * // => 6
114  *
115  * // returns a wrapped value
116  * var squares = wrapped.map(square);
117  *
118  * _.isArray(squares);
119  * // => false
120  *
121  * _.isArray(squares.value());
122  * // => true
123  */
124 function lodash(value) {
125   if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
126     if (value instanceof LodashWrapper) {
127       return value;
128     }
129     if (hasOwnProperty.call(value, '__wrapped__')) {
130       return wrapperClone(value);
131     }
132   }
133   return new LodashWrapper(value);
134 }
135
136 // Ensure wrappers are instances of `baseLodash`.
137 lodash.prototype = baseLodash.prototype;
138
139 module.exports = lodash;