blob: 4f35de61df4260c8873a1c88083be63ee1c994a9 [file] [log] [blame]
Danil Somsikov058b9d82024-10-07 11:22:191/**
2 * lodash (Custom Build) <https://lodash.com/>
3 * Build: `lodash modularize exports="npm" -o ./`
4 * Copyright jQuery Foundation and other contributors <https://jquery.org/>
5 * Released under MIT license <https://lodash.com/license>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8 */
9
10/** Used as references for various `Number` constants. */
11var INFINITY = 1 / 0;
12
13/** `Object#toString` result references. */
14var symbolTag = '[object Symbol]';
15
16/** Used to match Latin Unicode letters (excluding mathematical operators). */
17var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
18
19/** Used to compose unicode character classes. */
20var rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
21 rsComboSymbolsRange = '\\u20d0-\\u20f0';
22
23/** Used to compose unicode capture groups. */
24var rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']';
25
26/**
27 * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
28 * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
29 */
30var reComboMark = RegExp(rsCombo, 'g');
31
32/** Used to map Latin Unicode letters to basic Latin letters. */
33var deburredLetters = {
34 // Latin-1 Supplement block.
35 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
36 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
37 '\xc7': 'C', '\xe7': 'c',
38 '\xd0': 'D', '\xf0': 'd',
39 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
40 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
41 '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
42 '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
43 '\xd1': 'N', '\xf1': 'n',
44 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
45 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
46 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
47 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
48 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
49 '\xc6': 'Ae', '\xe6': 'ae',
50 '\xde': 'Th', '\xfe': 'th',
51 '\xdf': 'ss',
52 // Latin Extended-A block.
53 '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
54 '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
55 '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
56 '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
57 '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
58 '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
59 '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
60 '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
61 '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
62 '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
63 '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
64 '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
65 '\u0134': 'J', '\u0135': 'j',
66 '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
67 '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
68 '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
69 '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
70 '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
71 '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
72 '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
73 '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
74 '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
75 '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
76 '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
77 '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
78 '\u0163': 't', '\u0165': 't', '\u0167': 't',
79 '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
80 '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
81 '\u0174': 'W', '\u0175': 'w',
82 '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
83 '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
84 '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
85 '\u0132': 'IJ', '\u0133': 'ij',
86 '\u0152': 'Oe', '\u0153': 'oe',
87 '\u0149': "'n", '\u017f': 'ss'
88};
89
90/** Detect free variable `global` from Node.js. */
91var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
92
93/** Detect free variable `self`. */
94var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
95
96/** Used as a reference to the global object. */
97var root = freeGlobal || freeSelf || Function('return this')();
98
99/**
100 * The base implementation of `_.propertyOf` without support for deep paths.
101 *
102 * @private
103 * @param {Object} object The object to query.
104 * @returns {Function} Returns the new accessor function.
105 */
106function basePropertyOf(object) {
107 return function(key) {
108 return object == null ? undefined : object[key];
109 };
110}
111
112/**
113 * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
114 * letters to basic Latin letters.
115 *
116 * @private
117 * @param {string} letter The matched letter to deburr.
118 * @returns {string} Returns the deburred letter.
119 */
120var deburrLetter = basePropertyOf(deburredLetters);
121
122/** Used for built-in method references. */
123var objectProto = Object.prototype;
124
125/**
126 * Used to resolve the
127 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
128 * of values.
129 */
130var objectToString = objectProto.toString;
131
132/** Built-in value references. */
133var Symbol = root.Symbol;
134
135/** Used to convert symbols to primitives and strings. */
136var symbolProto = Symbol ? Symbol.prototype : undefined,
137 symbolToString = symbolProto ? symbolProto.toString : undefined;
138
139/**
140 * The base implementation of `_.toString` which doesn't convert nullish
141 * values to empty strings.
142 *
143 * @private
144 * @param {*} value The value to process.
145 * @returns {string} Returns the string.
146 */
147function baseToString(value) {
148 // Exit early for strings to avoid a performance hit in some environments.
149 if (typeof value == 'string') {
150 return value;
151 }
152 if (isSymbol(value)) {
153 return symbolToString ? symbolToString.call(value) : '';
154 }
155 var result = (value + '');
156 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
157}
158
159/**
160 * Checks if `value` is object-like. A value is object-like if it's not `null`
161 * and has a `typeof` result of "object".
162 *
163 * @static
164 * @memberOf _
165 * @since 4.0.0
166 * @category Lang
167 * @param {*} value The value to check.
168 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
169 * @example
170 *
171 * _.isObjectLike({});
172 * // => true
173 *
174 * _.isObjectLike([1, 2, 3]);
175 * // => true
176 *
177 * _.isObjectLike(_.noop);
178 * // => false
179 *
180 * _.isObjectLike(null);
181 * // => false
182 */
183function isObjectLike(value) {
184 return !!value && typeof value == 'object';
185}
186
187/**
188 * Checks if `value` is classified as a `Symbol` primitive or object.
189 *
190 * @static
191 * @memberOf _
192 * @since 4.0.0
193 * @category Lang
194 * @param {*} value The value to check.
195 * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
196 * @example
197 *
198 * _.isSymbol(Symbol.iterator);
199 * // => true
200 *
201 * _.isSymbol('abc');
202 * // => false
203 */
204function isSymbol(value) {
205 return typeof value == 'symbol' ||
206 (isObjectLike(value) && objectToString.call(value) == symbolTag);
207}
208
209/**
210 * Converts `value` to a string. An empty string is returned for `null`
211 * and `undefined` values. The sign of `-0` is preserved.
212 *
213 * @static
214 * @memberOf _
215 * @since 4.0.0
216 * @category Lang
217 * @param {*} value The value to process.
218 * @returns {string} Returns the string.
219 * @example
220 *
221 * _.toString(null);
222 * // => ''
223 *
224 * _.toString(-0);
225 * // => '-0'
226 *
227 * _.toString([1, 2, 3]);
228 * // => '1,2,3'
229 */
230function toString(value) {
231 return value == null ? '' : baseToString(value);
232}
233
234/**
235 * Deburrs `string` by converting
236 * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
237 * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
238 * letters to basic Latin letters and removing
239 * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
240 *
241 * @static
242 * @memberOf _
243 * @since 3.0.0
244 * @category String
245 * @param {string} [string=''] The string to deburr.
246 * @returns {string} Returns the deburred string.
247 * @example
248 *
249 * _.deburr('déjà vu');
250 * // => 'deja vu'
251 */
252function deburr(string) {
253 string = toString(string);
254 return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
255}
256
257module.exports = deburr;