@react-aria/i18n 3.3.4 → 3.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +234 -266
- package/dist/main.js.map +1 -1
- package/dist/module.js +224 -236
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/main.js
CHANGED
|
@@ -1,39 +1,35 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
MessageDictionary,
|
|
13
|
-
MessageFormatter
|
|
14
|
-
} = require("@internationalized/message");
|
|
15
|
-
|
|
16
|
-
var {
|
|
17
|
-
useIsSSR
|
|
18
|
-
} = require("@react-aria/ssr");
|
|
19
|
-
|
|
20
|
-
var _react2 = require("react");
|
|
21
|
-
|
|
22
|
-
var _react = $parcel$interopDefault(_react2);
|
|
1
|
+
var $87SwK$react = require("react");
|
|
2
|
+
var $87SwK$reactariassr = require("@react-aria/ssr");
|
|
3
|
+
var $87SwK$internationalizedmessage = require("@internationalized/message");
|
|
4
|
+
var $87SwK$internationalizeddate = require("@internationalized/date");
|
|
5
|
+
var $87SwK$internationalizednumber = require("@internationalized/number");
|
|
6
|
+
|
|
7
|
+
function $parcel$exportWildcard(dest, source) {
|
|
8
|
+
Object.keys(source).forEach(function(key) {
|
|
9
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
23
12
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
} = _react2;
|
|
13
|
+
Object.defineProperty(dest, key, {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return source[key];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
32
20
|
|
|
21
|
+
return dest;
|
|
22
|
+
}
|
|
33
23
|
function $parcel$interopDefault(a) {
|
|
34
24
|
return a && a.__esModule ? a.default : a;
|
|
35
25
|
}
|
|
26
|
+
function $parcel$export(e, n, v, s) {
|
|
27
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
28
|
+
}
|
|
29
|
+
var $47fa5ec5ff482271$exports = {};
|
|
36
30
|
|
|
31
|
+
$parcel$export($47fa5ec5ff482271$exports, "I18nProvider", () => $47fa5ec5ff482271$export$a54013f0d02a8f82);
|
|
32
|
+
$parcel$export($47fa5ec5ff482271$exports, "useLocale", () => $47fa5ec5ff482271$export$43bb16f9c6d9e3f7);
|
|
37
33
|
/*
|
|
38
34
|
* Copyright 2020 Adobe. All rights reserved.
|
|
39
35
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -44,284 +40,256 @@ function $parcel$interopDefault(a) {
|
|
|
44
40
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
45
41
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
46
42
|
* governing permissions and limitations under the License.
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
43
|
+
*/ // https://en.wikipedia.org/wiki/Right-to-left
|
|
44
|
+
const $4d65847630a056a8$var$RTL_SCRIPTS = new Set([
|
|
45
|
+
'Arab',
|
|
46
|
+
'Syrc',
|
|
47
|
+
'Samr',
|
|
48
|
+
'Mand',
|
|
49
|
+
'Thaa',
|
|
50
|
+
'Mend',
|
|
51
|
+
'Nkoo',
|
|
52
|
+
'Adlm',
|
|
53
|
+
'Rohg',
|
|
54
|
+
'Hebr'
|
|
55
|
+
]);
|
|
56
|
+
const $4d65847630a056a8$var$RTL_LANGS = new Set([
|
|
57
|
+
'ae',
|
|
58
|
+
'ar',
|
|
59
|
+
'arc',
|
|
60
|
+
'bcc',
|
|
61
|
+
'bqi',
|
|
62
|
+
'ckb',
|
|
63
|
+
'dv',
|
|
64
|
+
'fa',
|
|
65
|
+
'glk',
|
|
66
|
+
'he',
|
|
67
|
+
'ku',
|
|
68
|
+
'mzn',
|
|
69
|
+
'nqo',
|
|
70
|
+
'pnb',
|
|
71
|
+
'ps',
|
|
72
|
+
'sd',
|
|
73
|
+
'ug',
|
|
74
|
+
'ur',
|
|
75
|
+
'yi'
|
|
76
|
+
]);
|
|
77
|
+
function $4d65847630a056a8$export$702d680b21cbd764(locale) {
|
|
78
|
+
// If the Intl.Locale API is available, use it to get the script for the locale.
|
|
79
|
+
// This is more accurate than guessing by language, since languages can be written in multiple scripts.
|
|
60
80
|
// @ts-ignore
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
81
|
+
if (Intl.Locale) {
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
let script = new Intl.Locale(locale).maximize().script;
|
|
84
|
+
return $4d65847630a056a8$var$RTL_SCRIPTS.has(script);
|
|
85
|
+
}
|
|
86
|
+
// If not, just guess by the language (first part of the locale)
|
|
87
|
+
let lang = locale.split('-')[0];
|
|
88
|
+
return $4d65847630a056a8$var$RTL_LANGS.has(lang);
|
|
89
|
+
}
|
|
64
90
|
|
|
65
91
|
|
|
66
|
-
let lang = locale.split('-')[0];
|
|
67
|
-
return $dbb62b32f79d03a795a46f9fbec514c$var$RTL_LANGS.has(lang);
|
|
68
|
-
}
|
|
69
92
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
function $2919bdec75484e64$export$f09106e7c6677ec5() {
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
let locale = typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage) || 'en-US';
|
|
98
|
+
return {
|
|
99
|
+
locale: locale,
|
|
100
|
+
direction: $4d65847630a056a8$export$702d680b21cbd764(locale) ? 'rtl' : 'ltr'
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
let $2919bdec75484e64$var$currentLocale = $2919bdec75484e64$export$f09106e7c6677ec5();
|
|
104
|
+
let $2919bdec75484e64$var$listeners = new Set();
|
|
105
|
+
function $2919bdec75484e64$var$updateLocale() {
|
|
106
|
+
$2919bdec75484e64$var$currentLocale = $2919bdec75484e64$export$f09106e7c6677ec5();
|
|
107
|
+
for (let listener of $2919bdec75484e64$var$listeners)listener($2919bdec75484e64$var$currentLocale);
|
|
108
|
+
}
|
|
109
|
+
function $2919bdec75484e64$export$188ec29ebc2bdc3a() {
|
|
110
|
+
let isSSR = $87SwK$reactariassr.useIsSSR();
|
|
111
|
+
let [defaultLocale, setDefaultLocale] = $87SwK$react.useState($2919bdec75484e64$var$currentLocale);
|
|
112
|
+
$87SwK$react.useEffect(()=>{
|
|
113
|
+
if ($2919bdec75484e64$var$listeners.size === 0) window.addEventListener('languagechange', $2919bdec75484e64$var$updateLocale);
|
|
114
|
+
$2919bdec75484e64$var$listeners.add(setDefaultLocale);
|
|
115
|
+
return ()=>{
|
|
116
|
+
$2919bdec75484e64$var$listeners.delete(setDefaultLocale);
|
|
117
|
+
if ($2919bdec75484e64$var$listeners.size === 0) window.removeEventListener('languagechange', $2919bdec75484e64$var$updateLocale);
|
|
118
|
+
};
|
|
119
|
+
}, []);
|
|
120
|
+
// We cannot determine the browser's language on the server, so default to
|
|
121
|
+
// en-US. This will be updated after hydration on the client to the correct value.
|
|
122
|
+
if (isSSR) return {
|
|
123
|
+
locale: 'en-US',
|
|
124
|
+
direction: 'ltr'
|
|
125
|
+
};
|
|
126
|
+
return defaultLocale;
|
|
80
127
|
}
|
|
81
128
|
|
|
82
|
-
let $c53c7d716f930bd5da78e9efb99e3e$var$currentLocale = $c53c7d716f930bd5da78e9efb99e3e$export$getDefaultLocale();
|
|
83
|
-
let $c53c7d716f930bd5da78e9efb99e3e$var$listeners = new Set();
|
|
84
129
|
|
|
85
|
-
function $c53c7d716f930bd5da78e9efb99e3e$var$updateLocale() {
|
|
86
|
-
$c53c7d716f930bd5da78e9efb99e3e$var$currentLocale = $c53c7d716f930bd5da78e9efb99e3e$export$getDefaultLocale();
|
|
87
130
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
131
|
+
const $47fa5ec5ff482271$var$I18nContext = /*#__PURE__*/ ($parcel$interopDefault($87SwK$react)).createContext(null);
|
|
132
|
+
function $47fa5ec5ff482271$export$a54013f0d02a8f82(props) {
|
|
133
|
+
let { locale: locale , children: children } = props;
|
|
134
|
+
let defaultLocale = $2919bdec75484e64$export$188ec29ebc2bdc3a();
|
|
135
|
+
let value = locale ? {
|
|
136
|
+
locale: locale,
|
|
137
|
+
direction: $4d65847630a056a8$export$702d680b21cbd764(locale) ? 'rtl' : 'ltr'
|
|
138
|
+
} : defaultLocale;
|
|
139
|
+
return(/*#__PURE__*/ ($parcel$interopDefault($87SwK$react)).createElement($47fa5ec5ff482271$var$I18nContext.Provider, {
|
|
140
|
+
value: value
|
|
141
|
+
}, children));
|
|
142
|
+
}
|
|
143
|
+
function $47fa5ec5ff482271$export$43bb16f9c6d9e3f7() {
|
|
144
|
+
let defaultLocale = $2919bdec75484e64$export$188ec29ebc2bdc3a();
|
|
145
|
+
let context = $87SwK$react.useContext($47fa5ec5ff482271$var$I18nContext);
|
|
146
|
+
return context || defaultLocale;
|
|
91
147
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Returns the current browser/system language, and updates when it changes.
|
|
94
|
-
*/
|
|
95
148
|
|
|
96
149
|
|
|
97
|
-
|
|
98
|
-
let isSSR = useIsSSR();
|
|
99
|
-
let [defaultLocale, setDefaultLocale] = useState($c53c7d716f930bd5da78e9efb99e3e$var$currentLocale);
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
if ($c53c7d716f930bd5da78e9efb99e3e$var$listeners.size === 0) {
|
|
102
|
-
window.addEventListener('languagechange', $c53c7d716f930bd5da78e9efb99e3e$var$updateLocale);
|
|
103
|
-
}
|
|
150
|
+
var $c376aa482226bf60$exports = {};
|
|
104
151
|
|
|
105
|
-
|
|
106
|
-
return () => {
|
|
107
|
-
$c53c7d716f930bd5da78e9efb99e3e$var$listeners.delete(setDefaultLocale);
|
|
152
|
+
$parcel$export($c376aa482226bf60$exports, "useMessageFormatter", () => $c376aa482226bf60$export$ec23bf898b1eed85);
|
|
108
153
|
|
|
109
|
-
if ($c53c7d716f930bd5da78e9efb99e3e$var$listeners.size === 0) {
|
|
110
|
-
window.removeEventListener('languagechange', $c53c7d716f930bd5da78e9efb99e3e$var$updateLocale);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}, []); // We cannot determine the browser's language on the server, so default to
|
|
114
|
-
// en-US. This will be updated after hydration on the client to the correct value.
|
|
115
154
|
|
|
116
|
-
if (isSSR) {
|
|
117
|
-
return {
|
|
118
|
-
locale: 'en-US',
|
|
119
|
-
direction: 'ltr'
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
155
|
|
|
123
|
-
|
|
156
|
+
const $c376aa482226bf60$var$cache = new WeakMap();
|
|
157
|
+
function $c376aa482226bf60$var$getCachedDictionary(strings) {
|
|
158
|
+
let dictionary = $c376aa482226bf60$var$cache.get(strings);
|
|
159
|
+
if (!dictionary) {
|
|
160
|
+
dictionary = new $87SwK$internationalizedmessage.MessageDictionary(strings);
|
|
161
|
+
$c376aa482226bf60$var$cache.set(strings, dictionary);
|
|
162
|
+
}
|
|
163
|
+
return dictionary;
|
|
124
164
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}, children);
|
|
165
|
+
function $c376aa482226bf60$export$ec23bf898b1eed85(strings) {
|
|
166
|
+
let { locale: locale } = $47fa5ec5ff482271$export$43bb16f9c6d9e3f7();
|
|
167
|
+
let dictionary = $87SwK$react.useMemo(()=>$c376aa482226bf60$var$getCachedDictionary(strings)
|
|
168
|
+
, [
|
|
169
|
+
strings
|
|
170
|
+
]);
|
|
171
|
+
let formatter = $87SwK$react.useMemo(()=>new $87SwK$internationalizedmessage.MessageFormatter(locale, dictionary)
|
|
172
|
+
, [
|
|
173
|
+
locale,
|
|
174
|
+
dictionary
|
|
175
|
+
]);
|
|
176
|
+
return $87SwK$react.useCallback((key, variables)=>formatter.format(key, variables)
|
|
177
|
+
, [
|
|
178
|
+
formatter
|
|
179
|
+
]);
|
|
141
180
|
}
|
|
142
|
-
/**
|
|
143
|
-
* Returns the current locale and layout direction.
|
|
144
|
-
*/
|
|
145
|
-
|
|
146
181
|
|
|
147
|
-
exports.I18nProvider = I18nProvider;
|
|
148
182
|
|
|
149
|
-
|
|
150
|
-
let defaultLocale = $c53c7d716f930bd5da78e9efb99e3e$export$useDefaultLocale();
|
|
151
|
-
let context = useContext($aa95c2b730b505b265f124d9aec67193$var$I18nContext);
|
|
152
|
-
return context || defaultLocale;
|
|
153
|
-
}
|
|
183
|
+
var $b80c530ff2e20243$exports = {};
|
|
154
184
|
|
|
155
|
-
exports
|
|
156
|
-
const $a5aefbc9b72193c190dce301e0eb39$var$cache = new WeakMap();
|
|
185
|
+
$parcel$export($b80c530ff2e20243$exports, "useDateFormatter", () => $b80c530ff2e20243$export$85fd5fdf27bacc79);
|
|
157
186
|
|
|
158
|
-
function $a5aefbc9b72193c190dce301e0eb39$var$getCachedDictionary(strings) {
|
|
159
|
-
let dictionary = $a5aefbc9b72193c190dce301e0eb39$var$cache.get(strings);
|
|
160
187
|
|
|
161
|
-
if (!dictionary) {
|
|
162
|
-
dictionary = new MessageDictionary(strings);
|
|
163
|
-
$a5aefbc9b72193c190dce301e0eb39$var$cache.set(strings, dictionary);
|
|
164
|
-
}
|
|
165
188
|
|
|
166
|
-
|
|
189
|
+
function $b80c530ff2e20243$export$85fd5fdf27bacc79(options) {
|
|
190
|
+
// Reuse last options object if it is shallowly equal, which allows the useMemo result to also be reused.
|
|
191
|
+
let lastOptions = $87SwK$react.useRef(null);
|
|
192
|
+
if (options && lastOptions.current && $b80c530ff2e20243$var$isEqual(options, lastOptions.current)) options = lastOptions.current;
|
|
193
|
+
lastOptions.current = options;
|
|
194
|
+
let { locale: locale } = $47fa5ec5ff482271$export$43bb16f9c6d9e3f7();
|
|
195
|
+
return $87SwK$react.useMemo(()=>new $87SwK$internationalizeddate.DateFormatter(locale, options)
|
|
196
|
+
, [
|
|
197
|
+
locale,
|
|
198
|
+
options
|
|
199
|
+
]);
|
|
167
200
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
locale
|
|
178
|
-
} = useLocale();
|
|
179
|
-
let dictionary = useMemo(() => $a5aefbc9b72193c190dce301e0eb39$var$getCachedDictionary(strings), [strings]);
|
|
180
|
-
let formatter = useMemo(() => new MessageFormatter(locale, dictionary), [locale, dictionary]);
|
|
181
|
-
return useCallback((key, variables) => formatter.format(key, variables), [formatter]);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
exports.useMessageFormatter = useMessageFormatter;
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Provides localized date formatting for the current locale. Automatically updates when the locale changes,
|
|
188
|
-
* and handles caching of the date formatter for performance.
|
|
189
|
-
* @param options - Formatting options.
|
|
190
|
-
*/
|
|
191
|
-
function useDateFormatter(options) {
|
|
192
|
-
// Reuse last options object if it is shallowly equal, which allows the useMemo result to also be reused.
|
|
193
|
-
let lastOptions = useRef(null);
|
|
194
|
-
|
|
195
|
-
if (options && lastOptions.current && $bdeee39f835a1e28966186127db96579$var$isEqual(options, lastOptions.current)) {
|
|
196
|
-
options = lastOptions.current;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
lastOptions.current = options;
|
|
200
|
-
let {
|
|
201
|
-
locale
|
|
202
|
-
} = useLocale();
|
|
203
|
-
return useMemo(() => new DateFormatter(locale, options), [locale, options]);
|
|
201
|
+
function $b80c530ff2e20243$var$isEqual(a, b) {
|
|
202
|
+
if (a === b) return true;
|
|
203
|
+
let aKeys = Object.keys(a);
|
|
204
|
+
let bKeys = Object.keys(b);
|
|
205
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
206
|
+
for (let key of aKeys){
|
|
207
|
+
if (b[key] !== a[key]) return false;
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
204
210
|
}
|
|
205
211
|
|
|
206
|
-
exports.useDateFormatter = useDateFormatter;
|
|
207
212
|
|
|
208
|
-
|
|
209
|
-
if (a === b) {
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
213
|
+
var $fea93c5b7c90d9f4$exports = {};
|
|
212
214
|
|
|
213
|
-
|
|
214
|
-
let bKeys = Object.keys(b);
|
|
215
|
+
$parcel$export($fea93c5b7c90d9f4$exports, "useNumberFormatter", () => $fea93c5b7c90d9f4$export$b7a616150fdb9f44);
|
|
215
216
|
|
|
216
|
-
if (aKeys.length !== bKeys.length) {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
217
|
|
|
220
|
-
for (let key of aKeys) {
|
|
221
|
-
if (b[key] !== a[key]) {
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
218
|
|
|
226
|
-
|
|
219
|
+
function $fea93c5b7c90d9f4$export$b7a616150fdb9f44(options = {
|
|
220
|
+
}) {
|
|
221
|
+
let { locale: locale } = $47fa5ec5ff482271$export$43bb16f9c6d9e3f7();
|
|
222
|
+
return $87SwK$react.useMemo(()=>new $87SwK$internationalizednumber.NumberFormatter(locale, options)
|
|
223
|
+
, [
|
|
224
|
+
locale,
|
|
225
|
+
options
|
|
226
|
+
]);
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
/**
|
|
230
|
-
* Provides localized number formatting for the current locale. Automatically updates when the locale changes,
|
|
231
|
-
* and handles caching of the number formatter for performance.
|
|
232
|
-
* @param options - Formatting options.
|
|
233
|
-
*/
|
|
234
|
-
function useNumberFormatter(options) {
|
|
235
|
-
if (options === void 0) {
|
|
236
|
-
options = {};
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
let {
|
|
240
|
-
locale
|
|
241
|
-
} = useLocale();
|
|
242
|
-
return useMemo(() => new NumberFormatter(locale, options), [locale, options]);
|
|
243
|
-
}
|
|
244
229
|
|
|
245
|
-
exports
|
|
246
|
-
let $f2d7166fa8b4811bca7b68ebd673b$var$cache = new Map();
|
|
247
|
-
/**
|
|
248
|
-
* Provides localized string collation for the current locale. Automatically updates when the locale changes,
|
|
249
|
-
* and handles caching of the collator for performance.
|
|
250
|
-
* @param options - Collator options.
|
|
251
|
-
*/
|
|
252
|
-
|
|
253
|
-
function useCollator(options) {
|
|
254
|
-
let {
|
|
255
|
-
locale
|
|
256
|
-
} = useLocale();
|
|
257
|
-
let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');
|
|
258
|
-
|
|
259
|
-
if ($f2d7166fa8b4811bca7b68ebd673b$var$cache.has(cacheKey)) {
|
|
260
|
-
return $f2d7166fa8b4811bca7b68ebd673b$var$cache.get(cacheKey);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
let formatter = new Intl.Collator(locale, options);
|
|
264
|
-
$f2d7166fa8b4811bca7b68ebd673b$var$cache.set(cacheKey, formatter);
|
|
265
|
-
return formatter;
|
|
266
|
-
}
|
|
230
|
+
var $27a5ce66022270ad$exports = {};
|
|
267
231
|
|
|
268
|
-
exports
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Provides localized string search functionality that is useful for filtering or matching items
|
|
272
|
-
* in a list. Options can be provided to adjust the sensitivity to case, diacritics, and other parameters.
|
|
273
|
-
*/
|
|
274
|
-
function useFilter(options) {
|
|
275
|
-
let collator = useCollator(_babelRuntimeHelpersExtends({
|
|
276
|
-
usage: 'search'
|
|
277
|
-
}, options)); // TODO(later): these methods don't currently support the ignorePunctuation option.
|
|
278
|
-
|
|
279
|
-
return {
|
|
280
|
-
startsWith(string, substring) {
|
|
281
|
-
if (substring.length === 0) {
|
|
282
|
-
return true;
|
|
283
|
-
} // Normalize both strings so we can slice safely
|
|
284
|
-
// TODO: take into account the ignorePunctuation option as well...
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
string = string.normalize('NFC');
|
|
288
|
-
substring = substring.normalize('NFC');
|
|
289
|
-
return collator.compare(string.slice(0, substring.length), substring) === 0;
|
|
290
|
-
},
|
|
291
|
-
|
|
292
|
-
endsWith(string, substring) {
|
|
293
|
-
if (substring.length === 0) {
|
|
294
|
-
return true;
|
|
295
|
-
}
|
|
232
|
+
$parcel$export($27a5ce66022270ad$exports, "useCollator", () => $27a5ce66022270ad$export$a16aca283550c30d);
|
|
296
233
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
234
|
+
let $27a5ce66022270ad$var$cache = new Map();
|
|
235
|
+
function $27a5ce66022270ad$export$a16aca283550c30d(options) {
|
|
236
|
+
let { locale: locale } = $47fa5ec5ff482271$export$43bb16f9c6d9e3f7();
|
|
237
|
+
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1
|
|
238
|
+
).join() : '');
|
|
239
|
+
if ($27a5ce66022270ad$var$cache.has(cacheKey)) return $27a5ce66022270ad$var$cache.get(cacheKey);
|
|
240
|
+
let formatter = new Intl.Collator(locale, options);
|
|
241
|
+
$27a5ce66022270ad$var$cache.set(cacheKey, formatter);
|
|
242
|
+
return formatter;
|
|
243
|
+
}
|
|
301
244
|
|
|
302
|
-
contains(string, substring) {
|
|
303
|
-
if (substring.length === 0) {
|
|
304
|
-
return true;
|
|
305
|
-
}
|
|
306
245
|
|
|
307
|
-
|
|
308
|
-
substring = substring.normalize('NFC');
|
|
309
|
-
let scan = 0;
|
|
310
|
-
let sliceLen = substring.length;
|
|
246
|
+
var $832d079b867c7223$exports = {};
|
|
311
247
|
|
|
312
|
-
|
|
313
|
-
let slice = string.slice(scan, scan + sliceLen);
|
|
248
|
+
$parcel$export($832d079b867c7223$exports, "useFilter", () => $832d079b867c7223$export$3274cf84b703fff);
|
|
314
249
|
|
|
315
|
-
|
|
316
|
-
|
|
250
|
+
function $832d079b867c7223$export$3274cf84b703fff(options) {
|
|
251
|
+
let collator = $27a5ce66022270ad$export$a16aca283550c30d({
|
|
252
|
+
usage: 'search',
|
|
253
|
+
...options
|
|
254
|
+
});
|
|
255
|
+
// TODO(later): these methods don't currently support the ignorePunctuation option.
|
|
256
|
+
return {
|
|
257
|
+
startsWith (string, substring) {
|
|
258
|
+
if (substring.length === 0) return true;
|
|
259
|
+
// Normalize both strings so we can slice safely
|
|
260
|
+
// TODO: take into account the ignorePunctuation option as well...
|
|
261
|
+
string = string.normalize('NFC');
|
|
262
|
+
substring = substring.normalize('NFC');
|
|
263
|
+
return collator.compare(string.slice(0, substring.length), substring) === 0;
|
|
264
|
+
},
|
|
265
|
+
endsWith (string, substring) {
|
|
266
|
+
if (substring.length === 0) return true;
|
|
267
|
+
string = string.normalize('NFC');
|
|
268
|
+
substring = substring.normalize('NFC');
|
|
269
|
+
return collator.compare(string.slice(-substring.length), substring) === 0;
|
|
270
|
+
},
|
|
271
|
+
contains (string, substring) {
|
|
272
|
+
if (substring.length === 0) return true;
|
|
273
|
+
string = string.normalize('NFC');
|
|
274
|
+
substring = substring.normalize('NFC');
|
|
275
|
+
let scan = 0;
|
|
276
|
+
let sliceLen = substring.length;
|
|
277
|
+
for(; scan + sliceLen <= string.length; scan++){
|
|
278
|
+
let slice = string.slice(scan, scan + sliceLen);
|
|
279
|
+
if (collator.compare(substring, slice) === 0) return true;
|
|
280
|
+
}
|
|
281
|
+
return false;
|
|
317
282
|
}
|
|
318
|
-
|
|
283
|
+
};
|
|
284
|
+
}
|
|
319
285
|
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
322
286
|
|
|
323
|
-
|
|
324
|
-
|
|
287
|
+
$parcel$exportWildcard(module.exports, $47fa5ec5ff482271$exports);
|
|
288
|
+
$parcel$exportWildcard(module.exports, $c376aa482226bf60$exports);
|
|
289
|
+
$parcel$exportWildcard(module.exports, $b80c530ff2e20243$exports);
|
|
290
|
+
$parcel$exportWildcard(module.exports, $fea93c5b7c90d9f4$exports);
|
|
291
|
+
$parcel$exportWildcard(module.exports, $27a5ce66022270ad$exports);
|
|
292
|
+
$parcel$exportWildcard(module.exports, $832d079b867c7223$exports);
|
|
293
|
+
|
|
325
294
|
|
|
326
|
-
exports.useFilter = useFilter;
|
|
327
295
|
//# sourceMappingURL=main.js.map
|