Utils
Usage
isFileOrResourcePath(path)
Verifies if the specified path
is a valid resource or local file path.
let isPathValid
let path
path = 'https://thiscatdoesnotexist.com/' // Remote cat image
isPathValid = Utils.isFileOrResourcePath(path)
console.log(isPathValid) // isPathValid => false
path = 'res://icon'
isPathValid = Utils.isFileOrResourcePath(path)
console.log(isPathValid) // isPathValid => true
let isPathValid: boolean
let path: string
path = 'https://thiscatdoesnotexist.com/' // Remote cat image
isPathValid = Utils.isFileOrResourcePath(path)
console.log(isPathValid) // isPathValid => false
path = 'res://icon'
isPathValid = Utils.isFileOrResourcePath(path)
console.log(isPathValid) // isPathValid => true
isDataURI(uri)
Returns true if the specified URI is data URI (http://en.wikipedia.org/wiki/Data_URI_scheme).
escapeRegexSymbols() function
Escapes special regex symbols (., *, ^, $, etc.) in string in order to create a valid regex from it.
escapeRegexSymbols(sampleString)
var sampleString = 'All of these should be escaped: ^ $ * '
var newString = Utils.escapeRegexSymbols(sampleString)
console.log(newString) // All of these should be escaped: \^ \$ \*
var sampleString = 'All of these should be escaped: ^ $ * '
var newString: string = Utils.escapeRegexSymbols(sampleString)
console.log(newString) // All of these should be escaped: \^ \$ \*
convertString(value:any)
Converts a string value to a number or boolean;
let stringToBoolean = 'true'
let booleanValue = Utils.convertString(stringToBoolean)
console.log(booleanValue) // logs true
let stringToNumber = '23'
let numberValue = Utils.convertString(stringToNumber)
console.log(numberValue) // logs 23
let stringToBoolean = 'true'
let booleanValue: boolean = Utils.convertString(stringToBoolean)
console.log(booleanValue) // logs true
let stringToNumber = '23'
let numberValue: number = Utils.convertString(stringToNumber)
console.log(numberValue) // logs 23
Other functions
Name | Return Type | Description |
---|---|---|
|
|
A utility function that invokes garbage collection on the JavaScript side. |
|
|
A utility function that invokes garbage collection on the JavaScript side.
+ |
|
|
A utility function that queues a garbage collection, multiple calls in quick succession are debounced by default, and only one gc will be executed after 900ms.
+ |
|
|
A simple debounce utility.
+ |
|
|
A simple throttle utility.
+ |
|
|
Returns true if the specified URI is a font icon URI like "fontIcon://".
|
|
|
Checks if the current thread is the main thread.
Directly calls the passed function if it is, or dispatches it to the main thread otherwise.
+ |
|
|
Runs the passed function on the UI Thread.
+ |
|
|
Returns a function wrapper which executes the supplied function on the main thread.
The wrapper behaves like the original function and passes all of its arguments BUT discards its return value.
+ |
|
|
Returns a boolean value indicating whether the current thread is the main thread. |
|
|
Dispatches the passed function for execution on the main thread.
+ |
|
|
Releases the reference to the wrapped native object. |
|
|
Gets module name from |
|
|
Opens file.
+ |
|
|
Checks whether the application is running on a real device and not on simulator/emulator. |
|
|
A function that gets the class name of an object.
Examples: + |
|
|
A function that gets the entire class hierarchy of an object. |
|
|
A function that gets the ClassInfo for an object. |
|
|
A function that checks if something is valid boolean. |
|
|
A function that checks if something is defined (not undefined). |
|
|
A function that checks if something is a function. |
|
|
A function that checks if something is not defined (null or undefined). |
|
|
A function that checks if something is a valid number. |
|
|
A function that checks if something is an object.
Examples: + |
|
|
A function that checks if something is a valid string. |
|
|
A function that checks if something is "undefined". |
|
|
Returns a string representation of an object to be shown in UI. |
|
|
A function that checks if something is a valid function. Throws exception if passed value is not a valid function. |
Timer utilities
Setting & clearing interval
Utils.setInterval()
can be used to apply recurring action on a given interval in milliseconds.
To stop Utils.setInterval()
, use Utils.clearInterval()
.
let counter = 0
const interval = Utils.setInterval(() => {
console.log('Hello' + counter)
if (counter > 10) {
Dialogs.alert('Condition met')
Utils.clearInterval(interval)
}
counter++
}, 1000)
let counter = 0
const interval = Utils.setInterval(() => {
console.log('Hello' + counter)
if (counter > 10) {
Dialogs.alert('Condition met')
Utils.clearInterval(interval)
}
counter++
}, 1000)
Android specific utilities
Utils.android functions
Module with android specific utilities.
Name | Return Type | Description |
---|---|---|
|
|
Gets the native Android application instance. |
|
|
Gets the Android application context. |
|
|
Gets the native Android input method manager. |
|
|
Hides the soft input method, usually a soft keyboard. |
|
|
Shows the soft input method, usually a soft keyboard. |
Utils.android.collections functions
Utility module dealing with some android collections.
Name | Return Type | Description |
---|---|---|
|
|
Converts an array of strings into a String hash set. |
|
|
Converts a string hash set into an array of strings. |
Utils.android.resources functions
Utility module related to android resources.
Name | Return Type | Description |
---|---|---|
|
|
Gets the drawable id from a given name.
+ |
|
|
Gets the string id from a given name.
+ |
|
|
Gets the id from a given name.
+ |
|
|
Gets a color from the current theme.
+ |
iOS specific utilities
Utils.ios propeties
Name | Return Type | Description |
---|---|---|
|
|
Gets the iOS device major version (for 8.1 will return 8). |
Utils.ios functions
Name | Return Type | Description |
---|---|---|
|
|
Joins an array of file paths aeturns the joined path. |
|
|
Gets the root folder for the current application. This Folder is private for the application and not accessible from Users/External apps. This folder is read-only and contains the app and all its resources. |
|
|
Gets the currently visible(topmost) UIViewController.
+ |
|
|
|
|
|
Create a UIDocumentInteractionControllerDelegate implementation for use with UIDocumentInteractionController. |
Utils.ios.collections
Utility module dealing with some iOS collections.
Name | Return Type | Description |
---|---|---|
|
|
Converts JavaScript array to NSArray. |
|
|
Converts NSArray to JavaScript array. |