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

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()

Math.random()

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 

JavaScript built-in

roAssociativeArray

Not applicable 

JavaScript built-in

roBoolean

Not applicable 

JavaScript built-in

roByteArray

Blob()

Note that JavaScript now has typed arrays (for example, Uint8Array) . 

 

roDouble

Not applicable 

JavaScript built-in

roFunction

Not applicable 

JavaScript built-in

roInt, roFloat, roString

Not applicable 

JavaScript built-in

roList

Use JavaScript built-in function

JavaScript built-in

roMessagePort

Not applicable 

JavaScript built-in

roRegex

RegExp()

JavaScript built-in

roXMLElement

DOMParser()

JavaScript built-in

roXMLList

DOMParser()

JavaScript built-in

Presentation Objects





roAudioEventMx

Not available



roAudioOutput

audiooutput



roAudioPlayer

Use html audio tag



roCanvasWidget

Not applicable 



roClockWidget

Not applicable 



roHdmiInputChanged

videoinput.VideoInputConfiguration.hdmiinputchanged

BrightSign JavaScript API

roHdmiOutputChanged

videooutput.VideoOutputConfiguration.hotplugevent

BrightSign JavaScript API

roHTMLWidget

htmlwidget



roImageBuffer

Not applicable



roImagePlayer

<img> tag in HTML



roImageWidget

<img> tag in HTML



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()

BrightSign JavaScript API

SetMouseRotation()

Not applicable



EnableSerialTouchscreen()

Not available



SetSerialTouchscreenConfiguration()

Not available



GetDiagnosticInfo()

pointerCalibration.getDiagnosticInfoHTML()

BrightSign JavaScript API

StartCalibration()

pointerCalibration.startCalibration()

BrightSign JavaScript API

GetCalibrationStatus()

pointerCalibration.getCalibrationStatus()

BrightSign JavaScript API

ClearStoredCalibration()

pointerCalibration.clearStoredCalibration()

BrightSign JavaScript API

StartEventLogging()

pointerCalibration.startEventLogging()

BrightSign JavaScript API

StopEventLogging()

pointerCalibration.stopEventLogging()

BrightSign JavaScript API

ClearEventLogs()

Not applicable (no information on the log)



SetCalibrationRanges()

pointerCalibration.setCalibrationRanges()

BrightSign JavaScript API

roVIdeoInput

MediaDevices.getUserMedia()

Web API

roVideoMode

videomodeconfiguration



SetMode()

videomodeconfiguration.setMode()

BrightSign JavaScript API

SetModeForNextBoot()

Not applicable (use @brightsign/videomodeconfiguration SetMode())



GetModeForNextBoot()

Not applicable (use @brightsign/videomodeconfiguration getActiveMode())



GetBestMode()

videomodeconfiguration.getBestMode()

BrightSign JavaScript API

GetMode()

videomodeconfiguration.getActiveMode()

BrightSign JavaScript API

GetActiveMode()

videomodeconfiguration.getActiveMode()

BrightSign JavaScript API

GetAvailableModes()

videomodeconfiguration.getAvailableModes()

BrightSign JavaScript API

GetConfiguredMode()

videomodeconfiguration.getConfiguredMode()

BrightSign JavaScript API

GetFPS

videomodeconfiguration.getActiveMode()

BrightSign JavaScript API

SetDecoderMode()

decoderconfiguration.applyConfig()

BrightSign JavaScript API

GetDecoderModes()

decoderconfiguration.getConfig()

BrightSign JavaScript API

Set3DMode()

videooutput.set3dMode()      



Screenshot()

screenshot.syncCapture()/asyncCapture()

BrightSign JavaScript API

GetResX()

videomodeconfiguration.Mode.graphicsPlaneWidth

BrightSign JavaScript API

GetRexY()

videomodeconfiguration.Mode.graphicsPlaneHeight

BrightSign JavaScript API

GetVideoResX()

videomodeconfiguration.Mode.width

BrightSign JavaScript API

GetVideoResY()

videomodeconfiguration.Mode.height

BrightSign JavaScript API

GetOutputResX()

videooutput.Size.width

BrightSign JavaScript API

GetOutputResY()

videooutput.Size.height

BrightSign JavaScript API

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()

BrightSign JavaScript API

ResumeGraphics()

compositor.resume()

BrightSign JavaScript API

SetImageSizeThreshold()

system.setImageSizeThreshold()

BrightSign JavaScript API

AdjustGraphicsColor()

videooutput.adjustGraphicColor()



ConfigureHdmiInput()

videoinput.ApplyConfig()

BrightSign JavaScript API

SetHdmiMetadata()

Not available and possibly not applicable



GetHdmiOutputStatus()

videooutput.getOutputStatus()

BrightSign JavaScript API

GetHdmiInputStatus()

videoinput.getStatus()

