Skip to content

Commit

Permalink
improve number-utils typings, fix validator comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Apr 27, 2023
1 parent 2a1763c commit 16c3d3e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/helpers/number-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const nativeIsNaN = (num: unknown): boolean => {
* @param num arbitrary value
* @returns if provided value is finite
*/
export const nativeIsFinite = (num: unknown): boolean => {
export const nativeIsFinite = (num: unknown): num is number => {
// eslint-disable-next-line no-restricted-properties
const native = Number.isFinite || window.isFinite;
return native(num);
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/string-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export function generateRandomResponse(customResponseText: string): string | nul
}

// If rangeMin > rangeMax, swap variables
if ((rangeMin as number) > (rangeMax as number)) {
if ((rangeMin) > (rangeMax)) {
const temp = rangeMin;
rangeMin = rangeMax;
rangeMax = temp;
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const ADG_CSS_MASK_REG = /#@?\$#.+?\s*\{.*\}\s*$/g;
* Checks if the `rule` is AdGuard scriptlet rule
*
* @param rule - rule text
* @returns if given rule is adg rule
* @returns true if given rule is adg rule
*/
const isAdgScriptletRule = (rule: string): boolean => {
return (
Expand All @@ -71,7 +71,7 @@ const isAdgScriptletRule = (rule: string): boolean => {
* Checks if the `rule` is uBO scriptlet rule
*
* @param rule rule text
* @returns if given rule is ubo rule
* @returns true if given rule is ubo rule
*/
const isUboScriptletRule = (rule: string): boolean => {
return (
Expand All @@ -88,7 +88,7 @@ const isUboScriptletRule = (rule: string): boolean => {
* Checks if the `rule` is AdBlock Plus snippet
*
* @param rule rule text
* @returns if given rule is abp rule
* @returns true if given rule is abp rule
*/
const isAbpSnippetRule = (rule: string): boolean => {
return (
Expand Down Expand Up @@ -337,7 +337,7 @@ const parseModifiers = (rule: string): string[] => substringAfter(rule, '$')?.sp
* @param marker - specific Adg/Ubo or Abp redirect resources marker
* @returns - redirect resource name
*/
const getRedirectName = (rule: string, marker: string): string => {
const getRedirectName = (rule: string, marker: string): string | null => {
const ruleModifiers = parseModifiers(rule);
const redirectNamePart = ruleModifiers
.find((el) => el.includes(marker));
Expand All @@ -350,7 +350,7 @@ const getRedirectName = (rule: string, marker: string): string => {
* Discards comments and JS rules and checks if the `rule` has 'redirect' modifier.
*
* @param rule - rule text
* @returns if given rule is adg redirect
* @returns true if given rule is adg redirect
*/
const isAdgRedirectRule = (rule: string): boolean => {
const MARKER_IN_BASE_PART_MASK = '/((?!\\$|\\,).{1})redirect((-rule)?)=(.{0,}?)\\$(popup)?/';
Expand Down Expand Up @@ -418,7 +418,7 @@ const isRedirectRuleByType = (rule: string, type: RedirectRuleType): boolean =>
* Checks if the `rule` is **valid** AdGuard redirect resource rule
*
* @param rule - rule text
* @returns if given rule is valid adg redirect
* @returns true if given rule is valid adg redirect
*/
const isValidAdgRedirectRule = (rule: string): boolean => {
return isRedirectRuleByType(rule, RedirectRuleType.ValidAdg);
Expand Down

0 comments on commit 16c3d3e

Please sign in to comment.