-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26160 from software-mansion-labs/ts-migration/is-…
…selector-supported [No QA] [TS migration] Migrate 'isSelectorSupported' lib to TypeScript
- Loading branch information
Showing
4 changed files
with
15 additions
and
8 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import IsSelectorSupported from './types'; | ||
|
||
// Native platforms do not support the selector | ||
const isSelectorSupported: IsSelectorSupported = () => false; | ||
|
||
export default isSelectorSupported; |
10 changes: 6 additions & 4 deletions
10
src/libs/isSelectorSupported/index.js → src/libs/isSelectorSupported/index.ts
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,13 +1,15 @@ | ||
import IsSelectorSupported from './types'; | ||
|
||
/** | ||
* Check platform supports the selector or not | ||
* @param {String} selector | ||
* @return {Boolean} | ||
*/ | ||
export default function isSelectorSupported(selector) { | ||
const isSelectorSupported: IsSelectorSupported = (selector) => { | ||
try { | ||
document.querySelector(selector); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
}; | ||
|
||
export default isSelectorSupported; |
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,3 @@ | ||
type IsSelectorSupported = (selector: string) => boolean; | ||
|
||
export default IsSelectorSupported; |