1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.cyrillicToTranslit = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
2 | ;
|
3 |
|
4 | module.exports = function cyrillicToTranslit(config) {
|
5 | const invert = require('lodash.invert');
|
6 | const _preset = config ? config.preset : "ru";
|
7 |
|
8 | /*
|
9 | ASSOCIATIONS FOR INITIAL POSITION
|
10 | */
|
11 |
|
12 | // letters shared between languages
|
13 | const _firstLetters = {
|
14 | "а": "a",
|
15 | "б": "b",
|
16 | "в": "v",
|
17 | "д": "d",
|
18 | "з": "z",
|
19 | "й": "y",
|
20 | "к": "k",
|
21 | "л": "l",
|
22 | "м": "m",
|
23 | "н": "n",
|
24 | "о": "o",
|
25 | "п": "p",
|
26 | "р": "r",
|
27 | "с": "s",
|
28 | "т": "t",
|
29 | "у": "u",
|
30 | "ф": "f",
|
31 | "ь": ""
|
32 | };
|
33 |
|
34 | // language-specific letters
|
35 | if (_preset === "ru") {
|
36 | Object.assign(_firstLetters, {
|
37 | "г": "g",
|
38 | "и": "i",
|
39 | "ъ": "",
|
40 | "ы": "i",
|
41 | "э": "e",
|
42 | });
|
43 | } else if (_preset === "uk") {
|
44 | Object.assign(_firstLetters, {
|
45 | "г": "h",
|
46 | "ґ": "g",
|
47 | "е": "e",
|
48 | "и": "y",
|
49 | "і": "i",
|
50 | "'": "",
|
51 | "’": "",
|
52 | "ʼ": "",
|
53 | })
|
54 | }
|
55 |
|
56 | let _reversedFirstLetters;
|
57 | if (_preset === "ru") {
|
58 | // Russian: i > always и, y > й in initial position, e > э in initial position
|
59 | _reversedFirstLetters = Object.assign(invert(_firstLetters), { "i": "и", "": "" });
|
60 | } else if (_preset === "uk") {
|
61 | // Ukrainian: i > always i, y > always и, e > always е
|
62 | _reversedFirstLetters = Object.assign(invert(_firstLetters), { "": "" });
|
63 | }
|
64 |
|
65 | // digraphs appearing only in initial position
|
66 | const _initialDigraphs = (_preset === "ru") ? { "е": "ye" } : { "є": "ye", "ї": "yi" };
|
67 |
|
68 | // digraphs appearing in all positions
|
69 | const _regularDigraphs = {
|
70 | "ё": "yo",
|
71 | "ж": "zh",
|
72 | "х": "kh",
|
73 | "ц": "ts",
|
74 | "ч": "ch",
|
75 | "ш": "sh",
|
76 | "щ": "shch",
|
77 | "ю": "yu",
|
78 | "я": "ya",
|
79 | }
|
80 |
|
81 | const _firstDigraphs = Object.assign({}, _regularDigraphs, _initialDigraphs);
|
82 |
|
83 | const _reversedFirstDigraphs = Object.assign(invert(_firstDigraphs));
|
84 |
|
85 | const _firstAssociations = Object.assign(_firstLetters, _firstDigraphs);
|
86 |
|
87 | /*
|
88 | ASSOCIATIONS FOR NON-INITIAL POSITION
|
89 | */
|
90 |
|
91 | const _nonFirstLetters = Object.assign({}, _firstLetters, { "й": "i" });
|
92 | if (_preset === "ru") {
|
93 | Object.assign(_nonFirstLetters, { "е": "e" });
|
94 | } else if (_preset === "uk") {
|
95 | Object.assign(_nonFirstLetters, { "ї": "i" });
|
96 | }
|
97 |
|
98 | let _reversedNonFirstLetters;
|
99 | if (_preset === "ru") {
|
100 | // Russian: i > always и, y > ы in non-initial position, e > е in non-initial position
|
101 | _reversedNonFirstLetters = Object.assign(invert(_firstLetters), {
|
102 | "i": "и",
|
103 | "y": "ы",
|
104 | "e": "е",
|
105 | "": ""
|
106 | });
|
107 | } else if (_preset === "uk") {
|
108 | // Ukrainian: i > always i, y > always и, e > always е
|
109 | _reversedNonFirstLetters = Object.assign(invert(_firstLetters), { "": "" });
|
110 | }
|
111 |
|
112 | // digraphs appearing only in non-initial positions
|
113 | let _nonInitialDigraphs = {};
|
114 | if (_preset === "uk") {
|
115 | _nonInitialDigraphs = {
|
116 | "є": "ie",
|
117 | "ю": "iu",
|
118 | "я": "ia",
|
119 | };
|
120 | }
|
121 |
|
122 | const _nonFirstDigraphs = Object.assign(_regularDigraphs, _nonInitialDigraphs);
|
123 |
|
124 | const _reversedNonFirstDigraphs = Object.assign(invert(_nonFirstDigraphs));
|
125 |
|
126 | const _nonFirstAssociations = Object.assign(_nonFirstLetters, _nonFirstDigraphs);
|
127 |
|
128 |
|
129 | function transform(input, spaceReplacement) {
|
130 | if (!input) {
|
131 | return "";
|
132 | }
|
133 |
|
134 | // We must normalize string for transform all unicode chars to uniform form
|
135 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize
|
136 | const normalizedInput = input.normalize();
|
137 |
|
138 | let newStr = "";
|
139 | let isWordBoundary = false;
|
140 |
|
141 | for (let i = 0; i < normalizedInput.length; i++) {
|
142 | const isUpperCaseOrWhatever = normalizedInput[i] === normalizedInput[i].toUpperCase();
|
143 | let strLowerCase = normalizedInput[i].toLowerCase();
|
144 |
|
145 | if (strLowerCase === " ") {
|
146 | newStr += spaceReplacement ? spaceReplacement : " ";
|
147 | isWordBoundary = true;
|
148 | continue;
|
149 | }
|
150 |
|
151 | let newLetter;
|
152 |
|
153 | if ( _preset === "uk" && normalizedInput.slice(i-1, i+1).toLowerCase() === "зг") {
|
154 | // handle ukrainian special case зг > zgh
|
155 | newLetter = "gh";
|
156 | } else if (i === 0 || isWordBoundary) {
|
157 | newLetter = _firstAssociations[strLowerCase];
|
158 | isWordBoundary = false;
|
159 | } else {
|
160 | newLetter = _nonFirstAssociations[strLowerCase];
|
161 | }
|
162 |
|
163 | if ("undefined" === typeof newLetter) {
|
164 | newStr += isUpperCaseOrWhatever ? strLowerCase.toUpperCase() : strLowerCase;
|
165 | } else if (isUpperCaseOrWhatever) {
|
166 | // handle multi-symbol letters
|
167 | newLetter.length > 1
|
168 | ? newStr += newLetter[0].toUpperCase() + newLetter.slice(1)
|
169 | : newStr += newLetter.toUpperCase();
|
170 | } else {
|
171 | newStr += newLetter;
|
172 | }
|
173 | }
|
174 | return newStr;
|
175 | }
|
176 |
|
177 | function reverse(input, spaceReplacement) {
|
178 |
|
179 | if (!input) return "";
|
180 |
|
181 | const normalizedInput = input.normalize();
|
182 |
|
183 | let newStr = "";
|
184 | let isWordBoundary = false;
|
185 | let i = 0;
|
186 |
|
187 | while (i < normalizedInput.length) {
|
188 | const isUpperCaseOrWhatever = normalizedInput[i] === normalizedInput[i].toUpperCase();
|
189 | let strLowerCase = normalizedInput[i].toLowerCase();
|
190 | let currentIndex = i;
|
191 |
|
192 | if (strLowerCase === " " || strLowerCase === spaceReplacement) {
|
193 | newStr += " ";
|
194 | isWordBoundary = true;
|
195 | i++;
|
196 | continue;
|
197 | }
|
198 |
|
199 | let newLetter;
|
200 |
|
201 | let digraph = normalizedInput.slice(i, i + 2).toLowerCase();
|
202 | if (i === 0 || isWordBoundary) {
|
203 | newLetter = _reversedFirstDigraphs[digraph];
|
204 | if (newLetter) {
|
205 | i += 2;
|
206 | } else {
|
207 | newLetter = _reversedFirstLetters[strLowerCase];
|
208 | i++;
|
209 | }
|
210 | isWordBoundary = false;
|
211 | } else {
|
212 | newLetter = _reversedNonFirstDigraphs[digraph];
|
213 | if (newLetter) {
|
214 | i += 2;
|
215 | } else {
|
216 | newLetter = _reversedNonFirstLetters[strLowerCase];
|
217 | i++;
|
218 | }
|
219 | }
|
220 |
|
221 | // special cases: щ and зг
|
222 | if (normalizedInput.slice(currentIndex, currentIndex + 4).toLowerCase() === "shch") {
|
223 | newLetter = "щ";
|
224 | i = currentIndex + 4;
|
225 | } else if (normalizedInput.slice(currentIndex - 1, currentIndex + 2).toLowerCase() === "zgh") {
|
226 | newLetter = "г";
|
227 | i = currentIndex + 2;
|
228 | }
|
229 |
|
230 | if ("undefined" === typeof newLetter) {
|
231 | newStr += isUpperCaseOrWhatever ? strLowerCase.toUpperCase() : strLowerCase;
|
232 | }
|
233 | else {
|
234 | if (isUpperCaseOrWhatever) {
|
235 | // handle multi-symbol letters
|
236 | newLetter.length > 1
|
237 | ? newStr += newLetter[0].toUpperCase() + newLetter.slice(1)
|
238 | : newStr += newLetter.toUpperCase();
|
239 | } else {
|
240 | newStr += newLetter;
|
241 | }
|
242 | }
|
243 | }
|
244 |
|
245 | return newStr;
|
246 | }
|
247 |
|
248 | return {
|
249 | transform: transform,
|
250 | reverse: reverse
|
251 | };
|
252 | };
|
253 |
|
254 | },{"lodash.invert":2}],2:[function(require,module,exports){
|
255 | /**
|
256 | * lodash (Custom Build) <https://lodash.com/>
|
257 | * Build: `lodash modularize exports="npm" -o ./`
|
258 | * Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
259 | * Released under MIT license <https://lodash.com/license>
|
260 | * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
261 | * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
262 | */
|
263 |
|
264 | /** Used as references for various `Number` constants. */
|
265 | var MAX_SAFE_INTEGER = 9007199254740991;
|
266 |
|
267 | /** `Object#toString` result references. */
|
268 | var argsTag = '[object Arguments]',
|
269 | funcTag = '[object Function]',
|
270 | genTag = '[object GeneratorFunction]';
|
271 |
|
272 | /** Used to detect unsigned integer values. */
|
273 | var reIsUint = /^(?:0|[1-9]\d*)$/;
|
274 |
|
275 | /**
|
276 | * The base implementation of `_.times` without support for iteratee shorthands
|
277 | * or max array length checks.
|
278 | *
|
279 | * @private
|
280 | * @param {number} n The number of times to invoke `iteratee`.
|
281 | * @param {Function} iteratee The function invoked per iteration.
|
282 | * @returns {Array} Returns the array of results.
|
283 | */
|
284 | function baseTimes(n, iteratee) {
|
285 | var index = -1,
|
286 | result = Array(n);
|
287 |
|
288 | while (++index < n) {
|
289 | result[index] = iteratee(index);
|
290 | }
|
291 | return result;
|
292 | }
|
293 |
|
294 | /**
|
295 | * Creates a unary function that invokes `func` with its argument transformed.
|
296 | *
|
297 | * @private
|
298 | * @param {Function} func The function to wrap.
|
299 | * @param {Function} transform The argument transform.
|
300 | * @returns {Function} Returns the new function.
|
301 | */
|
302 | function overArg(func, transform) {
|
303 | return function(arg) {
|
304 | return func(transform(arg));
|
305 | };
|
306 | }
|
307 |
|
308 | /** Used for built-in method references. */
|
309 | var objectProto = Object.prototype;
|
310 |
|
311 | /** Used to check objects for own properties. */
|
312 | var hasOwnProperty = objectProto.hasOwnProperty;
|
313 |
|
314 | /**
|
315 | * Used to resolve the
|
316 | * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
317 | * of values.
|
318 | */
|
319 | var objectToString = objectProto.toString;
|
320 |
|
321 | /** Built-in value references. */
|
322 | var propertyIsEnumerable = objectProto.propertyIsEnumerable;
|
323 |
|
324 | /* Built-in method references for those with the same name as other `lodash` methods. */
|
325 | var nativeKeys = overArg(Object.keys, Object);
|
326 |
|
327 | /**
|
328 | * Creates an array of the enumerable property names of the array-like `value`.
|
329 | *
|
330 | * @private
|
331 | * @param {*} value The value to query.
|
332 | * @param {boolean} inherited Specify returning inherited property names.
|
333 | * @returns {Array} Returns the array of property names.
|
334 | */
|
335 | function arrayLikeKeys(value, inherited) {
|
336 | // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
|
337 | // Safari 9 makes `arguments.length` enumerable in strict mode.
|
338 | var result = (isArray(value) || isArguments(value))
|
339 | ? baseTimes(value.length, String)
|
340 | : [];
|
341 |
|
342 | var length = result.length,
|
343 | skipIndexes = !!length;
|
344 |
|
345 | for (var key in value) {
|
346 | if ((inherited || hasOwnProperty.call(value, key)) &&
|
347 | !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
|
348 | result.push(key);
|
349 | }
|
350 | }
|
351 | return result;
|
352 | }
|
353 |
|
354 | /**
|
355 | * The base implementation of `baseForOwn` which iterates over `object`
|
356 | * properties returned by `keysFunc` and invokes `iteratee` for each property.
|
357 | * Iteratee functions may exit iteration early by explicitly returning `false`.
|
358 | *
|
359 | * @private
|
360 | * @param {Object} object The object to iterate over.
|
361 | * @param {Function} iteratee The function invoked per iteration.
|
362 | * @param {Function} keysFunc The function to get the keys of `object`.
|
363 | * @returns {Object} Returns `object`.
|
364 | */
|
365 | var baseFor = createBaseFor();
|
366 |
|
367 | /**
|
368 | * The base implementation of `_.forOwn` without support for iteratee shorthands.
|
369 | *
|
370 | * @private
|
371 | * @param {Object} object The object to iterate over.
|
372 | * @param {Function} iteratee The function invoked per iteration.
|
373 | * @returns {Object} Returns `object`.
|
374 | */
|
375 | function baseForOwn(object, iteratee) {
|
376 | return object && baseFor(object, iteratee, keys);
|
377 | }
|
378 |
|
379 | /**
|
380 | * The base implementation of `_.invert` and `_.invertBy` which inverts
|
381 | * `object` with values transformed by `iteratee` and set by `setter`.
|
382 | *
|
383 | * @private
|
384 | * @param {Object} object The object to iterate over.
|
385 | * @param {Function} setter The function to set `accumulator` values.
|
386 | * @param {Function} iteratee The iteratee to transform values.
|
387 | * @param {Object} accumulator The initial inverted object.
|
388 | * @returns {Function} Returns `accumulator`.
|
389 | */
|
390 | function baseInverter(object, setter, iteratee, accumulator) {
|
391 | baseForOwn(object, function(value, key, object) {
|
392 | setter(accumulator, iteratee(value), key, object);
|
393 | });
|
394 | return accumulator;
|
395 | }
|
396 |
|
397 | /**
|
398 | * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
|
399 | *
|
400 | * @private
|
401 | * @param {Object} object The object to query.
|
402 | * @returns {Array} Returns the array of property names.
|
403 | */
|
404 | function baseKeys(object) {
|
405 | if (!isPrototype(object)) {
|
406 | return nativeKeys(object);
|
407 | }
|
408 | var result = [];
|
409 | for (var key in Object(object)) {
|
410 | if (hasOwnProperty.call(object, key) && key != 'constructor') {
|
411 | result.push(key);
|
412 | }
|
413 | }
|
414 | return result;
|
415 | }
|
416 |
|
417 | /**
|
418 | * Creates a base function for methods like `_.forIn` and `_.forOwn`.
|
419 | *
|
420 | * @private
|
421 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
422 | * @returns {Function} Returns the new base function.
|
423 | */
|
424 | function createBaseFor(fromRight) {
|
425 | return function(object, iteratee, keysFunc) {
|
426 | var index = -1,
|
427 | iterable = Object(object),
|
428 | props = keysFunc(object),
|
429 | length = props.length;
|
430 |
|
431 | while (length--) {
|
432 | var key = props[fromRight ? length : ++index];
|
433 | if (iteratee(iterable[key], key, iterable) === false) {
|
434 | break;
|
435 | }
|
436 | }
|
437 | return object;
|
438 | };
|
439 | }
|
440 |
|
441 | /**
|
442 | * Creates a function like `_.invertBy`.
|
443 | *
|
444 | * @private
|
445 | * @param {Function} setter The function to set accumulator values.
|
446 | * @param {Function} toIteratee The function to resolve iteratees.
|
447 | * @returns {Function} Returns the new inverter function.
|
448 | */
|
449 | function createInverter(setter, toIteratee) {
|
450 | return function(object, iteratee) {
|
451 | return baseInverter(object, setter, toIteratee(iteratee), {});
|
452 | };
|
453 | }
|
454 |
|
455 | /**
|
456 | * Checks if `value` is a valid array-like index.
|
457 | *
|
458 | * @private
|
459 | * @param {*} value The value to check.
|
460 | * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
|
461 | * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
462 | */
|
463 | function isIndex(value, length) {
|
464 | length = length == null ? MAX_SAFE_INTEGER : length;
|
465 | return !!length &&
|
466 | (typeof value == 'number' || reIsUint.test(value)) &&
|
467 | (value > -1 && value % 1 == 0 && value < length);
|
468 | }
|
469 |
|
470 | /**
|
471 | * Checks if `value` is likely a prototype object.
|
472 | *
|
473 | * @private
|
474 | * @param {*} value The value to check.
|
475 | * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
|
476 | */
|
477 | function isPrototype(value) {
|
478 | var Ctor = value && value.constructor,
|
479 | proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
|
480 |
|
481 | return value === proto;
|
482 | }
|
483 |
|
484 | /**
|
485 | * Checks if `value` is likely an `arguments` object.
|
486 | *
|
487 | * @static
|
488 | * @memberOf _
|
489 | * @since 0.1.0
|
490 | * @category Lang
|
491 | * @param {*} value The value to check.
|
492 | * @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
493 | * else `false`.
|
494 | * @example
|
495 | *
|
496 | * _.isArguments(function() { return arguments; }());
|
497 | * // => true
|
498 | *
|
499 | * _.isArguments([1, 2, 3]);
|
500 | * // => false
|
501 | */
|
502 | function isArguments(value) {
|
503 | // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
|
504 | return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
|
505 | (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
|
506 | }
|
507 |
|
508 | /**
|
509 | * Checks if `value` is classified as an `Array` object.
|
510 | *
|
511 | * @static
|
512 | * @memberOf _
|
513 | * @since 0.1.0
|
514 | * @category Lang
|
515 | * @param {*} value The value to check.
|
516 | * @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
517 | * @example
|
518 | *
|
519 | * _.isArray([1, 2, 3]);
|
520 | * // => true
|
521 | *
|
522 | * _.isArray(document.body.children);
|
523 | * // => false
|
524 | *
|
525 | * _.isArray('abc');
|
526 | * // => false
|
527 | *
|
528 | * _.isArray(_.noop);
|
529 | * // => false
|
530 | */
|
531 | var isArray = Array.isArray;
|
532 |
|
533 | /**
|
534 | * Checks if `value` is array-like. A value is considered array-like if it's
|
535 | * not a function and has a `value.length` that's an integer greater than or
|
536 | * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
|
537 | *
|
538 | * @static
|
539 | * @memberOf _
|
540 | * @since 4.0.0
|
541 | * @category Lang
|
542 | * @param {*} value The value to check.
|
543 | * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
544 | * @example
|
545 | *
|
546 | * _.isArrayLike([1, 2, 3]);
|
547 | * // => true
|
548 | *
|
549 | * _.isArrayLike(document.body.children);
|
550 | * // => true
|
551 | *
|
552 | * _.isArrayLike('abc');
|
553 | * // => true
|
554 | *
|
555 | * _.isArrayLike(_.noop);
|
556 | * // => false
|
557 | */
|
558 | function isArrayLike(value) {
|
559 | return value != null && isLength(value.length) && !isFunction(value);
|
560 | }
|
561 |
|
562 | /**
|
563 | * This method is like `_.isArrayLike` except that it also checks if `value`
|
564 | * is an object.
|
565 | *
|
566 | * @static
|
567 | * @memberOf _
|
568 | * @since 4.0.0
|
569 | * @category Lang
|
570 | * @param {*} value The value to check.
|
571 | * @returns {boolean} Returns `true` if `value` is an array-like object,
|
572 | * else `false`.
|
573 | * @example
|
574 | *
|
575 | * _.isArrayLikeObject([1, 2, 3]);
|
576 | * // => true
|
577 | *
|
578 | * _.isArrayLikeObject(document.body.children);
|
579 | * // => true
|
580 | *
|
581 | * _.isArrayLikeObject('abc');
|
582 | * // => false
|
583 | *
|
584 | * _.isArrayLikeObject(_.noop);
|
585 | * // => false
|
586 | */
|
587 | function isArrayLikeObject(value) {
|
588 | return isObjectLike(value) && isArrayLike(value);
|
589 | }
|
590 |
|
591 | /**
|
592 | * Checks if `value` is classified as a `Function` object.
|
593 | *
|
594 | * @static
|
595 | * @memberOf _
|
596 | * @since 0.1.0
|
597 | * @category Lang
|
598 | * @param {*} value The value to check.
|
599 | * @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
600 | * @example
|
601 | *
|
602 | * _.isFunction(_);
|
603 | * // => true
|
604 | *
|
605 | * _.isFunction(/abc/);
|
606 | * // => false
|
607 | */
|
608 | function isFunction(value) {
|
609 | // The use of `Object#toString` avoids issues with the `typeof` operator
|
610 | // in Safari 8-9 which returns 'object' for typed array and other constructors.
|
611 | var tag = isObject(value) ? objectToString.call(value) : '';
|
612 | return tag == funcTag || tag == genTag;
|
613 | }
|
614 |
|
615 | /**
|
616 | * Checks if `value` is a valid array-like length.
|
617 | *
|
618 | * **Note:** This method is loosely based on
|
619 | * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
620 | *
|
621 | * @static
|
622 | * @memberOf _
|
623 | * @since 4.0.0
|
624 | * @category Lang
|
625 | * @param {*} value The value to check.
|
626 | * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
627 | * @example
|
628 | *
|
629 | * _.isLength(3);
|
630 | * // => true
|
631 | *
|
632 | * _.isLength(Number.MIN_VALUE);
|
633 | * // => false
|
634 | *
|
635 | * _.isLength(Infinity);
|
636 | * // => false
|
637 | *
|
638 | * _.isLength('3');
|
639 | * // => false
|
640 | */
|
641 | function isLength(value) {
|
642 | return typeof value == 'number' &&
|
643 | value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
644 | }
|
645 |
|
646 | /**
|
647 | * Checks if `value` is the
|
648 | * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
649 | * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
650 | *
|
651 | * @static
|
652 | * @memberOf _
|
653 | * @since 0.1.0
|
654 | * @category Lang
|
655 | * @param {*} value The value to check.
|
656 | * @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
657 | * @example
|
658 | *
|
659 | * _.isObject({});
|
660 | * // => true
|
661 | *
|
662 | * _.isObject([1, 2, 3]);
|
663 | * // => true
|
664 | *
|
665 | * _.isObject(_.noop);
|
666 | * // => true
|
667 | *
|
668 | * _.isObject(null);
|
669 | * // => false
|
670 | */
|
671 | function isObject(value) {
|
672 | var type = typeof value;
|
673 | return !!value && (type == 'object' || type == 'function');
|
674 | }
|
675 |
|
676 | /**
|
677 | * Checks if `value` is object-like. A value is object-like if it's not `null`
|
678 | * and has a `typeof` result of "object".
|
679 | *
|
680 | * @static
|
681 | * @memberOf _
|
682 | * @since 4.0.0
|
683 | * @category Lang
|
684 | * @param {*} value The value to check.
|
685 | * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
686 | * @example
|
687 | *
|
688 | * _.isObjectLike({});
|
689 | * // => true
|
690 | *
|
691 | * _.isObjectLike([1, 2, 3]);
|
692 | * // => true
|
693 | *
|
694 | * _.isObjectLike(_.noop);
|
695 | * // => false
|
696 | *
|
697 | * _.isObjectLike(null);
|
698 | * // => false
|
699 | */
|
700 | function isObjectLike(value) {
|
701 | return !!value && typeof value == 'object';
|
702 | }
|
703 |
|
704 | /**
|
705 | * Creates an object composed of the inverted keys and values of `object`.
|
706 | * If `object` contains duplicate values, subsequent values overwrite
|
707 | * property assignments of previous values.
|
708 | *
|
709 | * @static
|
710 | * @memberOf _
|
711 | * @since 0.7.0
|
712 | * @category Object
|
713 | * @param {Object} object The object to invert.
|
714 | * @returns {Object} Returns the new inverted object.
|
715 | * @example
|
716 | *
|
717 | * var object = { 'a': 1, 'b': 2, 'c': 1 };
|
718 | *
|
719 | * _.invert(object);
|
720 | * // => { '1': 'c', '2': 'b' }
|
721 | */
|
722 | var invert = createInverter(function(result, value, key) {
|
723 | result[value] = key;
|
724 | }, constant(identity));
|
725 |
|
726 | /**
|
727 | * Creates an array of the own enumerable property names of `object`.
|
728 | *
|
729 | * **Note:** Non-object values are coerced to objects. See the
|
730 | * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
|
731 | * for more details.
|
732 | *
|
733 | * @static
|
734 | * @since 0.1.0
|
735 | * @memberOf _
|
736 | * @category Object
|
737 | * @param {Object} object The object to query.
|
738 | * @returns {Array} Returns the array of property names.
|
739 | * @example
|
740 | *
|
741 | * function Foo() {
|
742 | * this.a = 1;
|
743 | * this.b = 2;
|
744 | * }
|
745 | *
|
746 | * Foo.prototype.c = 3;
|
747 | *
|
748 | * _.keys(new Foo);
|
749 | * // => ['a', 'b'] (iteration order is not guaranteed)
|
750 | *
|
751 | * _.keys('hi');
|
752 | * // => ['0', '1']
|
753 | */
|
754 | function keys(object) {
|
755 | return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
|
756 | }
|
757 |
|
758 | /**
|
759 | * Creates a function that returns `value`.
|
760 | *
|
761 | * @static
|
762 | * @memberOf _
|
763 | * @since 2.4.0
|
764 | * @category Util
|
765 | * @param {*} value The value to return from the new function.
|
766 | * @returns {Function} Returns the new constant function.
|
767 | * @example
|
768 | *
|
769 | * var objects = _.times(2, _.constant({ 'a': 1 }));
|
770 | *
|
771 | * console.log(objects);
|
772 | * // => [{ 'a': 1 }, { 'a': 1 }]
|
773 | *
|
774 | * console.log(objects[0] === objects[1]);
|
775 | * // => true
|
776 | */
|
777 | function constant(value) {
|
778 | return function() {
|
779 | return value;
|
780 | };
|
781 | }
|
782 |
|
783 | /**
|
784 | * This method returns the first argument it receives.
|
785 | *
|
786 | * @static
|
787 | * @since 0.1.0
|
788 | * @memberOf _
|
789 | * @category Util
|
790 | * @param {*} value Any value.
|
791 | * @returns {*} Returns `value`.
|
792 | * @example
|
793 | *
|
794 | * var object = { 'a': 1 };
|
795 | *
|
796 | * console.log(_.identity(object) === object);
|
797 | * // => true
|
798 | */
|
799 | function identity(value) {
|
800 | return value;
|
801 | }
|
802 |
|
803 | module.exports = invert;
|
804 |
|
805 | },{}]},{},[1])(1)
|
806 | });
|