Skip to content

Commit

Permalink
safari
Browse files Browse the repository at this point in the history
  • Loading branch information
leeoniya committed Sep 23, 2022
1 parent 6a9f47e commit 0a7ad33
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 9 deletions.
19 changes: 17 additions & 2 deletions dist/uFuzzy.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const inf = Infinity;

const isInt = /\d/;

const ua = navigator.userAgent.toLowerCase();
const isSafari = ua.indexOf('safari') != -1 && ua.indexOf('chrome') == -1;
const canLookBehind = !isSafari;

const OPTS = {
// term segmentation & punct/whitespace merging
interSplit: '[^A-Za-z0-9]+',
Expand Down Expand Up @@ -105,8 +109,19 @@ function uFuzzy(opts) {
// array of regexp tpls for each term
let reTpl = parts.map(p => p.split('').join(intraCharsTpl));

if (opts.strictPre)
reTpl = reTpl.map(term => '(?<!' + typeClassOf(term[0]) + ')' + term);
if (opts.strictPre) {
// Safari sucks and doesn't support RegExp lookbehinds: https://caniuse.com/js-regexp-lookbehind
// https://bugs.webkit.org/show_bug.cgi?id=174931
// so we just use a normal \b word boundary, instead of the fancier solution which can infer
// word boundaries at alpha-num or upper-lower transitions, WebKit, 007james, __ABC
//
// this can be worked around by using a non-capturing group ahead of each term, like (?:[^opts.upperChars])
// and then shifting/trimming the match props in the .info() phase before collecting stats and ranges
if (!canLookBehind)
reTpl = reTpl.map(term => '\\b' + term);
else
reTpl = reTpl.map(term => '(?<!' + typeClassOf(term[0]) + ')' + term);
}

if (opts.strictSuf)
reTpl = reTpl.map(term => term + '(?!' + typeClassOf(term.at(-1)) + ')');
Expand Down
19 changes: 17 additions & 2 deletions dist/uFuzzy.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const inf = Infinity;

const isInt = /\d/;

const ua = navigator.userAgent.toLowerCase();
const isSafari = ua.indexOf('safari') != -1 && ua.indexOf('chrome') == -1;
const canLookBehind = !isSafari;

const OPTS = {
// term segmentation & punct/whitespace merging
interSplit: '[^A-Za-z0-9]+',
Expand Down Expand Up @@ -103,8 +107,19 @@ function uFuzzy(opts) {
// array of regexp tpls for each term
let reTpl = parts.map(p => p.split('').join(intraCharsTpl));

if (opts.strictPre)
reTpl = reTpl.map(term => '(?<!' + typeClassOf(term[0]) + ')' + term);
if (opts.strictPre) {
// Safari sucks and doesn't support RegExp lookbehinds: https://caniuse.com/js-regexp-lookbehind
// https://bugs.webkit.org/show_bug.cgi?id=174931
// so we just use a normal \b word boundary, instead of the fancier solution which can infer
// word boundaries at alpha-num or upper-lower transitions, WebKit, 007james, __ABC
//
// this can be worked around by using a non-capturing group ahead of each term, like (?:[^opts.upperChars])
// and then shifting/trimming the match props in the .info() phase before collecting stats and ranges
if (!canLookBehind)
reTpl = reTpl.map(term => '\\b' + term);
else
reTpl = reTpl.map(term => '(?<!' + typeClassOf(term[0]) + ')' + term);
}

if (opts.strictSuf)
reTpl = reTpl.map(term => term + '(?!' + typeClassOf(term.at(-1)) + ')');
Expand Down
19 changes: 17 additions & 2 deletions dist/uFuzzy.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ var uFuzzy = (function () {

const isInt = /\d/;

const ua = navigator.userAgent.toLowerCase();
const isSafari = ua.indexOf('safari') != -1 && ua.indexOf('chrome') == -1;
const canLookBehind = !isSafari;

const OPTS = {
// term segmentation & punct/whitespace merging
interSplit: '[^A-Za-z0-9]+',
Expand Down Expand Up @@ -106,8 +110,19 @@ var uFuzzy = (function () {
// array of regexp tpls for each term
let reTpl = parts.map(p => p.split('').join(intraCharsTpl));

if (opts.strictPre)
reTpl = reTpl.map(term => '(?<!' + typeClassOf(term[0]) + ')' + term);
if (opts.strictPre) {
// Safari sucks and doesn't support RegExp lookbehinds: https://caniuse.com/js-regexp-lookbehind
// https://bugs.webkit.org/show_bug.cgi?id=174931
// so we just use a normal \b word boundary, instead of the fancier solution which can infer
// word boundaries at alpha-num or upper-lower transitions, WebKit, 007james, __ABC
//
// this can be worked around by using a non-capturing group ahead of each term, like (?:[^opts.upperChars])
// and then shifting/trimming the match props in the .info() phase before collecting stats and ranges
if (!canLookBehind)
reTpl = reTpl.map(term => '\\b' + term);
else
reTpl = reTpl.map(term => '(?<!' + typeClassOf(term[0]) + ')' + term);
}

if (opts.strictSuf)
reTpl = reTpl.map(term => term + '(?!' + typeClassOf(term.at(-1)) + ')');
Expand Down
2 changes: 1 addition & 1 deletion dist/uFuzzy.iife.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions src/uFuzzy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const inf = Infinity;

const isInt = /\d/;

const ua = navigator.userAgent.toLowerCase();
const isSafari = ua.indexOf('safari') != -1 && ua.indexOf('chrome') == -1;
const canLookBehind = !isSafari;

const OPTS = {
// term segmentation & punct/whitespace merging
interSplit: '[^A-Za-z0-9]+',
Expand Down Expand Up @@ -96,8 +100,19 @@ export default function uFuzzy(opts) {
// array of regexp tpls for each term
let reTpl = parts.map(p => p.split('').join(intraCharsTpl));

if (opts.strictPre)
reTpl = reTpl.map(term => '(?<!' + typeClassOf(term[0]) + ')' + term);
if (opts.strictPre) {
// Safari sucks and doesn't support RegExp lookbehinds: https://caniuse.com/js-regexp-lookbehind
// https://bugs.webkit.org/show_bug.cgi?id=174931
// so we just use a normal \b word boundary, instead of the fancier solution which can infer
// word boundaries at alpha-num or upper-lower transitions, WebKit, 007james, __ABC
//
// this can be worked around by using a non-capturing group ahead of each term, like (?:[^opts.upperChars])
// and then shifting/trimming the match props in the .info() phase before collecting stats and ranges
if (!canLookBehind)
reTpl = reTpl.map(term => '\\b' + term);
else
reTpl = reTpl.map(term => '(?<!' + typeClassOf(term[0]) + ')' + term);
}

if (opts.strictSuf)
reTpl = reTpl.map(term => term + '(?!' + typeClassOf(term.at(-1)) + ')');
Expand Down

0 comments on commit 0a7ad33

Please sign in to comment.