Copy it

Hold Alt click on text, Copy as plain text. Alt + Shift click on text, Copy as kebab-case.

当前为 2023-08-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Copy it
  3. // @name:zh-CN 便捷复制
  4. // @namespace https://github.com/xianghongai/Tampermonkey-UserScript
  5. // @version 1.2.0
  6. // @description Hold Alt click on text, Copy as plain text. Alt + Shift click on text, Copy as kebab-case.
  7. // @description:zh-CN 按住 Alt 键点击文本,复制为纯文本。Alt + Shift 复制为 kebab-case 风格字符。
  8. // @author Nicholas Hsiang
  9. // @icon https://xinlu.ink/favicon.ico
  10. // @match http*://*/*
  11. // @exclude *://*.github.dev
  12. // @grant GM_setClipboard
  13. // @license MIT
  14. // ==/UserScript==
  15.  
  16. function main() {
  17. 'use strict';
  18. // https://www.w3schools.com/js/tryit.asp?filename=tryjs_addeventlistener_usecapture
  19. // true: capturing, 当目标元素有添加事件,停止冒泡,以致无法生效,采用捕获模式
  20. // false: bubbling,当目标元素有添加事件,并有其它交互行为 (切换视图、打开弹窗...),以致无法额外触发,采用冒泡模式
  21. document.addEventListener('click', listener, true);
  22.  
  23. function listener(event) {
  24. if (event.altKey) {
  25. event.preventDefault();
  26. event.stopPropagation();
  27. const text = getText(event.target);
  28. if (event.shiftKey) {
  29. // camelCase,capitalize,kebabCase,snakeCase
  30. return copyTextToClipboard(_.kebabCase(text));
  31. }
  32. return copyTextToClipboard(text);
  33. }
  34. }
  35.  
  36. const VALUE_CONTROLLER = ['INPUT', 'TEXTAREA'];
  37.  
  38. function getText(el) {
  39. let text = '';
  40. if (VALUE_CONTROLLER.includes(el.tagName)) {
  41. const value = `${el.value}`.trim();
  42. const placeholder = el.placeholder ?? '';
  43. text = value === '' ? placeholder : value;
  44. } else if (el.tagName === 'SELECT') {
  45. const selectedOption = el.options[el.selectedIndex];
  46. text = selectedOption.text;
  47. } else {
  48. text = el.innerText;
  49. }
  50. return text.trim();
  51. }
  52.  
  53. function copyTextToClipboard(text) {
  54. GM_setClipboard(text, 'text');
  55. }
  56. }
  57.  
  58.  
  59. /**
  60. * @license
  61. * Lodash (Custom Build) <https://lodash.com/>
  62. * Build: `lodash include="camelCase,capitalize,kebabCase,snakeCase,"`
  63. * Copyright JS Foundation and other contributors <https://js.foundation/>
  64. * Released under MIT license <https://lodash.com/license>
  65. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  66. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  67. */
  68. ; (function () {
  69.  
  70. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  71. var undefined;
  72.  
  73. /** Used as the semantic version number. */
  74. var VERSION = '4.17.5';
  75.  
  76. /** Used as references for various `Number` constants. */
  77. var INFINITY = 1 / 0;
  78.  
  79. /** `Object#toString` result references. */
  80. var nullTag = '[object Null]',
  81. symbolTag = '[object Symbol]',
  82. undefinedTag = '[object Undefined]';
  83.  
  84. /** Used to match words composed of alphanumeric characters. */
  85. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  86.  
  87. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  88. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  89.  
  90. /** Used to compose unicode character classes. */
  91. var rsAstralRange = '\\ud800-\\udfff',
  92. rsComboMarksRange = '\\u0300-\\u036f',
  93. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  94. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  95. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  96. rsDingbatRange = '\\u2700-\\u27bf',
  97. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  98. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  99. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  100. rsPunctuationRange = '\\u2000-\\u206f',
  101. rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
  102. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  103. rsVarRange = '\\ufe0e\\ufe0f',
  104. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  105.  
  106. /** Used to compose unicode capture groups. */
  107. var rsApos = "['\u2019]",
  108. rsAstral = '[' + rsAstralRange + ']',
  109. rsBreak = '[' + rsBreakRange + ']',
  110. rsCombo = '[' + rsComboRange + ']',
  111. rsDigits = '\\d+',
  112. rsDingbat = '[' + rsDingbatRange + ']',
  113. rsLower = '[' + rsLowerRange + ']',
  114. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  115. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  116. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  117. rsNonAstral = '[^' + rsAstralRange + ']',
  118. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  119. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  120. rsUpper = '[' + rsUpperRange + ']',
  121. rsZWJ = '\\u200d';
  122.  
  123. /** Used to compose unicode regexes. */
  124. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  125. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  126. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  127. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  128. reOptMod = rsModifier + '?',
  129. rsOptVar = '[' + rsVarRange + ']?',
  130. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  131. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  132. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  133. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  134. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  135. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  136.  
  137. /** Used to match apostrophes. */
  138. var reApos = RegExp(rsApos, 'g');
  139.  
  140. /**
  141. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  142. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  143. */
  144. var reComboMark = RegExp(rsCombo, 'g');
  145.  
  146. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  147. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  148.  
  149. /** Used to match complex or compound words. */
  150. var reUnicodeWord = RegExp([
  151. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  152. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  153. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  154. rsUpper + '+' + rsOptContrUpper,
  155. rsOrdUpper,
  156. rsOrdLower,
  157. rsDigits,
  158. rsEmoji
  159. ].join('|'), 'g');
  160.  
  161. /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
  162. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  163.  
  164. /** Used to detect strings that need a more robust regexp to match words. */
  165. var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
  166.  
  167. /** Used to map Latin Unicode letters to basic Latin letters. */
  168. var deburredLetters = {
  169. // Latin-1 Supplement block.
  170. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  171. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  172. '\xc7': 'C', '\xe7': 'c',
  173. '\xd0': 'D', '\xf0': 'd',
  174. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  175. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  176. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  177. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  178. '\xd1': 'N', '\xf1': 'n',
  179. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  180. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  181. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  182. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  183. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  184. '\xc6': 'Ae', '\xe6': 'ae',
  185. '\xde': 'Th', '\xfe': 'th',
  186. '\xdf': 'ss',
  187. // Latin Extended-A block.
  188. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  189. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  190. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  191. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  192. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  193. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  194. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  195. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  196. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  197. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  198. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  199. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  200. '\u0134': 'J', '\u0135': 'j',
  201. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  202. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  203. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  204. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  205. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  206. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  207. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  208. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  209. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  210. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  211. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  212. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  213. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  214. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  215. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  216. '\u0174': 'W', '\u0175': 'w',
  217. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  218. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  219. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  220. '\u0132': 'IJ', '\u0133': 'ij',
  221. '\u0152': 'Oe', '\u0153': 'oe',
  222. '\u0149': "'n", '\u017f': 's'
  223. };
  224.  
  225. /** Detect free variable `global` from Node.js. */
  226. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  227.  
  228. /** Detect free variable `self`. */
  229. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  230.  
  231. /** Used as a reference to the global object. */
  232. var root = freeGlobal || freeSelf || Function('return this')();
  233.  
  234. /** Detect free variable `exports`. */
  235. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  236.  
  237. /** Detect free variable `module`. */
  238. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  239.  
  240. /*--------------------------------------------------------------------------*/
  241.  
  242. /**
  243. * A specialized version of `_.map` for arrays without support for iteratee
  244. * shorthands.
  245. *
  246. * @private
  247. * @param {Array} [array] The array to iterate over.
  248. * @param {Function} iteratee The function invoked per iteration.
  249. * @returns {Array} Returns the new mapped array.
  250. */
  251. function arrayMap(array, iteratee) {
  252. var index = -1,
  253. length = array == null ? 0 : array.length,
  254. result = Array(length);
  255.  
  256. while (++index < length) {
  257. result[index] = iteratee(array[index], index, array);
  258. }
  259. return result;
  260. }
  261.  
  262. /**
  263. * A specialized version of `_.reduce` for arrays without support for
  264. * iteratee shorthands.
  265. *
  266. * @private
  267. * @param {Array} [array] The array to iterate over.
  268. * @param {Function} iteratee The function invoked per iteration.
  269. * @param {*} [accumulator] The initial value.
  270. * @param {boolean} [initAccum] Specify using the first element of `array` as
  271. * the initial value.
  272. * @returns {*} Returns the accumulated value.
  273. */
  274. function arrayReduce(array, iteratee, accumulator, initAccum) {
  275. var index = -1,
  276. length = array == null ? 0 : array.length;
  277.  
  278. if (initAccum && length) {
  279. accumulator = array[++index];
  280. }
  281. while (++index < length) {
  282. accumulator = iteratee(accumulator, array[index], index, array);
  283. }
  284. return accumulator;
  285. }
  286.  
  287. /**
  288. * Converts an ASCII `string` to an array.
  289. *
  290. * @private
  291. * @param {string} string The string to convert.
  292. * @returns {Array} Returns the converted array.
  293. */
  294. function asciiToArray(string) {
  295. return string.split('');
  296. }
  297.  
  298. /**
  299. * Splits an ASCII `string` into an array of its words.
  300. *
  301. * @private
  302. * @param {string} The string to inspect.
  303. * @returns {Array} Returns the words of `string`.
  304. */
  305. function asciiWords(string) {
  306. return string.match(reAsciiWord) || [];
  307. }
  308.  
  309. /**
  310. * The base implementation of `_.propertyOf` without support for deep paths.
  311. *
  312. * @private
  313. * @param {Object} object The object to query.
  314. * @returns {Function} Returns the new accessor function.
  315. */
  316. function basePropertyOf(object) {
  317. return function (key) {
  318. return object == null ? undefined : object[key];
  319. };
  320. }
  321.  
  322. /**
  323. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  324. * letters to basic Latin letters.
  325. *
  326. * @private
  327. * @param {string} letter The matched letter to deburr.
  328. * @returns {string} Returns the deburred letter.
  329. */
  330. var deburrLetter = basePropertyOf(deburredLetters);
  331.  
  332. /**
  333. * Checks if `string` contains Unicode symbols.
  334. *
  335. * @private
  336. * @param {string} string The string to inspect.
  337. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  338. */
  339. function hasUnicode(string) {
  340. return reHasUnicode.test(string);
  341. }
  342.  
  343. /**
  344. * Checks if `string` contains a word composed of Unicode symbols.
  345. *
  346. * @private
  347. * @param {string} string The string to inspect.
  348. * @returns {boolean} Returns `true` if a word is found, else `false`.
  349. */
  350. function hasUnicodeWord(string) {
  351. return reHasUnicodeWord.test(string);
  352. }
  353.  
  354. /**
  355. * Converts `string` to an array.
  356. *
  357. * @private
  358. * @param {string} string The string to convert.
  359. * @returns {Array} Returns the converted array.
  360. */
  361. function stringToArray(string) {
  362. return hasUnicode(string)
  363. ? unicodeToArray(string)
  364. : asciiToArray(string);
  365. }
  366.  
  367. /**
  368. * Converts a Unicode `string` to an array.
  369. *
  370. * @private
  371. * @param {string} string The string to convert.
  372. * @returns {Array} Returns the converted array.
  373. */
  374. function unicodeToArray(string) {
  375. return string.match(reUnicode) || [];
  376. }
  377.  
  378. /**
  379. * Splits a Unicode `string` into an array of its words.
  380. *
  381. * @private
  382. * @param {string} The string to inspect.
  383. * @returns {Array} Returns the words of `string`.
  384. */
  385. function unicodeWords(string) {
  386. return string.match(reUnicodeWord) || [];
  387. }
  388.  
  389. /*--------------------------------------------------------------------------*/
  390.  
  391. /** Used for built-in method references. */
  392. var objectProto = Object.prototype;
  393.  
  394. /** Used to check objects for own properties. */
  395. var hasOwnProperty = objectProto.hasOwnProperty;
  396.  
  397. /**
  398. * Used to resolve the
  399. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  400. * of values.
  401. */
  402. var nativeObjectToString = objectProto.toString;
  403.  
  404. /** Built-in value references. */
  405. var Symbol = root.Symbol,
  406. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  407.  
  408. /** Used to lookup unminified function names. */
  409. var realNames = {};
  410.  
  411. /** Used to convert symbols to primitives and strings. */
  412. var symbolProto = Symbol ? Symbol.prototype : undefined,
  413. symbolToString = symbolProto ? symbolProto.toString : undefined;
  414.  
  415. /*------------------------------------------------------------------------*/
  416.  
  417. /**
  418. * Creates a `lodash` object which wraps `value` to enable implicit method
  419. * chain sequences. Methods that operate on and return arrays, collections,
  420. * and functions can be chained together. Methods that retrieve a single value
  421. * or may return a primitive value will automatically end the chain sequence
  422. * and return the unwrapped value. Otherwise, the value must be unwrapped
  423. * with `_#value`.
  424. *
  425. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  426. * enabled using `_.chain`.
  427. *
  428. * The execution of chained methods is lazy, that is, it's deferred until
  429. * `_#value` is implicitly or explicitly called.
  430. *
  431. * Lazy evaluation allows several methods to support shortcut fusion.
  432. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  433. * the creation of intermediate arrays and can greatly reduce the number of
  434. * iteratee executions. Sections of a chain sequence qualify for shortcut
  435. * fusion if the section is applied to an array and iteratees accept only
  436. * one argument. The heuristic for whether a section qualifies for shortcut
  437. * fusion is subject to change.
  438. *
  439. * Chaining is supported in custom builds as long as the `_#value` method is
  440. * directly or indirectly included in the build.
  441. *
  442. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  443. *
  444. * The wrapper `Array` methods are:
  445. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  446. *
  447. * The wrapper `String` methods are:
  448. * `replace` and `split`
  449. *
  450. * The wrapper methods that support shortcut fusion are:
  451. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  452. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  453. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  454. *
  455. * The chainable wrapper methods are:
  456. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  457. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  458. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  459. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  460. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  461. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  462. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  463. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  464. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  465. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  466. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  467. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  468. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  469. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  470. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  471. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  472. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  473. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  474. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  475. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  476. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  477. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  478. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  479. * `zipObject`, `zipObjectDeep`, and `zipWith`
  480. *
  481. * The wrapper methods that are **not** chainable by default are:
  482. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  483. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  484. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  485. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  486. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  487. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  488. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  489. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  490. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  491. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  492. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  493. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  494. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  495. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  496. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  497. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  498. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  499. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  500. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  501. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  502. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  503. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  504. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  505. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  506. * `upperFirst`, `value`, and `words`
  507. *
  508. * @name _
  509. * @constructor
  510. * @category Seq
  511. * @param {*} value The value to wrap in a `lodash` instance.
  512. * @returns {Object} Returns the new `lodash` wrapper instance.
  513. * @example
  514. *
  515. * function square(n) {
  516. * return n * n;
  517. * }
  518. *
  519. * var wrapped = _([1, 2, 3]);
  520. *
  521. * // Returns an unwrapped value.
  522. * wrapped.reduce(_.add);
  523. * // => 6
  524. *
  525. * // Returns a wrapped value.
  526. * var squares = wrapped.map(square);
  527. *
  528. * _.isArray(squares);
  529. * // => false
  530. *
  531. * _.isArray(squares.value());
  532. * // => true
  533. */
  534. function lodash() {
  535. // No operation performed.
  536. }
  537.  
  538. /*------------------------------------------------------------------------*/
  539.  
  540. /**
  541. * The base implementation of `getTag` without fallbacks for buggy environments.
  542. *
  543. * @private
  544. * @param {*} value The value to query.
  545. * @returns {string} Returns the `toStringTag`.
  546. */
  547. function baseGetTag(value) {
  548. if (value == null) {
  549. return value === undefined ? undefinedTag : nullTag;
  550. }
  551. return (symToStringTag && symToStringTag in Object(value))
  552. ? getRawTag(value)
  553. : objectToString(value);
  554. }
  555.  
  556. /**
  557. * The base implementation of `_.slice` without an iteratee call guard.
  558. *
  559. * @private
  560. * @param {Array} array The array to slice.
  561. * @param {number} [start=0] The start position.
  562. * @param {number} [end=array.length] The end position.
  563. * @returns {Array} Returns the slice of `array`.
  564. */
  565. function baseSlice(array, start, end) {
  566. var index = -1,
  567. length = array.length;
  568.  
  569. if (start < 0) {
  570. start = -start > length ? 0 : (length + start);
  571. }
  572. end = end > length ? length : end;
  573. if (end < 0) {
  574. end += length;
  575. }
  576. length = start > end ? 0 : ((end - start) >>> 0);
  577. start >>>= 0;
  578.  
  579. var result = Array(length);
  580. while (++index < length) {
  581. result[index] = array[index + start];
  582. }
  583. return result;
  584. }
  585.  
  586. /**
  587. * The base implementation of `_.toString` which doesn't convert nullish
  588. * values to empty strings.
  589. *
  590. * @private
  591. * @param {*} value The value to process.
  592. * @returns {string} Returns the string.
  593. */
  594. function baseToString(value) {
  595. // Exit early for strings to avoid a performance hit in some environments.
  596. if (typeof value == 'string') {
  597. return value;
  598. }
  599. if (isArray(value)) {
  600. // Recursively convert values (susceptible to call stack limits).
  601. return arrayMap(value, baseToString) + '';
  602. }
  603. if (isSymbol(value)) {
  604. return symbolToString ? symbolToString.call(value) : '';
  605. }
  606. var result = (value + '');
  607. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  608. }
  609.  
  610. /**
  611. * Casts `array` to a slice if it's needed.
  612. *
  613. * @private
  614. * @param {Array} array The array to inspect.
  615. * @param {number} start The start position.
  616. * @param {number} [end=array.length] The end position.
  617. * @returns {Array} Returns the cast slice.
  618. */
  619. function castSlice(array, start, end) {
  620. var length = array.length;
  621. end = end === undefined ? length : end;
  622. return (!start && end >= length) ? array : baseSlice(array, start, end);
  623. }
  624.  
  625. /**
  626. * Creates a function like `_.lowerFirst`.
  627. *
  628. * @private
  629. * @param {string} methodName The name of the `String` case method to use.
  630. * @returns {Function} Returns the new case function.
  631. */
  632. function createCaseFirst(methodName) {
  633. return function (string) {
  634. string = toString(string);
  635.  
  636. var strSymbols = hasUnicode(string)
  637. ? stringToArray(string)
  638. : undefined;
  639.  
  640. var chr = strSymbols
  641. ? strSymbols[0]
  642. : string.charAt(0);
  643.  
  644. var trailing = strSymbols
  645. ? castSlice(strSymbols, 1).join('')
  646. : string.slice(1);
  647.  
  648. return chr[methodName]() + trailing;
  649. };
  650. }
  651.  
  652. /**
  653. * Creates a function like `_.camelCase`.
  654. *
  655. * @private
  656. * @param {Function} callback The function to combine each word.
  657. * @returns {Function} Returns the new compounder function.
  658. */
  659. function createCompounder(callback) {
  660. return function (string) {
  661. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  662. };
  663. }
  664.  
  665. /**
  666. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  667. *
  668. * @private
  669. * @param {*} value The value to query.
  670. * @returns {string} Returns the raw `toStringTag`.
  671. */
  672. function getRawTag(value) {
  673. var isOwn = hasOwnProperty.call(value, symToStringTag),
  674. tag = value[symToStringTag];
  675.  
  676. try {
  677. value[symToStringTag] = undefined;
  678. var unmasked = true;
  679. } catch (e) { }
  680.  
  681. var result = nativeObjectToString.call(value);
  682. if (unmasked) {
  683. if (isOwn) {
  684. value[symToStringTag] = tag;
  685. } else {
  686. delete value[symToStringTag];
  687. }
  688. }
  689. return result;
  690. }
  691.  
  692. /**
  693. * Converts `value` to a string using `Object.prototype.toString`.
  694. *
  695. * @private
  696. * @param {*} value The value to convert.
  697. * @returns {string} Returns the converted string.
  698. */
  699. function objectToString(value) {
  700. return nativeObjectToString.call(value);
  701. }
  702.  
  703. /*------------------------------------------------------------------------*/
  704.  
  705. /**
  706. * Checks if `value` is classified as an `Array` object.
  707. *
  708. * @static
  709. * @memberOf _
  710. * @since 0.1.0
  711. * @category Lang
  712. * @param {*} value The value to check.
  713. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  714. * @example
  715. *
  716. * _.isArray([1, 2, 3]);
  717. * // => true
  718. *
  719. * _.isArray(document.body.children);
  720. * // => false
  721. *
  722. * _.isArray('abc');
  723. * // => false
  724. *
  725. * _.isArray(_.noop);
  726. * // => false
  727. */
  728. var isArray = Array.isArray;
  729.  
  730. /**
  731. * Checks if `value` is object-like. A value is object-like if it's not `null`
  732. * and has a `typeof` result of "object".
  733. *
  734. * @static
  735. * @memberOf _
  736. * @since 4.0.0
  737. * @category Lang
  738. * @param {*} value The value to check.
  739. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  740. * @example
  741. *
  742. * _.isObjectLike({});
  743. * // => true
  744. *
  745. * _.isObjectLike([1, 2, 3]);
  746. * // => true
  747. *
  748. * _.isObjectLike(_.noop);
  749. * // => false
  750. *
  751. * _.isObjectLike(null);
  752. * // => false
  753. */
  754. function isObjectLike(value) {
  755. return value != null && typeof value == 'object';
  756. }
  757.  
  758. /**
  759. * Checks if `value` is classified as a `Symbol` primitive or object.
  760. *
  761. * @static
  762. * @memberOf _
  763. * @since 4.0.0
  764. * @category Lang
  765. * @param {*} value The value to check.
  766. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  767. * @example
  768. *
  769. * _.isSymbol(Symbol.iterator);
  770. * // => true
  771. *
  772. * _.isSymbol('abc');
  773. * // => false
  774. */
  775. function isSymbol(value) {
  776. return typeof value == 'symbol' ||
  777. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  778. }
  779.  
  780. /**
  781. * Converts `value` to a string. An empty string is returned for `null`
  782. * and `undefined` values. The sign of `-0` is preserved.
  783. *
  784. * @static
  785. * @memberOf _
  786. * @since 4.0.0
  787. * @category Lang
  788. * @param {*} value The value to convert.
  789. * @returns {string} Returns the converted string.
  790. * @example
  791. *
  792. * _.toString(null);
  793. * // => ''
  794. *
  795. * _.toString(-0);
  796. * // => '-0'
  797. *
  798. * _.toString([1, 2, 3]);
  799. * // => '1,2,3'
  800. */
  801. function toString(value) {
  802. return value == null ? '' : baseToString(value);
  803. }
  804.  
  805. /*------------------------------------------------------------------------*/
  806.  
  807. /**
  808. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  809. *
  810. * @static
  811. * @memberOf _
  812. * @since 3.0.0
  813. * @category String
  814. * @param {string} [string=''] The string to convert.
  815. * @returns {string} Returns the camel cased string.
  816. * @example
  817. *
  818. * _.camelCase('Foo Bar');
  819. * // => 'fooBar'
  820. *
  821. * _.camelCase('--foo-bar--');
  822. * // => 'fooBar'
  823. *
  824. * _.camelCase('__FOO_BAR__');
  825. * // => 'fooBar'
  826. */
  827. var camelCase = createCompounder(function (result, word, index) {
  828. word = word.toLowerCase();
  829. return result + (index ? capitalize(word) : word);
  830. });
  831.  
  832. /**
  833. * Converts the first character of `string` to upper case and the remaining
  834. * to lower case.
  835. *
  836. * @static
  837. * @memberOf _
  838. * @since 3.0.0
  839. * @category String
  840. * @param {string} [string=''] The string to capitalize.
  841. * @returns {string} Returns the capitalized string.
  842. * @example
  843. *
  844. * _.capitalize('FRED');
  845. * // => 'Fred'
  846. */
  847. function capitalize(string) {
  848. return upperFirst(toString(string).toLowerCase());
  849. }
  850.  
  851. /**
  852. * Deburrs `string` by converting
  853. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  854. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  855. * letters to basic Latin letters and removing
  856. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  857. *
  858. * @static
  859. * @memberOf _
  860. * @since 3.0.0
  861. * @category String
  862. * @param {string} [string=''] The string to deburr.
  863. * @returns {string} Returns the deburred string.
  864. * @example
  865. *
  866. * _.deburr('déjà vu');
  867. * // => 'deja vu'
  868. */
  869. function deburr(string) {
  870. string = toString(string);
  871. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  872. }
  873.  
  874. /**
  875. * Converts `string` to
  876. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  877. *
  878. * @static
  879. * @memberOf _
  880. * @since 3.0.0
  881. * @category String
  882. * @param {string} [string=''] The string to convert.
  883. * @returns {string} Returns the kebab cased string.
  884. * @example
  885. *
  886. * _.kebabCase('Foo Bar');
  887. * // => 'foo-bar'
  888. *
  889. * _.kebabCase('fooBar');
  890. * // => 'foo-bar'
  891. *
  892. * _.kebabCase('__FOO_BAR__');
  893. * // => 'foo-bar'
  894. */
  895. var kebabCase = createCompounder(function (result, word, index) {
  896. return result + (index ? '-' : '') + word.toLowerCase();
  897. });
  898.  
  899. /**
  900. * Converts `string` to
  901. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  902. *
  903. * @static
  904. * @memberOf _
  905. * @since 3.0.0
  906. * @category String
  907. * @param {string} [string=''] The string to convert.
  908. * @returns {string} Returns the snake cased string.
  909. * @example
  910. *
  911. * _.snakeCase('Foo Bar');
  912. * // => 'foo_bar'
  913. *
  914. * _.snakeCase('fooBar');
  915. * // => 'foo_bar'
  916. *
  917. * _.snakeCase('--FOO-BAR--');
  918. * // => 'foo_bar'
  919. */
  920. var snakeCase = createCompounder(function (result, word, index) {
  921. return result + (index ? '_' : '') + word.toLowerCase();
  922. });
  923.  
  924. /**
  925. * Converts the first character of `string` to upper case.
  926. *
  927. * @static
  928. * @memberOf _
  929. * @since 4.0.0
  930. * @category String
  931. * @param {string} [string=''] The string to convert.
  932. * @returns {string} Returns the converted string.
  933. * @example
  934. *
  935. * _.upperFirst('fred');
  936. * // => 'Fred'
  937. *
  938. * _.upperFirst('FRED');
  939. * // => 'FRED'
  940. */
  941. var upperFirst = createCaseFirst('toUpperCase');
  942.  
  943. /**
  944. * Splits `string` into an array of its words.
  945. *
  946. * @static
  947. * @memberOf _
  948. * @since 3.0.0
  949. * @category String
  950. * @param {string} [string=''] The string to inspect.
  951. * @param {RegExp|string} [pattern] The pattern to match words.
  952. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  953. * @returns {Array} Returns the words of `string`.
  954. * @example
  955. *
  956. * _.words('fred, barney, & pebbles');
  957. * // => ['fred', 'barney', 'pebbles']
  958. *
  959. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  960. * // => ['fred', 'barney', '&', 'pebbles']
  961. */
  962. function words(string, pattern, guard) {
  963. string = toString(string);
  964. pattern = guard ? undefined : pattern;
  965.  
  966. if (pattern === undefined) {
  967. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  968. }
  969. return string.match(pattern) || [];
  970. }
  971.  
  972. /*------------------------------------------------------------------------*/
  973.  
  974. // Add methods that return wrapped values in chain sequences.
  975. lodash.words = words;
  976.  
  977. /*------------------------------------------------------------------------*/
  978.  
  979. // Add methods that return unwrapped values in chain sequences.
  980. lodash.camelCase = camelCase;
  981. lodash.capitalize = capitalize;
  982. lodash.deburr = deburr;
  983. lodash.isArray = isArray;
  984. lodash.isObjectLike = isObjectLike;
  985. lodash.isSymbol = isSymbol;
  986. lodash.kebabCase = kebabCase;
  987. lodash.snakeCase = snakeCase;
  988. lodash.toString = toString;
  989. lodash.upperFirst = upperFirst;
  990.  
  991. /*------------------------------------------------------------------------*/
  992.  
  993. /**
  994. * The semantic version number.
  995. *
  996. * @static
  997. * @memberOf _
  998. * @type {string}
  999. */
  1000. lodash.VERSION = VERSION;
  1001.  
  1002. /*--------------------------------------------------------------------------*/
  1003.  
  1004. // Some AMD build optimizers, like r.js, check for condition patterns like:
  1005. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  1006. // Expose Lodash on the global object to prevent errors when Lodash is
  1007. // loaded by a script tag in the presence of an AMD loader.
  1008. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  1009. // Use `_.noConflict` to remove Lodash from the global object.
  1010. root._ = lodash;
  1011.  
  1012. // Define as an anonymous module so, through path mapping, it can be
  1013. // referenced as the "underscore" module.
  1014. define(function () {
  1015. return lodash;
  1016. });
  1017. }
  1018. // Check for `exports` after `define` in case a build optimizer adds it.
  1019. else if (freeModule) {
  1020. // Export for Node.js.
  1021. (freeModule.exports = lodash)._ = lodash;
  1022. // Export for CommonJS support.
  1023. freeExports._ = lodash;
  1024. }
  1025. else {
  1026. // Export to the global object.
  1027. root._ = lodash;
  1028. }
  1029. }.call(this));
  1030.  
  1031. (function () {
  1032. main();
  1033. })();