-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
85 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function getAddress(text: string) { | ||
let index = 0; | ||
let start = -1; | ||
let end = -1; | ||
|
||
while (index >= 0) { | ||
const nextIndex = text.slice(Math.max(0, index)).indexOf('('); | ||
index = nextIndex > 0 ? nextIndex + index + 1 : -1; | ||
|
||
if (nextIndex > 0) { | ||
start = index; | ||
} | ||
} | ||
|
||
if (start === -1) return ''; | ||
|
||
index = text.slice(Math.max(0, start)).indexOf(')'); | ||
if (index === -1) return ''; | ||
|
||
end = index + start; | ||
|
||
return text.slice(start, end); | ||
} | ||
|
||
export default getAddress; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
import isRgb from './is-rgb.js'; | ||
|
||
function isBgRgb(value: string): value is string { | ||
if (!value.startsWith('bg')) return false; | ||
|
||
const rgbRegular = /^bg\((?:\d{1,3},){2}\d{1,3}\)$/; | ||
const numberRegular = /\d{1,3}/g; | ||
|
||
const numberMatch = value.match(numberRegular); | ||
const validNumber = Boolean(numberMatch?.every((item) => Number(item) <= 255)); | ||
|
||
const validRgb = rgbRegular.test(value.replace(/\s/g, '')); | ||
return validNumber && validRgb; | ||
const rgbValue = value.slice(2).replace(/\s/g, ''); | ||
return isRgb(rgbValue); | ||
} | ||
|
||
export default isBgRgb; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
function isRgb(value: string): value is string { | ||
const rgbRegular = /^\((?:\d{1,3},){2}\d{1,3}\)$/; | ||
const numberRegular = /\d{1,3}/g; | ||
const rgbRegular = /^\(\d{1,3},\d{1,3},\d{1,3}\)$/; | ||
const validRgb = rgbRegular.test(value.replace(/\s/g, '')); | ||
if (!validRgb) return false; | ||
|
||
const numberRegular = /\d{1,3}/g; | ||
const numberMatch = value.match(numberRegular); | ||
const validNumber = Boolean(numberMatch?.every((item) => Number(item) <= 255)); | ||
|
||
const validRgb = rgbRegular.test(value.replace(/\s/g, '')); | ||
return validNumber && validRgb; | ||
return Boolean(numberMatch?.every((item) => Number(item) <= 255)); | ||
} | ||
|
||
export default isRgb; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { expect, test } from 'vitest'; | ||
import getAddress from '../../src/helpers/get-address'; | ||
|
||
test('getAddress - should return empty string for invalid input', () => { | ||
const text = ''; | ||
const result = getAddress(text); | ||
const expected = ''; | ||
expect(result).toBe(expected); | ||
}); | ||
|
||
test('getAddress - should return empty string if no parentheses are found', () => { | ||
const text = 'This is a test string without parentheses'; | ||
const result = getAddress(text); | ||
const expected = ''; | ||
expect(result).toBe(expected); | ||
}); | ||
|
||
test('getAddress - should return empty string if parentheses are not closed', () => { | ||
const text = 'This is a test string with an open parenthesis ( but no closing parenthesis'; | ||
const result = getAddress(text); | ||
const expected = ''; | ||
expect(result).toBe(expected); | ||
}); | ||
|
||
test('getAddress - should return the content within the parentheses', () => { | ||
const text = 'This is a test string with (some content) within parentheses'; | ||
const result = getAddress(text); | ||
const expected = 'some content'; | ||
expect(result).toBe(expected); | ||
}); | ||
|
||
test('getAddress - should return the content within the last set of parentheses', () => { | ||
const text = | ||
'This is a test string with (multiple sets of parentheses) but should return the content within the last one'; | ||
const result = getAddress(text); | ||
const expected = 'multiple sets of parentheses'; | ||
expect(result).toBe(expected); | ||
}); | ||
|
||
test('getAddress - should handle nested parentheses and return the content within the outermost set', () => { | ||
const text = 'This is a test string with (nested (parentheses) within parentheses)'; | ||
const result = getAddress(text); | ||
const expected = 'parentheses'; | ||
expect(result).toBe(expected); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.