BrightSign JavaScript API

GetCompositorCrc()

compositor.getCrc()

BrightSign JavaScript API

GetTxHdcpStatus()

videooutput.getTxHdcpStatus()

BrightSign JavaScript API

ForceHdcpOn()

videooutput.forceHdcpOn()

BrightSign JavaScript API

DisableHdcpRepeater()

videooutput.DisableHdcpRepeater()



SetBackgroundColor()

videooutput.setBackgroundColor()

BrightSign JavaScript API

SetPowerSaveMode()

videooutput.SetPowerSaveMode()

BrightSign JavaScript API

IsAttached()

videooutput.isAttached()

BrightSign JavaScript API

HdmiAudioDisable()

videooutput.disableAudio()

BrightSign JavaScript API

SetMultiscreenBezel()

videooutput.setMultiscreenBezel()

BrightSign JavaScript API

SaveEdids()

videooutput.getEdid() returns EDID information as a hex-encoded string.



GetEdidIdentity()

videooutput.getEdidIdentity()

BrightSign JavaScript API

SetMpcdi()

videooutput.setMpcdi()



SetSyncDomain()

videooutput.setSyncDomain()

BrightSign JavaScript API

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

registry



GetSectionList()

registry.read()

BrightSign JavaScript API

Delete()

registry.write()

BrightSign JavaScript API

Flush()

Not applicable; registry writes are flushed implicitly



roRegistrySection

registry



Read()

registry.read()

BrightSign JavaScript API

Write()

registry.write()

BrightSign JavaScript API

Delete()

registry.write()

BrightSign JavaScript API

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

filesysteminfo and storageinfo



GetBytesPerBlock()

filesysteminfo.getStatistics()

BrightSign JavaScript API

GetSizeInMegabytes()

filesysteminfo.getStatistics()

BrightSign JavaScript API

GetUsedInMegabytes()

node.js fs.stat()



GetFreeInMegabytes()

filesysteminfo.getStatistics()

BrightSign JavaScript API

GetFileSystemType()

filesysteminfo.getFileSystemType()

BrightSign JavaScript API

GetStorageCardInfo()

storageinfo.getStorageCardInfo()

BrightSign JavaScript API

roVirtualMemory

Not available



Content Management Objects





roAssetCollection

Not available



roAssetFetcher

assetpoolfetcher

BrightSign JavaScript API

roAssetPool

assetpool

BrightSign JavaScript API

roAssetPoolFiles

assetpoolfiles



roAssetRealizer

assetrealizer

BrightSign JavaScript API

roSyncSpec

Not applicable



Networking Objects





roDatagramReceiver

Node.js Dgram API



roDatagramSender

Node.js Dgram API



roDatagramSocket

Node.js Dgram API



roHttpServer

Node.js



roKeyStore

keystore

BrightSign JavaScript API

roMediaServer

node-media-server 



roMediaStreamer

Not available



roMimeStream

Not applicable



roNetworkAdvertisement

Not applicable (use node.js)



roNetworkConfiguration

networkconfiguration



Apply()

networkconfiguration.applyConfig()

BrightSign JavaScript API

SetupDWS()

dwsconfiguration

BrightSign JavaScript API

EnableLEDs()

networkconfiguration.enableLeds()

BrightSign JavaScript API

SetClientIdentifier()

networkconfiguration.NetworkInterfaceConfig.clientIdentifier

BrightSign JavaScript API

GetClientIdentifier()

networkconfiguration.NetworkInterfaceConfig.clientIdentifier

BrightSign JavaScript API

SetLoginPassword()

hostconfiguration.HostConfigWritable.loginPassword

BrightSign JavaScript API

SetObfuscatedLoginPassword()

hostconfiguration.HostConfigWritable.ObfuscatedLoginPassword

BrightSign JavaScript API

SetInboundShaperRate()

networkconfiguration.NetworkInterfaceConfig.inboundShaperRate

BrightSign JavaScript API

SetMTU()

networkconfiguration.NetworkInterfaceConfig.mtu

BrightSign JavaScript API

SetRoutingMetric()

networkconfiguration.NetworkInterfaceConfig.metric

BrightSign JavaScript API

SetDHCP()

networkconfiguration.NetworkInterfaceConfig.ipAddressList

BrightSign JavaScript API

SetEnabledProtocols()

networkconfiguration.NetworkInterfaceConfig.enabledProtocolList

BrightSign JavaScript API

SetIP4Address()

networkconfiguration.NetworkInterfaceConfig.ipAddressList

BrightSign JavaScript API

SetIP4Netmask()

networkconfiguration.NetworkInterfaceConfig.ipAddressList

BrightSign JavaScript API

SetIP4Broadcast()

networkconfiguration.NetworkInterfaceConfig.ipAddressList

BrightSign JavaScript API

