lodash-ckeditor.js 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  1. /**
  2. * @license
  3. * Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/>
  4. * Build: `lodash modern exports="amd" include="clone,extend,isPlainObject,isObject" --debug --output src/lib/lodash/lodash-ckeditor.js`
  5. * Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/>
  6. * Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE>
  7. * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  8. * Available under MIT license <http://lodash.com/license>
  9. */
  10. ;(function() {
  11. /** Used to pool arrays and objects used internally */
  12. var arrayPool = [];
  13. /** Used as the max size of the `arrayPool` and `objectPool` */
  14. var maxPoolSize = 40;
  15. /** Used to match regexp flags from their coerced string values */
  16. var reFlags = /\w*$/;
  17. /** Used to detected named functions */
  18. var reFuncName = /^\s*function[ \n\r\t]+\w/;
  19. /** Used to detect functions containing a `this` reference */
  20. var reThis = /\bthis\b/;
  21. /** `Object#toString` result shortcuts */
  22. var argsClass = '[object Arguments]',
  23. arrayClass = '[object Array]',
  24. boolClass = '[object Boolean]',
  25. dateClass = '[object Date]',
  26. funcClass = '[object Function]',
  27. numberClass = '[object Number]',
  28. objectClass = '[object Object]',
  29. regexpClass = '[object RegExp]',
  30. stringClass = '[object String]';
  31. /** Used to identify object classifications that `_.clone` supports */
  32. var cloneableClasses = {};
  33. cloneableClasses[funcClass] = false;
  34. cloneableClasses[argsClass] = cloneableClasses[arrayClass] =
  35. cloneableClasses[boolClass] = cloneableClasses[dateClass] =
  36. cloneableClasses[numberClass] = cloneableClasses[objectClass] =
  37. cloneableClasses[regexpClass] = cloneableClasses[stringClass] = true;
  38. /** Used as the property descriptor for `__bindData__` */
  39. var descriptor = {
  40. 'configurable': false,
  41. 'enumerable': false,
  42. 'value': null,
  43. 'writable': false
  44. };
  45. /** Used to determine if values are of the language type Object */
  46. var objectTypes = {
  47. 'boolean': false,
  48. 'function': true,
  49. 'object': true,
  50. 'number': false,
  51. 'string': false,
  52. 'undefined': false
  53. };
  54. /** Used as a reference to the global object */
  55. var root = (objectTypes[typeof window] && window) || this;
  56. /** Detect free variable `global` from Node.js or Browserified code and use it as `root` */
  57. var freeGlobal = objectTypes[typeof global] && global;
  58. if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal)) {
  59. root = freeGlobal;
  60. }
  61. /*--------------------------------------------------------------------------*/
  62. /**
  63. * Gets an array from the array pool or creates a new one if the pool is empty.
  64. *
  65. * @private
  66. * @returns {Array} The array from the pool.
  67. */
  68. function getArray() {
  69. return arrayPool.pop() || [];
  70. }
  71. /**
  72. * Releases the given array back to the array pool.
  73. *
  74. * @private
  75. * @param {Array} [array] The array to release.
  76. */
  77. function releaseArray(array) {
  78. array.length = 0;
  79. if (arrayPool.length < maxPoolSize) {
  80. arrayPool.push(array);
  81. }
  82. }
  83. /**
  84. * Slices the `collection` from the `start` index up to, but not including,
  85. * the `end` index.
  86. *
  87. * Note: This function is used instead of `Array#slice` to support node lists
  88. * in IE < 9 and to ensure dense arrays are returned.
  89. *
  90. * @private
  91. * @param {Array|Object|string} collection The collection to slice.
  92. * @param {number} start The start index.
  93. * @param {number} end The end index.
  94. * @returns {Array} Returns the new array.
  95. */
  96. function slice(array, start, end) {
  97. start || (start = 0);
  98. if (typeof end == 'undefined') {
  99. end = array ? array.length : 0;
  100. }
  101. var index = -1,
  102. length = end - start || 0,
  103. result = Array(length < 0 ? 0 : length);
  104. while (++index < length) {
  105. result[index] = array[start + index];
  106. }
  107. return result;
  108. }
  109. /*--------------------------------------------------------------------------*/
  110. /**
  111. * Used for `Array` method references.
  112. *
  113. * Normally `Array.prototype` would suffice, however, using an array literal
  114. * avoids issues in Narwhal.
  115. */
  116. var arrayRef = [];
  117. /** Used for native method references */
  118. var objectProto = Object.prototype;
  119. /** Used to resolve the internal [[Class]] of values */
  120. var toString = objectProto.toString;
  121. /** Used to detect if a method is native */
  122. var reNative = RegExp('^' +
  123. String(toString)
  124. .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
  125. .replace(/toString| for [^\]]+/g, '.*?') + '$'
  126. );
  127. /** Native method shortcuts */
  128. var fnToString = Function.prototype.toString,
  129. getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
  130. hasOwnProperty = objectProto.hasOwnProperty,
  131. push = arrayRef.push,
  132. unshift = arrayRef.unshift;
  133. /** Used to set meta data on functions */
  134. var defineProperty = (function() {
  135. // IE 8 only accepts DOM elements
  136. try {
  137. var o = {},
  138. func = isNative(func = Object.defineProperty) && func,
  139. result = func(o, o, o) && func;
  140. } catch(e) { }
  141. return result;
  142. }());
  143. /* Native method shortcuts for methods with the same name as other `lodash` methods */
  144. var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
  145. nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
  146. nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys;
  147. /** Used to lookup a built-in constructor by [[Class]] */
  148. var ctorByClass = {};
  149. ctorByClass[arrayClass] = Array;
  150. ctorByClass[boolClass] = Boolean;
  151. ctorByClass[dateClass] = Date;
  152. ctorByClass[funcClass] = Function;
  153. ctorByClass[objectClass] = Object;
  154. ctorByClass[numberClass] = Number;
  155. ctorByClass[regexpClass] = RegExp;
  156. ctorByClass[stringClass] = String;
  157. /*--------------------------------------------------------------------------*/
  158. /**
  159. * Creates a `lodash` object which wraps the given value to enable intuitive
  160. * method chaining.
  161. *
  162. * In addition to Lo-Dash methods, wrappers also have the following `Array` methods:
  163. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
  164. * and `unshift`
  165. *
  166. * Chaining is supported in custom builds as long as the `value` method is
  167. * implicitly or explicitly included in the build.
  168. *
  169. * The chainable wrapper functions are:
  170. * `after`, `assign`, `bind`, `bindAll`, `bindKey`, `chain`, `compact`,
  171. * `compose`, `concat`, `countBy`, `create`, `createCallback`, `curry`,
  172. * `debounce`, `defaults`, `defer`, `delay`, `difference`, `filter`, `flatten`,
  173. * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
  174. * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
  175. * `invoke`, `keys`, `map`, `max`, `memoize`, `merge`, `min`, `object`, `omit`,
  176. * `once`, `pairs`, `partial`, `partialRight`, `pick`, `pluck`, `pull`, `push`,
  177. * `range`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`,
  178. * `sortBy`, `splice`, `tap`, `throttle`, `times`, `toArray`, `transform`,
  179. * `union`, `uniq`, `unshift`, `unzip`, `values`, `where`, `without`, `wrap`,
  180. * and `zip`
  181. *
  182. * The non-chainable wrapper functions are:
  183. * `clone`, `cloneDeep`, `contains`, `escape`, `every`, `find`, `findIndex`,
  184. * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `has`, `identity`,
  185. * `indexOf`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
  186. * `isEmpty`, `isEqual`, `isFinite`, `isFunction`, `isNaN`, `isNull`, `isNumber`,
  187. * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `join`,
  188. * `lastIndexOf`, `mixin`, `noConflict`, `parseInt`, `pop`, `random`, `reduce`,
  189. * `reduceRight`, `result`, `shift`, `size`, `some`, `sortedIndex`, `runInContext`,
  190. * `template`, `unescape`, `uniqueId`, and `value`
  191. *
  192. * The wrapper functions `first` and `last` return wrapped values when `n` is
  193. * provided, otherwise they return unwrapped values.
  194. *
  195. * Explicit chaining can be enabled by using the `_.chain` method.
  196. *
  197. * @name _
  198. * @constructor
  199. * @category Chaining
  200. * @param {*} value The value to wrap in a `lodash` instance.
  201. * @returns {Object} Returns a `lodash` instance.
  202. * @example
  203. *
  204. * var wrapped = _([1, 2, 3]);
  205. *
  206. * // returns an unwrapped value
  207. * wrapped.reduce(function(sum, num) {
  208. * return sum + num;
  209. * });
  210. * // => 6
  211. *
  212. * // returns a wrapped value
  213. * var squares = wrapped.map(function(num) {
  214. * return num * num;
  215. * });
  216. *
  217. * _.isArray(squares);
  218. * // => false
  219. *
  220. * _.isArray(squares.value());
  221. * // => true
  222. */
  223. function lodash() {
  224. // no operation performed
  225. }
  226. /**
  227. * An object used to flag environments features.
  228. *
  229. * @static
  230. * @memberOf _
  231. * @type Object
  232. */
  233. var support = lodash.support = {};
  234. /**
  235. * Detect if functions can be decompiled by `Function#toString`
  236. * (all but PS3 and older Opera mobile browsers & avoided in Windows 8 apps).
  237. *
  238. * @memberOf _.support
  239. * @type boolean
  240. */
  241. support.funcDecomp = !isNative(root.WinRTError) && reThis.test(function() { return this; });
  242. /**
  243. * Detect if `Function#name` is supported (all but IE).
  244. *
  245. * @memberOf _.support
  246. * @type boolean
  247. */
  248. support.funcNames = typeof Function.name == 'string';
  249. /*--------------------------------------------------------------------------*/
  250. /**
  251. * The base implementation of `_.bind` that creates the bound function and
  252. * sets its meta data.
  253. *
  254. * @private
  255. * @param {Array} bindData The bind data array.
  256. * @returns {Function} Returns the new bound function.
  257. */
  258. function baseBind(bindData) {
  259. var func = bindData[0],
  260. partialArgs = bindData[2],
  261. thisArg = bindData[4];
  262. function bound() {
  263. // `Function#bind` spec
  264. // http://es5.github.io/#x15.3.4.5
  265. if (partialArgs) {
  266. // avoid `arguments` object deoptimizations by using `slice` instead
  267. // of `Array.prototype.slice.call` and not assigning `arguments` to a
  268. // variable as a ternary expression
  269. var args = slice(partialArgs);
  270. push.apply(args, arguments);
  271. }
  272. // mimic the constructor's `return` behavior
  273. // http://es5.github.io/#x13.2.2
  274. if (this instanceof bound) {
  275. // ensure `new bound` is an instance of `func`
  276. var thisBinding = baseCreate(func.prototype),
  277. result = func.apply(thisBinding, args || arguments);
  278. return isObject(result) ? result : thisBinding;
  279. }
  280. return func.apply(thisArg, args || arguments);
  281. }
  282. setBindData(bound, bindData);
  283. return bound;
  284. }
  285. /**
  286. * The base implementation of `_.clone` without argument juggling or support
  287. * for `thisArg` binding.
  288. *
  289. * @private
  290. * @param {*} value The value to clone.
  291. * @param {boolean} [isDeep=false] Specify a deep clone.
  292. * @param {Function} [callback] The function to customize cloning values.
  293. * @param {Array} [stackA=[]] Tracks traversed source objects.
  294. * @param {Array} [stackB=[]] Associates clones with source counterparts.
  295. * @returns {*} Returns the cloned value.
  296. */
  297. function baseClone(value, isDeep, callback, stackA, stackB) {
  298. if (callback) {
  299. var result = callback(value);
  300. if (typeof result != 'undefined') {
  301. return result;
  302. }
  303. }
  304. // inspect [[Class]]
  305. var isObj = isObject(value);
  306. if (isObj) {
  307. var className = toString.call(value);
  308. if (!cloneableClasses[className]) {
  309. return value;
  310. }
  311. var ctor = ctorByClass[className];
  312. switch (className) {
  313. case boolClass:
  314. case dateClass:
  315. return new ctor(+value);
  316. case numberClass:
  317. case stringClass:
  318. return new ctor(value);
  319. case regexpClass:
  320. result = ctor(value.source, reFlags.exec(value));
  321. result.lastIndex = value.lastIndex;
  322. return result;
  323. }
  324. } else {
  325. return value;
  326. }
  327. var isArr = isArray(value);
  328. if (isDeep) {
  329. // check for circular references and return corresponding clone
  330. var initedStack = !stackA;
  331. stackA || (stackA = getArray());
  332. stackB || (stackB = getArray());
  333. var length = stackA.length;
  334. while (length--) {
  335. if (stackA[length] == value) {
  336. return stackB[length];
  337. }
  338. }
  339. result = isArr ? ctor(value.length) : {};
  340. }
  341. else {
  342. result = isArr ? slice(value) : assign({}, value);
  343. }
  344. // add array properties assigned by `RegExp#exec`
  345. if (isArr) {
  346. if (hasOwnProperty.call(value, 'index')) {
  347. result.index = value.index;
  348. }
  349. if (hasOwnProperty.call(value, 'input')) {
  350. result.input = value.input;
  351. }
  352. }
  353. // exit for shallow clone
  354. if (!isDeep) {
  355. return result;
  356. }
  357. // add the source value to the stack of traversed objects
  358. // and associate it with its clone
  359. stackA.push(value);
  360. stackB.push(result);
  361. // recursively populate clone (susceptible to call stack limits)
  362. (isArr ? forEach : forOwn)(value, function(objValue, key) {
  363. result[key] = baseClone(objValue, isDeep, callback, stackA, stackB);
  364. });
  365. if (initedStack) {
  366. releaseArray(stackA);
  367. releaseArray(stackB);
  368. }
  369. return result;
  370. }
  371. /**
  372. * The base implementation of `_.create` without support for assigning
  373. * properties to the created object.
  374. *
  375. * @private
  376. * @param {Object} prototype The object to inherit from.
  377. * @returns {Object} Returns the new object.
  378. */
  379. function baseCreate(prototype, properties) {
  380. return isObject(prototype) ? nativeCreate(prototype) : {};
  381. }
  382. // fallback for browsers without `Object.create`
  383. if (!nativeCreate) {
  384. baseCreate = (function() {
  385. function Object() {}
  386. return function(prototype) {
  387. if (isObject(prototype)) {
  388. Object.prototype = prototype;
  389. var result = new Object;
  390. Object.prototype = null;
  391. }
  392. return result || root.Object();
  393. };
  394. }());
  395. }
  396. /**
  397. * The base implementation of `_.createCallback` without support for creating
  398. * "_.pluck" or "_.where" style callbacks.
  399. *
  400. * @private
  401. * @param {*} [func=identity] The value to convert to a callback.
  402. * @param {*} [thisArg] The `this` binding of the created callback.
  403. * @param {number} [argCount] The number of arguments the callback accepts.
  404. * @returns {Function} Returns a callback function.
  405. */
  406. function baseCreateCallback(func, thisArg, argCount) {
  407. if (typeof func != 'function') {
  408. return identity;
  409. }
  410. // exit early for no `thisArg` or already bound by `Function#bind`
  411. if (typeof thisArg == 'undefined' || !('prototype' in func)) {
  412. return func;
  413. }
  414. var bindData = func.__bindData__;
  415. if (typeof bindData == 'undefined') {
  416. if (support.funcNames) {
  417. bindData = !func.name;
  418. }
  419. bindData = bindData || !support.funcDecomp;
  420. if (!bindData) {
  421. var source = fnToString.call(func);
  422. if (!support.funcNames) {
  423. bindData = !reFuncName.test(source);
  424. }
  425. if (!bindData) {
  426. // checks if `func` references the `this` keyword and stores the result
  427. bindData = reThis.test(source);
  428. setBindData(func, bindData);
  429. }
  430. }
  431. }
  432. // exit early if there are no `this` references or `func` is bound
  433. if (bindData === false || (bindData !== true && bindData[1] & 1)) {
  434. return func;
  435. }
  436. switch (argCount) {
  437. case 1: return function(value) {
  438. return func.call(thisArg, value);
  439. };
  440. case 2: return function(a, b) {
  441. return func.call(thisArg, a, b);
  442. };
  443. case 3: return function(value, index, collection) {
  444. return func.call(thisArg, value, index, collection);
  445. };
  446. case 4: return function(accumulator, value, index, collection) {
  447. return func.call(thisArg, accumulator, value, index, collection);
  448. };
  449. }
  450. return bind(func, thisArg);
  451. }
  452. /**
  453. * The base implementation of `createWrapper` that creates the wrapper and
  454. * sets its meta data.
  455. *
  456. * @private
  457. * @param {Array} bindData The bind data array.
  458. * @returns {Function} Returns the new function.
  459. */
  460. function baseCreateWrapper(bindData) {
  461. var func = bindData[0],
  462. bitmask = bindData[1],
  463. partialArgs = bindData[2],
  464. partialRightArgs = bindData[3],
  465. thisArg = bindData[4],
  466. arity = bindData[5];
  467. var isBind = bitmask & 1,
  468. isBindKey = bitmask & 2,
  469. isCurry = bitmask & 4,
  470. isCurryBound = bitmask & 8,
  471. key = func;
  472. function bound() {
  473. var thisBinding = isBind ? thisArg : this;
  474. if (partialArgs) {
  475. var args = slice(partialArgs);
  476. push.apply(args, arguments);
  477. }
  478. if (partialRightArgs || isCurry) {
  479. args || (args = slice(arguments));
  480. if (partialRightArgs) {
  481. push.apply(args, partialRightArgs);
  482. }
  483. if (isCurry && args.length < arity) {
  484. bitmask |= 16 & ~32;
  485. return baseCreateWrapper([func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity]);
  486. }
  487. }
  488. args || (args = arguments);
  489. if (isBindKey) {
  490. func = thisBinding[key];
  491. }
  492. if (this instanceof bound) {
  493. thisBinding = baseCreate(func.prototype);
  494. var result = func.apply(thisBinding, args);
  495. return isObject(result) ? result : thisBinding;
  496. }
  497. return func.apply(thisBinding, args);
  498. }
  499. setBindData(bound, bindData);
  500. return bound;
  501. }
  502. /**
  503. * Creates a function that, when called, either curries or invokes `func`
  504. * with an optional `this` binding and partially applied arguments.
  505. *
  506. * @private
  507. * @param {Function|string} func The function or method name to reference.
  508. * @param {number} bitmask The bitmask of method flags to compose.
  509. * The bitmask may be composed of the following flags:
  510. * 1 - `_.bind`
  511. * 2 - `_.bindKey`
  512. * 4 - `_.curry`
  513. * 8 - `_.curry` (bound)
  514. * 16 - `_.partial`
  515. * 32 - `_.partialRight`
  516. * @param {Array} [partialArgs] An array of arguments to prepend to those
  517. * provided to the new function.
  518. * @param {Array} [partialRightArgs] An array of arguments to append to those
  519. * provided to the new function.
  520. * @param {*} [thisArg] The `this` binding of `func`.
  521. * @param {number} [arity] The arity of `func`.
  522. * @returns {Function} Returns the new function.
  523. */
  524. function createWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) {
  525. var isBind = bitmask & 1,
  526. isBindKey = bitmask & 2,
  527. isCurry = bitmask & 4,
  528. isCurryBound = bitmask & 8,
  529. isPartial = bitmask & 16,
  530. isPartialRight = bitmask & 32;
  531. if (!isBindKey && !isFunction(func)) {
  532. throw new TypeError;
  533. }
  534. if (isPartial && !partialArgs.length) {
  535. bitmask &= ~16;
  536. isPartial = partialArgs = false;
  537. }
  538. if (isPartialRight && !partialRightArgs.length) {
  539. bitmask &= ~32;
  540. isPartialRight = partialRightArgs = false;
  541. }
  542. var bindData = func && func.__bindData__;
  543. if (bindData && bindData !== true) {
  544. // clone `bindData`
  545. bindData = slice(bindData);
  546. if (bindData[2]) {
  547. bindData[2] = slice(bindData[2]);
  548. }
  549. if (bindData[3]) {
  550. bindData[3] = slice(bindData[3]);
  551. }
  552. // set `thisBinding` is not previously bound
  553. if (isBind && !(bindData[1] & 1)) {
  554. bindData[4] = thisArg;
  555. }
  556. // set if previously bound but not currently (subsequent curried functions)
  557. if (!isBind && bindData[1] & 1) {
  558. bitmask |= 8;
  559. }
  560. // set curried arity if not yet set
  561. if (isCurry && !(bindData[1] & 4)) {
  562. bindData[5] = arity;
  563. }
  564. // append partial left arguments
  565. if (isPartial) {
  566. push.apply(bindData[2] || (bindData[2] = []), partialArgs);
  567. }
  568. // append partial right arguments
  569. if (isPartialRight) {
  570. unshift.apply(bindData[3] || (bindData[3] = []), partialRightArgs);
  571. }
  572. // merge flags
  573. bindData[1] |= bitmask;
  574. return createWrapper.apply(null, bindData);
  575. }
  576. // fast path for `_.bind`
  577. var creater = (bitmask == 1 || bitmask === 17) ? baseBind : baseCreateWrapper;
  578. return creater([func, bitmask, partialArgs, partialRightArgs, thisArg, arity]);
  579. }
  580. /**
  581. * Checks if `value` is a native function.
  582. *
  583. * @private
  584. * @param {*} value The value to check.
  585. * @returns {boolean} Returns `true` if the `value` is a native function, else `false`.
  586. */
  587. function isNative(value) {
  588. return typeof value == 'function' && reNative.test(value);
  589. }
  590. /**
  591. * Sets `this` binding data on a given function.
  592. *
  593. * @private
  594. * @param {Function} func The function to set data on.
  595. * @param {Array} value The data array to set.
  596. */
  597. var setBindData = !defineProperty ? noop : function(func, value) {
  598. descriptor.value = value;
  599. defineProperty(func, '__bindData__', descriptor);
  600. };
  601. /**
  602. * A fallback implementation of `isPlainObject` which checks if a given value
  603. * is an object created by the `Object` constructor, assuming objects created
  604. * by the `Object` constructor have no inherited enumerable properties and that
  605. * there are no `Object.prototype` extensions.
  606. *
  607. * @private
  608. * @param {*} value The value to check.
  609. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  610. */
  611. function shimIsPlainObject(value) {
  612. var ctor,
  613. result;
  614. // avoid non Object objects, `arguments` objects, and DOM elements
  615. if (!(value && toString.call(value) == objectClass) ||
  616. (ctor = value.constructor, isFunction(ctor) && !(ctor instanceof ctor))) {
  617. return false;
  618. }
  619. // In most environments an object's own properties are iterated before
  620. // its inherited properties. If the last iterated property is an object's
  621. // own property then there are no inherited enumerable properties.
  622. forIn(value, function(value, key) {
  623. result = key;
  624. });
  625. return typeof result == 'undefined' || hasOwnProperty.call(value, result);
  626. }
  627. /*--------------------------------------------------------------------------*/
  628. /**
  629. * Checks if `value` is an array.
  630. *
  631. * @static
  632. * @memberOf _
  633. * @type Function
  634. * @category Objects
  635. * @param {*} value The value to check.
  636. * @returns {boolean} Returns `true` if the `value` is an array, else `false`.
  637. * @example
  638. *
  639. * (function() { return _.isArray(arguments); })();
  640. * // => false
  641. *
  642. * _.isArray([1, 2, 3]);
  643. * // => true
  644. */
  645. var isArray = nativeIsArray || function(value) {
  646. return value && typeof value == 'object' && typeof value.length == 'number' &&
  647. toString.call(value) == arrayClass || false;
  648. };
  649. /**
  650. * A fallback implementation of `Object.keys` which produces an array of the
  651. * given object's own enumerable property names.
  652. *
  653. * @private
  654. * @type Function
  655. * @param {Object} object The object to inspect.
  656. * @returns {Array} Returns an array of property names.
  657. */
  658. var shimKeys = function(object) {
  659. var index, iterable = object, result = [];
  660. if (!iterable) return result;
  661. if (!(objectTypes[typeof object])) return result;
  662. for (index in iterable) {
  663. if (hasOwnProperty.call(iterable, index)) {
  664. result.push(index);
  665. }
  666. }
  667. return result
  668. };
  669. /**
  670. * Creates an array composed of the own enumerable property names of an object.
  671. *
  672. * @static
  673. * @memberOf _
  674. * @category Objects
  675. * @param {Object} object The object to inspect.
  676. * @returns {Array} Returns an array of property names.
  677. * @example
  678. *
  679. * _.keys({ 'one': 1, 'two': 2, 'three': 3 });
  680. * // => ['one', 'two', 'three'] (property order is not guaranteed across environments)
  681. */
  682. var keys = !nativeKeys ? shimKeys : function(object) {
  683. if (!isObject(object)) {
  684. return [];
  685. }
  686. return nativeKeys(object);
  687. };
  688. /*--------------------------------------------------------------------------*/
  689. /**
  690. * Assigns own enumerable properties of source object(s) to the destination
  691. * object. Subsequent sources will overwrite property assignments of previous
  692. * sources. If a callback is provided it will be executed to produce the
  693. * assigned values. The callback is bound to `thisArg` and invoked with two
  694. * arguments; (objectValue, sourceValue).
  695. *
  696. * @static
  697. * @memberOf _
  698. * @type Function
  699. * @alias extend
  700. * @category Objects
  701. * @param {Object} object The destination object.
  702. * @param {...Object} [source] The source objects.
  703. * @param {Function} [callback] The function to customize assigning values.
  704. * @param {*} [thisArg] The `this` binding of `callback`.
  705. * @returns {Object} Returns the destination object.
  706. * @example
  707. *
  708. * _.assign({ 'name': 'fred' }, { 'employer': 'slate' });
  709. * // => { 'name': 'fred', 'employer': 'slate' }
  710. *
  711. * var defaults = _.partialRight(_.assign, function(a, b) {
  712. * return typeof a == 'undefined' ? b : a;
  713. * });
  714. *
  715. * var object = { 'name': 'barney' };
  716. * defaults(object, { 'name': 'fred', 'employer': 'slate' });
  717. * // => { 'name': 'barney', 'employer': 'slate' }
  718. */
  719. var assign = function(object, source, guard) {
  720. var index, iterable = object, result = iterable;
  721. if (!iterable) return result;
  722. var args = arguments,
  723. argsIndex = 0,
  724. argsLength = typeof guard == 'number' ? 2 : args.length;
  725. if (argsLength > 3 && typeof args[argsLength - 2] == 'function') {
  726. var callback = baseCreateCallback(args[--argsLength - 1], args[argsLength--], 2);
  727. } else if (argsLength > 2 && typeof args[argsLength - 1] == 'function') {
  728. callback = args[--argsLength];
  729. }
  730. while (++argsIndex < argsLength) {
  731. iterable = args[argsIndex];
  732. if (iterable && objectTypes[typeof iterable]) {
  733. var ownIndex = -1,
  734. ownProps = objectTypes[typeof iterable] && keys(iterable),
  735. length = ownProps ? ownProps.length : 0;
  736. while (++ownIndex < length) {
  737. index = ownProps[ownIndex];
  738. result[index] = callback ? callback(result[index], iterable[index]) : iterable[index];
  739. }
  740. }
  741. }
  742. return result
  743. };
  744. /**
  745. * Creates a clone of `value`. If `isDeep` is `true` nested objects will also
  746. * be cloned, otherwise they will be assigned by reference. If a callback
  747. * is provided it will be executed to produce the cloned values. If the
  748. * callback returns `undefined` cloning will be handled by the method instead.
  749. * The callback is bound to `thisArg` and invoked with one argument; (value).
  750. *
  751. * @static
  752. * @memberOf _
  753. * @category Objects
  754. * @param {*} value The value to clone.
  755. * @param {boolean} [isDeep=false] Specify a deep clone.
  756. * @param {Function} [callback] The function to customize cloning values.
  757. * @param {*} [thisArg] The `this` binding of `callback`.
  758. * @returns {*} Returns the cloned value.
  759. * @example
  760. *
  761. * var characters = [
  762. * { 'name': 'barney', 'age': 36 },
  763. * { 'name': 'fred', 'age': 40 }
  764. * ];
  765. *
  766. * var shallow = _.clone(characters);
  767. * shallow[0] === characters[0];
  768. * // => true
  769. *
  770. * var deep = _.clone(characters, true);
  771. * deep[0] === characters[0];
  772. * // => false
  773. *
  774. * _.mixin({
  775. * 'clone': _.partialRight(_.clone, function(value) {
  776. * return _.isElement(value) ? value.cloneNode(false) : undefined;
  777. * })
  778. * });
  779. *
  780. * var clone = _.clone(document.body);
  781. * clone.childNodes.length;
  782. * // => 0
  783. */
  784. function clone(value, isDeep, callback, thisArg) {
  785. // allows working with "Collections" methods without using their `index`
  786. // and `collection` arguments for `isDeep` and `callback`
  787. if (typeof isDeep != 'boolean' && isDeep != null) {
  788. thisArg = callback;
  789. callback = isDeep;
  790. isDeep = false;
  791. }
  792. return baseClone(value, isDeep, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1));
  793. }
  794. /**
  795. * Iterates over own and inherited enumerable properties of an object,
  796. * executing the callback for each property. The callback is bound to `thisArg`
  797. * and invoked with three arguments; (value, key, object). Callbacks may exit
  798. * iteration early by explicitly returning `false`.
  799. *
  800. * @static
  801. * @memberOf _
  802. * @type Function
  803. * @category Objects
  804. * @param {Object} object The object to iterate over.
  805. * @param {Function} [callback=identity] The function called per iteration.
  806. * @param {*} [thisArg] The `this` binding of `callback`.
  807. * @returns {Object} Returns `object`.
  808. * @example
  809. *
  810. * function Shape() {
  811. * this.x = 0;
  812. * this.y = 0;
  813. * }
  814. *
  815. * Shape.prototype.move = function(x, y) {
  816. * this.x += x;
  817. * this.y += y;
  818. * };
  819. *
  820. * _.forIn(new Shape, function(value, key) {
  821. * console.log(key);
  822. * });
  823. * // => logs 'x', 'y', and 'move' (property order is not guaranteed across environments)
  824. */
  825. var forIn = function(collection, callback, thisArg) {
  826. var index, iterable = collection, result = iterable;
  827. if (!iterable) return result;
  828. if (!objectTypes[typeof iterable]) return result;
  829. callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3);
  830. for (index in iterable) {
  831. if (callback(iterable[index], index, collection) === false) return result;
  832. }
  833. return result
  834. };
  835. /**
  836. * Iterates over own enumerable properties of an object, executing the callback
  837. * for each property. The callback is bound to `thisArg` and invoked with three
  838. * arguments; (value, key, object). Callbacks may exit iteration early by
  839. * explicitly returning `false`.
  840. *
  841. * @static
  842. * @memberOf _
  843. * @type Function
  844. * @category Objects
  845. * @param {Object} object The object to iterate over.
  846. * @param {Function} [callback=identity] The function called per iteration.
  847. * @param {*} [thisArg] The `this` binding of `callback`.
  848. * @returns {Object} Returns `object`.
  849. * @example
  850. *
  851. * _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) {
  852. * console.log(key);
  853. * });
  854. * // => logs '0', '1', and 'length' (property order is not guaranteed across environments)
  855. */
  856. var forOwn = function(collection, callback, thisArg) {
  857. var index, iterable = collection, result = iterable;
  858. if (!iterable) return result;
  859. if (!objectTypes[typeof iterable]) return result;
  860. callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3);
  861. var ownIndex = -1,
  862. ownProps = objectTypes[typeof iterable] && keys(iterable),
  863. length = ownProps ? ownProps.length : 0;
  864. while (++ownIndex < length) {
  865. index = ownProps[ownIndex];
  866. if (callback(iterable[index], index, collection) === false) return result;
  867. }
  868. return result
  869. };
  870. /**
  871. * Checks if `value` is a function.
  872. *
  873. * @static
  874. * @memberOf _
  875. * @category Objects
  876. * @param {*} value The value to check.
  877. * @returns {boolean} Returns `true` if the `value` is a function, else `false`.
  878. * @example
  879. *
  880. * _.isFunction(_);
  881. * // => true
  882. */
  883. function isFunction(value) {
  884. return typeof value == 'function';
  885. }
  886. /**
  887. * Checks if `value` is the language type of Object.
  888. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  889. *
  890. * @static
  891. * @memberOf _
  892. * @category Objects
  893. * @param {*} value The value to check.
  894. * @returns {boolean} Returns `true` if the `value` is an object, else `false`.
  895. * @example
  896. *
  897. * _.isObject({});
  898. * // => true
  899. *
  900. * _.isObject([1, 2, 3]);
  901. * // => true
  902. *
  903. * _.isObject(1);
  904. * // => false
  905. */
  906. function isObject(value) {
  907. // check if the value is the ECMAScript language type of Object
  908. // http://es5.github.io/#x8
  909. // and avoid a V8 bug
  910. // http://code.google.com/p/v8/issues/detail?id=2291
  911. return !!(value && objectTypes[typeof value]);
  912. }
  913. /**
  914. * Checks if `value` is an object created by the `Object` constructor.
  915. *
  916. * @static
  917. * @memberOf _
  918. * @category Objects
  919. * @param {*} value The value to check.
  920. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  921. * @example
  922. *
  923. * function Shape() {
  924. * this.x = 0;
  925. * this.y = 0;
  926. * }
  927. *
  928. * _.isPlainObject(new Shape);
  929. * // => false
  930. *
  931. * _.isPlainObject([1, 2, 3]);
  932. * // => false
  933. *
  934. * _.isPlainObject({ 'x': 0, 'y': 0 });
  935. * // => true
  936. */
  937. var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) {
  938. if (!(value && toString.call(value) == objectClass)) {
  939. return false;
  940. }
  941. var valueOf = value.valueOf,
  942. objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
  943. return objProto
  944. ? (value == objProto || getPrototypeOf(value) == objProto)
  945. : shimIsPlainObject(value);
  946. };
  947. /*--------------------------------------------------------------------------*/
  948. /**
  949. * Iterates over elements of a collection, executing the callback for each
  950. * element. The callback is bound to `thisArg` and invoked with three arguments;
  951. * (value, index|key, collection). Callbacks may exit iteration early by
  952. * explicitly returning `false`.
  953. *
  954. * Note: As with other "Collections" methods, objects with a `length` property
  955. * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
  956. * may be used for object iteration.
  957. *
  958. * @static
  959. * @memberOf _
  960. * @alias each
  961. * @category Collections
  962. * @param {Array|Object|string} collection The collection to iterate over.
  963. * @param {Function} [callback=identity] The function called per iteration.
  964. * @param {*} [thisArg] The `this` binding of `callback`.
  965. * @returns {Array|Object|string} Returns `collection`.
  966. * @example
  967. *
  968. * _([1, 2, 3]).forEach(function(num) { console.log(num); }).join(',');
  969. * // => logs each number and returns '1,2,3'
  970. *
  971. * _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { console.log(num); });
  972. * // => logs each number and returns the object (property order is not guaranteed across environments)
  973. */
  974. function forEach(collection, callback, thisArg) {
  975. var index = -1,
  976. length = collection ? collection.length : 0;
  977. callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3);
  978. if (typeof length == 'number') {
  979. while (++index < length) {
  980. if (callback(collection[index], index, collection) === false) {
  981. break;
  982. }
  983. }
  984. } else {
  985. forOwn(collection, callback);
  986. }
  987. return collection;
  988. }
  989. /*--------------------------------------------------------------------------*/
  990. /**
  991. * Creates a function that, when called, invokes `func` with the `this`
  992. * binding of `thisArg` and prepends any additional `bind` arguments to those
  993. * provided to the bound function.
  994. *
  995. * @static
  996. * @memberOf _
  997. * @category Functions
  998. * @param {Function} func The function to bind.
  999. * @param {*} [thisArg] The `this` binding of `func`.
  1000. * @param {...*} [arg] Arguments to be partially applied.
  1001. * @returns {Function} Returns the new bound function.
  1002. * @example
  1003. *
  1004. * var func = function(greeting) {
  1005. * return greeting + ' ' + this.name;
  1006. * };
  1007. *
  1008. * func = _.bind(func, { 'name': 'fred' }, 'hi');
  1009. * func();
  1010. * // => 'hi fred'
  1011. */
  1012. function bind(func, thisArg) {
  1013. return arguments.length > 2
  1014. ? createWrapper(func, 17, slice(arguments, 2), null, thisArg)
  1015. : createWrapper(func, 1, null, null, thisArg);
  1016. }
  1017. /*--------------------------------------------------------------------------*/
  1018. /**
  1019. * This method returns the first argument provided to it.
  1020. *
  1021. * @static
  1022. * @memberOf _
  1023. * @category Utilities
  1024. * @param {*} value Any value.
  1025. * @returns {*} Returns `value`.
  1026. * @example
  1027. *
  1028. * var object = { 'name': 'fred' };
  1029. * _.identity(object) === object;
  1030. * // => true
  1031. */
  1032. function identity(value) {
  1033. return value;
  1034. }
  1035. /**
  1036. * A no-operation function.
  1037. *
  1038. * @static
  1039. * @memberOf _
  1040. * @category Utilities
  1041. * @example
  1042. *
  1043. * var object = { 'name': 'fred' };
  1044. * _.noop(object) === undefined;
  1045. * // => true
  1046. */
  1047. function noop() {
  1048. // no operation performed
  1049. }
  1050. /*--------------------------------------------------------------------------*/
  1051. lodash.assign = assign;
  1052. lodash.bind = bind;
  1053. lodash.forEach = forEach;
  1054. lodash.forIn = forIn;
  1055. lodash.forOwn = forOwn;
  1056. lodash.keys = keys;
  1057. lodash.each = forEach;
  1058. lodash.extend = assign;
  1059. /*--------------------------------------------------------------------------*/
  1060. // add functions that return unwrapped values when chaining
  1061. lodash.clone = clone;
  1062. lodash.identity = identity;
  1063. lodash.isArray = isArray;
  1064. lodash.isFunction = isFunction;
  1065. lodash.isObject = isObject;
  1066. lodash.isPlainObject = isPlainObject;
  1067. lodash.noop = noop;
  1068. /*--------------------------------------------------------------------------*/
  1069. /**
  1070. * The semantic version number.
  1071. *
  1072. * @static
  1073. * @memberOf _
  1074. * @type string
  1075. */
  1076. lodash.VERSION = '2.4.1';
  1077. /*--------------------------------------------------------------------------*/
  1078. // some AMD build optimizers like r.js check for condition patterns like the following:
  1079. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  1080. // define as an anonymous module so, through path mapping, it can be
  1081. // referenced as the "underscore" module
  1082. define(function() {
  1083. return lodash;
  1084. });
  1085. }
  1086. }.call(this));