68 lines
2.6 KiB
Plaintext
68 lines
2.6 KiB
Plaintext
import {useCollator as $325a3faab7a68acd$export$a16aca283550c30d} from "./useCollator.module.js";
|
|
import {useCallback as $21ck9$useCallback, useMemo as $21ck9$useMemo} from "react";
|
|
|
|
/*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/
|
|
|
|
function $bb77f239b46e8c72$export$3274cf84b703fff(options) {
|
|
let collator = (0, $325a3faab7a68acd$export$a16aca283550c30d)({
|
|
usage: 'search',
|
|
...options
|
|
});
|
|
// TODO(later): these methods don't currently support the ignorePunctuation option.
|
|
let startsWith = (0, $21ck9$useCallback)((string, substring)=>{
|
|
if (substring.length === 0) return true;
|
|
// Normalize both strings so we can slice safely
|
|
// TODO: take into account the ignorePunctuation option as well...
|
|
string = string.normalize('NFC');
|
|
substring = substring.normalize('NFC');
|
|
return collator.compare(string.slice(0, substring.length), substring) === 0;
|
|
}, [
|
|
collator
|
|
]);
|
|
let endsWith = (0, $21ck9$useCallback)((string, substring)=>{
|
|
if (substring.length === 0) return true;
|
|
string = string.normalize('NFC');
|
|
substring = substring.normalize('NFC');
|
|
return collator.compare(string.slice(-substring.length), substring) === 0;
|
|
}, [
|
|
collator
|
|
]);
|
|
let contains = (0, $21ck9$useCallback)((string, substring)=>{
|
|
if (substring.length === 0) return true;
|
|
string = string.normalize('NFC');
|
|
substring = substring.normalize('NFC');
|
|
let scan = 0;
|
|
let sliceLen = substring.length;
|
|
for(; scan + sliceLen <= string.length; scan++){
|
|
let slice = string.slice(scan, scan + sliceLen);
|
|
if (collator.compare(substring, slice) === 0) return true;
|
|
}
|
|
return false;
|
|
}, [
|
|
collator
|
|
]);
|
|
return (0, $21ck9$useMemo)(()=>({
|
|
startsWith: startsWith,
|
|
endsWith: endsWith,
|
|
contains: contains
|
|
}), [
|
|
startsWith,
|
|
endsWith,
|
|
contains
|
|
]);
|
|
}
|
|
|
|
|
|
export {$bb77f239b46e8c72$export$3274cf84b703fff as useFilter};
|
|
//# sourceMappingURL=useFilter.module.js.map
|