SetIP4Gateway()

networkconfiguration.NetworkInterfaceConfig.ipAddressList

BrightSign JavaScript API

SetVlanIds()

networkconfiguration.NetworkInterfaceConfig.vlanIdList

BrightSign JavaScript API

SetWiFiESSID()/.GetWiFiESSID()

networkconfiguration.WiFiInterfaceConfig.essId

BrightSign JavaScript API

SetWiFiPassphrase()

networkconfiguration.WiFiInterfaceConfig.passphrase

BrightSign JavaScript API

SetWiFiPassphraseAndObfuscate()

networkconfiguration.WiFiInterfaceConfig.obfuscatedPassphrase

BrightSign JavaScript API

SetWiFiAccessPointMode()

networkconfiguration.WiFiInterfaceConfig.accessPointMode

BrightSign JavaScript API

SetAccessPointFrequencyMHz()

networkconfiguration.WiFiInterfaceConfig.accessPointFrequency

BrightSign JavaScript API

SetWiFiIdentity()

networkconfiguration.WiFiInterfaceConfig.identity

BrightSign JavaScript API

SetWiFiEapTlsOptions()

networkconfiguration.WiFiInterfaceConfig.eapTlsOptions

BrightSign JavaScript API

SetWiFiCACertificates()

networkconfiguration.WiFiInterfaceConfig.caCertificates

BrightSign JavaScript API

SetWiFiClientCertificate()

networkconfiguration.WiFiInterfaceConfig.clientCertificate

BrightSign JavaScript API

SetWiFiPrivateKey()

networkconfiguration.WiFiInterfaceConfig.privateKey

BrightSign JavaScript API

SetWiFiSecurityMode()

networkconfiguration.WiFiInterfaceConfig.securityMode

BrightSign JavaScript API

ConfigureDHCPServer()

networkconfiguration.NetworkInterfaceConfig.dhcpServerConfig

BrightSign JavaScript API

SetForwardingPolicy()

Not available



SetDNSServers()/.AddDNSServer()

networkconfiguration.NetworkInterfaceConfig.dnsServerList

BrightSign JavaScript API

SetTimeServer()

hostconfiguration.HostConfig.timeServerList

BrightSign JavaScript API

SetTimeServerIntervalSeconds()/ GetTimeServerIntervalSecons()

hostconfiguration.HostConfig.timeServerInterval

BrightSign JavaScript API

SetHostName()/.GetHostName()

hostconfiguration.HostConfig.hostName

BrightSign JavaScript API

SetProxy()/.GetProxy()

hostconfiguration.HostConfig.proxy

BrightSign JavaScript API

SetProxyBypass()/.GetProxyBypass()

hostconfiguration.HostConfig.proxyBypassList

BrightSign JavaScript API

GetRecoveryUrl()

Not available



ResetInterfaceSettings()

networkconfiguration.applyConfig()

BrightSign JavaScript API

ResetHostSettings()

hostconfiguration.applyConfig()

BrightSign JavaScript API

GetCurrentConfig()

networkconfiguration.getConfig()/hostconfiguration.getConfig()

BrightSign JavaScript API

TestInterface()

networkdiagnostics.testNetworkInterface()

BrightSign JavaScript API

TestInternetConnectivity()

networkdiagnostics.testInternetConnectivity()

BrightSign JavaScript API

GetNeighborInformation()

networkconfiguration.getNeighborInformation()

BrightSign JavaScript API

ScanWiFi()

networkconfiguration.scan()

BrightSign JavaScript API

roNetworkHotplug

networkhotplug



roNetworkAttached

networkhotplug



roNetworkDetached

networkhotplug



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

BSSyncManager

BS- JavaScript objects

roTCPServer/roTCPStream

net.socket

Node.js®

roUPnP

Not applicable



roUrlTransfer

http

Node.js®

Input/Output Objects





roBtManager

BSBtManager

BS- JavaScript objects

roBtClientManager/roBtClient

BSBtManager



roCecInterface

BSCECTransmitter/BSCECReceiver

BS- JavaScript objects

roChannelManager

obsolete



roControlPort

controlport

BS- JavaScript objects

roGpioControlPort

controlport

BS- JavaScript objects

roIRReceiver

BSIRReceiver

BS- JavaScript objects

roIRTransmitter

BSIRTransmitter

BS- JavaScript objects

roIRRemote

BSIRRemote



roKeyboard

keyboard

BrightSign JavaScript API

roSequenceManager

Not applicable



roSerialPort

BSSerialPort

BS- JavaScript objects

System Objects





roDeviceCustomization

Not available



roDeviceInfo

BSDeviceInfo



roResourceManager

Not applicable



roSystemLog

Not available



Date and Time Objects





roDateTime

Date

JavaScript built-in

roSystemTime

systemtime

BrightSign JavaScript API

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.