Skip to content

Commit

Permalink
remove getWildcardSymbol helper
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Nov 11, 2022
1 parent dfd8ce1 commit e411fe3
Show file tree
Hide file tree
Showing 13 changed files with 8 additions and 35 deletions.
3 changes: 1 addition & 2 deletions src/helpers/adjust-set-utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { nativeIsNaN, nativeIsFinite } from './number-utils';
import { getWildcardSymbol } from './constants';

export const shouldMatchAnyDelay = (delay) => delay === getWildcardSymbol();
export const shouldMatchAnyDelay = (delay) => delay === '*';

/**
* Handles input delay value
Expand Down
5 changes: 0 additions & 5 deletions src/helpers/constants.js

This file was deleted.

4 changes: 1 addition & 3 deletions src/helpers/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {

import { isExisting } from './array-utils';

import { getWildcardSymbol } from './constants';

import validator from './validator';

import { parseRule } from './parse-rule';
Expand Down Expand Up @@ -48,7 +46,7 @@ const UBO_SET_CONSTANT_EMPTY_STRING = '\'\'';

const ADG_PREVENT_FETCH_NAME = 'prevent-fetch';
const ADG_PREVENT_FETCH_EMPTY_STRING = '';
const ADG_PREVENT_FETCH_WILDCARD = getWildcardSymbol();
const ADG_PREVENT_FETCH_WILDCARD = '*';
const UBO_NO_FETCH_IF_WILDCARD = '/^/';

const ESCAPED_COMMA_SEPARATOR = '\\,';
Expand Down
6 changes: 2 additions & 4 deletions src/helpers/get-wildcard-property-in-chain.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { getWildcardSymbol } from './constants';

/**
* @typedef Chain
* @property {Object} base
Expand All @@ -23,7 +21,7 @@ export function getWildcardPropertyInChain(base, chain, lookThrough = false, out
const pos = chain.indexOf('.');
if (pos === -1) {
// for paths like 'a.b.*' every final nested prop should be processed
if (chain === getWildcardSymbol() || chain === '[]') {
if (chain === '*' || chain === '[]') {
// eslint-disable-next-line no-restricted-syntax
for (const key in base) {
// to process each key in base except inherited ones
Expand All @@ -41,7 +39,7 @@ export function getWildcardPropertyInChain(base, chain, lookThrough = false, out
const prop = chain.slice(0, pos);

const shouldLookThrough = (prop === '[]' && Array.isArray(base))
|| (prop === getWildcardSymbol() && base instanceof Object);
|| (prop === '*' && base instanceof Object);

if (shouldLookThrough) {
const nextProp = chain.slice(pos + 1);
Expand Down
1 change: 0 additions & 1 deletion src/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
export * from './add-event-listener-utils';
export * from './adjust-set-utils';
export * from './array-utils';
export * from './constants';
export * from './cookie-utils';
export * from './log-utils';
export * from './noop-utils';
Expand Down
2 changes: 0 additions & 2 deletions src/scriptlets/adjust-setInterval.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
nativeIsNaN,
nativeIsFinite,
getMatchDelay,
getWildcardSymbol,
shouldMatchAnyDelay,
} from '../helpers/index';

Expand Down Expand Up @@ -105,6 +104,5 @@ adjustSetInterval.injections = [
nativeIsNaN,
nativeIsFinite,
getMatchDelay,
getWildcardSymbol,
shouldMatchAnyDelay,
];
2 changes: 0 additions & 2 deletions src/scriptlets/adjust-setTimeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
nativeIsNaN,
nativeIsFinite,
getMatchDelay,
getWildcardSymbol,
shouldMatchAnyDelay,
} from '../helpers/index';

Expand Down Expand Up @@ -107,6 +106,5 @@ adjustSetTimeout.injections = [
nativeIsNaN,
nativeIsFinite,
getMatchDelay,
getWildcardSymbol,
shouldMatchAnyDelay,
];
2 changes: 0 additions & 2 deletions src/scriptlets/json-prune.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
logMessage,
// following helpers are needed for helpers above
toRegExp,
getWildcardSymbol,
getNativeRegexpTest,
} from '../helpers/index';

Expand Down Expand Up @@ -233,6 +232,5 @@ jsonPrune.injections = [
logVerbose,
logMessage,
toRegExp,
getWildcardSymbol,
getNativeRegexpTest,
];
2 changes: 0 additions & 2 deletions src/scriptlets/prevent-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
getFetchData,
objectToString,
noopPromiseResolve,
getWildcardSymbol,
matchRequestProps,
logMessage,
logVerbose,
Expand Down Expand Up @@ -154,7 +153,6 @@ preventFetch.injections = [
getFetchData,
objectToString,
noopPromiseResolve,
getWildcardSymbol,
matchRequestProps,
logMessage,
logVerbose,
Expand Down
6 changes: 2 additions & 4 deletions src/scriptlets/prevent-window-open.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
createDecoy,
getPreventGetter,
noopNull,
getWildcardSymbol,
logMessage,
logVerbose,
// following helpers are needed for helpers above
Expand Down Expand Up @@ -84,7 +83,7 @@ import {
* > For better compatibility with uBO, old syntax is not recommended to use.
*/
/* eslint-enable max-len */
export function preventWindowOpen(source, match = getWildcardSymbol(), delay, replacement) {
export function preventWindowOpen(source, match = '*', delay, replacement) {
// default match value is needed for preventing all window.open calls
// if scriptlet runs without args
const nativeOpen = window.open;
Expand Down Expand Up @@ -117,7 +116,7 @@ export function preventWindowOpen(source, match = getWildcardSymbol(), delay, re
}

let shouldPrevent = false;
if (match === getWildcardSymbol()) {
if (match === '*') {
shouldPrevent = true;
} else if (isValidMatchStr(match)) {
const { isInvertedMatch, matchRegexp } = parseMatchArg(match);
Expand Down Expand Up @@ -188,7 +187,6 @@ preventWindowOpen.injections = [
createDecoy,
getPreventGetter,
noopNull,
getWildcardSymbol,
logMessage,
logVerbose,
noopFunc,
Expand Down
2 changes: 0 additions & 2 deletions src/scriptlets/prevent-xhr.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
hit,
objectToString,
getWildcardSymbol,
getRandomIntInclusive,
getRandomStrByLength,
generateRandomResponse,
Expand Down Expand Up @@ -191,7 +190,6 @@ preventXHR.injections = [
logMessage,
logVerbose,
objectToString,
getWildcardSymbol,
matchRequestProps,
getRandomIntInclusive,
getRandomStrByLength,
Expand Down
4 changes: 1 addition & 3 deletions src/scriptlets/trusted-replace-fetch-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
logVerbose,
getFetchData,
objectToString,
getWildcardSymbol,
matchRequestProps,
// following helpers should be imported and injected
// because they are used by helpers above
Expand Down Expand Up @@ -157,7 +156,7 @@ export function trustedReplaceFetchResponse(source, pattern = '', replacement =
.then((response) => {
return response.text()
.then((bodyText) => {
const patternRegexp = pattern === getWildcardSymbol()
const patternRegexp = pattern === '*'
? toRegExp()
: toRegExp(pattern);

Expand Down Expand Up @@ -196,7 +195,6 @@ trustedReplaceFetchResponse.injections = [
logVerbose,
getFetchData,
objectToString,
getWildcardSymbol,
matchRequestProps,
toRegExp,
isValidStrPattern,
Expand Down
4 changes: 1 addition & 3 deletions src/scriptlets/trusted-replace-xhr-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
logVerbose,
toRegExp,
objectToString,
getWildcardSymbol,
matchRequestProps,
getXhrData,
// following helpers should be imported and injected
Expand Down Expand Up @@ -160,7 +159,7 @@ export function trustedReplaceXhrResponse(source, pattern = '', replacement = ''
return;
}

const patternRegexp = pattern === getWildcardSymbol()
const patternRegexp = pattern === '*'
? toRegExp()
: toRegExp(pattern);

Expand Down Expand Up @@ -236,7 +235,6 @@ trustedReplaceXhrResponse.injections = [
logVerbose,
toRegExp,
objectToString,
getWildcardSymbol,
matchRequestProps,
getXhrData,
getMatchPropsData,
Expand Down

0 comments on commit e411fe3

Please sign in to comment.