BrightScript-JavaScript Migration Guide
Â
This page describes the mapping between BrightScript and JavaScript APIs. BrightScript functionality is implemented in JavaScript using the BrightSign JavaScript API and the older BS- JavaScript objects; BrightScript APIs are not ported when standard JavaScript libraries provide equivalent functionality.
If the JavaScript equivalent is "Not available", the functionality is not currently implemented but should be in the future. If the equivalent is "Not applicable", the corresponding BrightScript method would be meaningless in JavaScript or is otherwise unnecessary.Â
BrightScript API | JavaScript Equivalent | Library |
---|---|---|
Global Functions | ||
CreateObject() | Not applicable | |
RestartScript() | Not applicable | |
RestartApplication() | process.exit() | Node.js® |
Sleep() | Not applicable | |
asc() | String.charCodeAt() | JavaScript built-in |
chr() | String.fromCharCode() | JavaScript built-in |
len() | String.length | JavaScript built-in |
str() | Number.toString() | JavaScript built-in |
strl() | Number.toString() | JavaScript built-in |
val() | Number() | JavaScript built-in |
abs() | Math.abs() | JavaScript built-in |
atn() | Math.atan() | JavaScript built-in |
csng() | Not applicable | |
cdbl() | Not applicable | |
cint() | Not applicable | |
cos() | Math.cos() | JavaScript built-in |
exp() | Math.exp() | JavaScript built-in |
fix() | Number.toFixed() | JavaScript built-in |
int() | Math.trunc() | JavaScript built-in |
log() | Math.log() | JavaScript built-in |
sgn() | Math.sign() | JavaScript built-in |
sgnl() | Math.sign() | JavaScript built-in |
sin() | Math.sin() | JavaScript built-in |
tan() | Math.tan() | JavaScript built-in |
sqr() | Math.sqrt() | JavaScript built-in |
Left(target_string, n) | target_string.substr(0, n)* | JavaScript built-in |
Right(target_string, n) | target_string.substr(target_string.length - n)* target_string.substr(-n)* | JavaScript built-in |
StringI() | String.repeat() | JavaScript built-in |
Mid(target_string, start_position, length | target_string.substr(start_position, length)* | JavaScript built-in |
Instr() | String.indexOf() | JavaScript built-in |
GetInterface() | Access object interfaces as strings | |
Wait() | Not applicable in JavaScript, unless the function is used without reference to ports, and merely to delay execution for a time, in which case, use setTimeout(). | JavaScript built-in |
ReadAsciiFile() | readFileSync() Async operations are always preferable. | Node.js® |
WriteAsciiFile() | fs.writeFile() Async operations are always preferable. | Node.js® |
ListDir() | fs.readDir() Async operations are always preferable. | Node.js® |
MatchFiles() | fs.readDir() Async operations are always preferable. Additional JavaScript code is needed to complete matching. | Node.js® |
LCase() | String.toLowerCase() | JavaScript built-in |
UCase() | String.toUpperCase() | JavaScript built-in |
DeleteFile() | fs.unlink() Async operations are always preferable. | Node.js® |
DeleteDirectory() | fs.rmdir() Async operations are always preferable. | Node.js® |
CreateDirectory() | fs.mkdir() Async operations are always preferable. | Node.js® |
RebootSystem() | system.reboot() | BrightSign JavaScript API |
ShutdownSystem() | Not available | |
UpTime() | OS.uptime() | Node.js® |
FormatDrive() | No exact equivalent. | |
EjectDrive() | Not available | |
CopyFile() | fs.copyFile() Async operations are always preferable. | Node.js® |
MoveFile() | fs.rename() Async operations are always preferable. | Node.js® |
MapFilenameToNative() | Not applicable | |
strtoi() | parseInt() strtoi() parses in base 10, whereas JavaScript supports any base. | JavaScript built-in |
rnd() | JavaScript built-in | |
RunGarbageCollector() | Not applicable | |
GetDefaultDrive() | Not applicable | Node.js® |
SetDefaultDrive() | process.chdir() | Node.js® |
EnableZoneSupport() | Not applicable | |
EnableAudioMixer() | Not applicable | |
Pi() | Math.PI | JavaScript built-in |
ParseJson() | JSON.parse() BrightScript returns Invalid in the case of problematic strings, whereas JavaScript throws an exception. | JavaScript built-in |
FormatJson() | JSON.stringify()  JSON.stringify must be invoked with a custom replacer, for example, Cyclic_object_value or WebReflection/flatted#flatted | JavaScript built-in |
Core Objects | ||
roArray | Not applicable | |
roAssociativeArray | Not applicable | |
roBoolean | Not applicable | |
roByteArray | Blob() Note that JavaScript now has typed arrays (for example, Uint8Array) . |  |
roDouble | Not applicable | |
roFunction | Not applicable | |
roInt, roFloat, roString | Not applicable | |
roList | Use JavaScript built-in function | |
roMessagePort | Not applicable | |
roRegex | RegExp() | |
roXMLElement | DOMParser() | |
roXMLList | DOMParser() | |
Presentation Objects | ||
roAudioEventMx | Not available | |
roAudioOutput | ||
roAudioPlayer | Use html audio tag | |
roCanvasWidget | Not applicable | |
roClockWidget | Not applicable | |
roHdmiInputChanged | videoinput.VideoInputConfiguration.hdmiinputchanged | |
roHdmiOutputChanged | videooutput.VideoOutputConfiguration.hotplugevent | |
roHTMLWidget | ||
roImageBuffer | Not applicable | |
roImagePlayer | ||
roImageWidget | ||
roRectangle | Not applicable | |
roStreamQueue | Not available | |
roTextField | Not applicable | |
roTextWidget | Not applicable | |
roTouchEvent | TouchEvent() | Web API |
roTouchScreen | Not available | |
SetResolution() | Browser performs mapping | |
AddRectangle() | Map CSS cursor properties to hardware cursor | |
AddCircleRegion() | Map CSS cursor properties to hardware cursor | |
ClearRegions() | Not applicable | |
GetDeviceName() | Not applicable | |
SetCursorPosition() | Simulate mouse cursor events in JavaScript | |
SetCursorBitmap() | Map CSS cursor properties to hardware cursor | |
EnableCursor() | Map CSS cursor properties to hardware cursor | |
EnableRollover() | Not applicable | |
EnableRegion() | Map CSS cursor properties to hardware cursor | |
SetRollOverOrigin() | Map CSS cursor properties to hardware cursor | |
IsMousePresent() | pointer.isMousePresent() | |
SetMouseRotation() | Not applicable | |
EnableSerialTouchscreen() | Not available | |
SetSerialTouchscreenConfiguration() | Not available | |
GetDiagnosticInfo() | pointerCalibration.getDiagnosticInfoHTML() | |
StartCalibration() | pointerCalibration.startCalibration() | |
GetCalibrationStatus() | pointerCalibration.getCalibrationStatus() | |
ClearStoredCalibration() | pointerCalibration.clearStoredCalibration() | |
StartEventLogging() | pointerCalibration.startEventLogging() | |
StopEventLogging() | pointerCalibration.stopEventLogging() | |
ClearEventLogs() | Not applicable (no information on the log) | |
SetCalibrationRanges() | pointerCalibration.setCalibrationRanges() | |
roVIdeoInput | MediaDevices.getUserMedia() | Web API |
roVideoMode | ||
SetMode() | videomodeconfiguration.setMode() | |
SetModeForNextBoot() | Not applicable (use @brightsign/videomodeconfiguration SetMode()) | |
GetModeForNextBoot() | Not applicable (use @brightsign/videomodeconfiguration getActiveMode()) | |
GetBestMode() | videomodeconfiguration.getBestMode() | |
GetMode() | videomodeconfiguration.getActiveMode() | |
GetActiveMode() | videomodeconfiguration.getActiveMode() | |
GetAvailableModes() | videomodeconfiguration.getAvailableModes() | |
GetConfiguredMode() | videomodeconfiguration.getConfiguredMode() | |
GetFPS | videomodeconfiguration.getActiveMode() | |
SetDecoderMode() | decoderconfiguration.applyConfig() | |
GetDecoderModes() | decoderconfiguration.getConfig() | |
Set3DMode() | videooutput.set3dMode()Â Â Â Â Â Â | |
Screenshot() | screenshot.syncCapture()/asyncCapture() | |
GetResX() | videomodeconfiguration.Mode.graphicsPlaneWidth | |
GetRexY() | videomodeconfiguration.Mode.graphicsPlaneHeight | |
GetVideoResX() | videomodeconfiguration.Mode.width | |
GetVideoResY() | videomodeconfiguration.Mode.height | |
GetOutputResX() | videooutput.Size.width | |
GetOutputResY() | videooutput.Size.height | |
GetSafeX() | BSVideoMode.safeX | BS- JavaScript objects |
GetSafeY() | BSVideoMode.safeY | BS- JavaScript objects |
SafeWidth() | BSVideoMode.safeWidth | BS- JavaScript objects |
SafeHeight() | BSVideoMOde.safeHeight | BS- JavaScript objects |
SetGraphicsZOrder | Not applicable | |
PauseGraphics() | compositor.pause() | |
ResumeGraphics() | compositor.resume() | |
SetImageSizeThreshold() | system.setImageSizeThreshold() | |
AdjustGraphicsColor() | videooutput.adjustGraphicColor() | |
ConfigureHdmiInput() | videoinput.ApplyConfig() | |
SetHdmiMetadata() | Not available and possibly not applicable | |
GetHdmiOutputStatus() | videooutput.getOutputStatus() | |
GetHdmiInputStatus() | videoinput.getStatus() | |
GetCompositorCrc() | compositor.getCrc() | |
GetTxHdcpStatus() | videooutput.getTxHdcpStatus() | |
ForceHdcpOn() | videooutput.forceHdcpOn() | |
DisableHdcpRepeater() | videooutput.DisableHdcpRepeater() | |
SetBackgroundColor() | videooutput.setBackgroundColor() | |
SetPowerSaveMode() | videooutput.SetPowerSaveMode() | |
IsAttached() | videooutput.isAttached() | |
HdmiAudioDisable() | videooutput.disableAudio() | |
SetMultiscreenBezel() | videooutput.setMultiscreenBezel() | |
SaveEdids() | videooutput.getEdid() returns EDID information as a hex-encoded string. | |
GetEdidIdentity() | videooutput.getEdidIdentity() | |
SetMpcdi() | videooutput.setMpcdi() | |
SetSyncDomain() | videooutput.setSyncDomain() | |
roVideoPlayer | Use <video> elements with BrightSign properties | |
File Objects | Use Node.js File API | |
Hashing and Storage Objects | ||
roBlockCipher | Node.js Crypto API | |
roBrightPackage | Node.js Zlib API | |
roDiskErrorEvent | Not available | |
roDiskMonitor | Not available | |
roHashGenerator | Node.js Crypto API | |
roPassKey | Node.js Crypto API | |
roRegistry | ||
GetSectionList() | registry.read() | |
Delete() | registry.write() | |
Flush() | Not applicable; registry writes are flushed implicitly | |
roRegistrySection | ||
Read() | registry.read() | |
Write() | registry.write() | |
Delete() | registry.write() | |
Exists() | Not applicable (Use read followed by a truthy check on the registry key) | |
Flush() | Not applicable; registry writes are flushed implicitly | |
GetKeyList() | Not applicable (Use read followed by Object.keys()) | |
roSqliteDatabase | Use IndexedDB | |
roSqliteStatement | Use IndexedDB | |
roStorageAttached | node.js fs.watch() | |
roStorageDetached | node.js fs.watch() | |
roStorageHotplug | node.js fs.watch() | |
roStorageInfo | ||
GetBytesPerBlock() | filesysteminfo.getStatistics() | |
GetSizeInMegabytes() | filesysteminfo.getStatistics() | |
GetUsedInMegabytes() | node.js fs.stat() | |
GetFreeInMegabytes() | filesysteminfo.getStatistics() | |
GetFileSystemType() | filesysteminfo.getFileSystemType() | |
GetStorageCardInfo() | storageinfo.getStorageCardInfo() | |
roVirtualMemory | Not available | |
Content Management Objects | ||
roAssetCollection | Not available | |
roAssetFetcher | ||
roAssetPool | ||
roAssetPoolFiles | ||
roAssetRealizer | ||
roSyncSpec | Not applicable | |
Networking Objects | ||
roDatagramReceiver | Node.js Dgram API | |
roDatagramSender | Node.js Dgram API | |
roDatagramSocket | Node.js Dgram API | |
roHttpServer | Node.js | |
roKeyStore | ||
roMediaServer | node-media-server | |
roMediaStreamer | Not available | |
roMimeStream | Not applicable | |
roNetworkAdvertisement | Not applicable (use node.js) | |
roNetworkConfiguration | ||
Apply() | networkconfiguration.applyConfig() | |
SetupDWS() | dwsconfiguration | |
EnableLEDs() | networkconfiguration.enableLeds() | |
SetClientIdentifier() | networkconfiguration.NetworkInterfaceConfig.clientIdentifier | |
GetClientIdentifier() | networkconfiguration.NetworkInterfaceConfig.clientIdentifier | |
SetLoginPassword() | hostconfiguration.HostConfigWritable.loginPassword | |
SetObfuscatedLoginPassword() | hostconfiguration.HostConfigWritable.ObfuscatedLoginPassword | |
SetInboundShaperRate() | networkconfiguration.NetworkInterfaceConfig.inboundShaperRate | |
SetMTU() | networkconfiguration.NetworkInterfaceConfig.mtu | |
SetRoutingMetric() | networkconfiguration.NetworkInterfaceConfig.metric | |
SetDHCP() | networkconfiguration.NetworkInterfaceConfig.ipAddressList | |
SetEnabledProtocols() | networkconfiguration.NetworkInterfaceConfig.enabledProtocolList | |
SetIP4Address() | networkconfiguration.NetworkInterfaceConfig.ipAddressList | |
SetIP4Netmask() | networkconfiguration.NetworkInterfaceConfig.ipAddressList | |
SetIP4Broadcast() | networkconfiguration.NetworkInterfaceConfig.ipAddressList | |
SetIP4Gateway() | networkconfiguration.NetworkInterfaceConfig.ipAddressList | |
SetVlanIds() | networkconfiguration.NetworkInterfaceConfig.vlanIdList | |
SetWiFiESSID()/.GetWiFiESSID() | networkconfiguration.WiFiInterfaceConfig.essId | |
SetWiFiPassphrase() | networkconfiguration.WiFiInterfaceConfig.passphrase | |
SetWiFiPassphraseAndObfuscate() | networkconfiguration.WiFiInterfaceConfig.obfuscatedPassphrase | |
SetWiFiAccessPointMode() | networkconfiguration.WiFiInterfaceConfig.accessPointMode | |
SetAccessPointFrequencyMHz() | networkconfiguration.WiFiInterfaceConfig.accessPointFrequency | |
SetWiFiIdentity() | networkconfiguration.WiFiInterfaceConfig.identity | |
SetWiFiEapTlsOptions() | networkconfiguration.WiFiInterfaceConfig.eapTlsOptions | |
SetWiFiCACertificates() | networkconfiguration.WiFiInterfaceConfig.caCertificates | |
SetWiFiClientCertificate() | networkconfiguration.WiFiInterfaceConfig.clientCertificate | |
SetWiFiPrivateKey() | networkconfiguration.WiFiInterfaceConfig.privateKey | |
SetWiFiSecurityMode() | networkconfiguration.WiFiInterfaceConfig.securityMode | |
ConfigureDHCPServer() | networkconfiguration.NetworkInterfaceConfig.dhcpServerConfig | |
SetForwardingPolicy() | Not available | |
SetDNSServers()/.AddDNSServer() | networkconfiguration.NetworkInterfaceConfig.dnsServerList | |
SetTimeServer() | hostconfiguration.HostConfig.timeServerList | |
SetTimeServerIntervalSeconds()/ GetTimeServerIntervalSecons() | hostconfiguration.HostConfig.timeServerInterval | |
SetHostName()/.GetHostName() | hostconfiguration.HostConfig.hostName | |
SetProxy()/.GetProxy() | hostconfiguration.HostConfig.proxy | |
SetProxyBypass()/.GetProxyBypass() | hostconfiguration.HostConfig.proxyBypassList | |
GetRecoveryUrl() | Not available | |
ResetInterfaceSettings() | networkconfiguration.applyConfig() | |
ResetHostSettings() | hostconfiguration.applyConfig() | |
GetCurrentConfig() | networkconfiguration.getConfig()/hostconfiguration.getConfig() | |
TestInterface() | networkdiagnostics.testNetworkInterface() | |
TestInternetConnectivity() | networkdiagnostics.testInternetConnectivity() | |
GetNeighborInformation() | networkconfiguration.getNeighborInformation() | |
ScanWiFi() | networkconfiguration.scan() | |
roNetworkHotplug | ||
roNetworkAttached | ||
roNetworkDetached | ||
roNetworkDiscovery | Not applicable (node.js can be used instead) | |
roNetworkStatistics | Not applicable (See node module net-stat) | |
roPtp | hostconfiguration (see OS 8.0.94 release note) | |
roRssArticle/roRssParser | Not applicable | |
roRtspStream | Use <video> elements | |
roSnmpAgent | net-snmp | npm** |
roStream | Not applicable | |
roSyncManager | BS- JavaScript objects | |
roTCPServer/roTCPStream | net.socket | Node.js® |
roUPnP | Not applicable | |
roUrlTransfer | http | Node.js® |
Input/Output Objects | ||
roBtManager | BS- JavaScript objects | |
roBtClientManager/roBtClient | ||
roCecInterface | BS- JavaScript objects | |
roChannelManager | obsolete | |
roControlPort | BS- JavaScript objects | |
roGpioControlPort | BS- JavaScript objects | |
roIRReceiver | BS- JavaScript objects | |
roIRTransmitter | BS- JavaScript objects | |
roIRRemote | BSIRRemote | |
roKeyboard | ||
roSequenceManager | Not applicable | |
roSerialPort | BS- JavaScript objects | |
System Objects | ||
roDeviceCustomization | Not available | |
roDeviceInfo | ||
roResourceManager | Not applicable | |
roSystemLog | Not available | |
Date and Time Objects | ||
roDateTime | Date | JavaScript built-in |
roSystemTime | ||
roTimer | .setTimeout()/.setInterval() | Web API |
roTimeSpan | Date | JavaScript built-in |
Â
 * substr takes parameters as (from, length).
  substring takes parameters as (from, to).
  slice takes parameters as (from, to).
** npm is a registered trademark of npm, Inc.