Guía de migración de BrightScript a JavaScript
Esta página describe la asignación entre las APIs de BrightScript y JavaScript. La funcionalidad de BrightScript se implementa en JavaScript mediante la API de JavaScript de BrightSignBrightSign JavaScript API y los antiguos Objetos BrightScript-JavaScriptBS- JavaScript objects; las APIs de BrightScript no se migran cuando las bibliotecas estándar de JavaScript proporcionan una funcionalidad equivalente.
Si el equivalente en JavaScript es "No disponible", la funcionalidad no está implementada actualmente, pero debería estarlo en el futuro. Si el equivalente es "No aplicable", el método correspondiente de BrightScript no tendría sentido en JavaScript o no es necesario por otros motivos.
Funciones globales
API de BrightScript | Equivalente en JavaScript | Biblioteca |
|---|---|---|
CreateObject() | No aplicable | |
RestartScript() | No aplicable | |
RestartApplication() | process.exit() | Node.js® |
Sleep() | No aplicable | |
asc() | String.charCodeAt() | Integrado de JavaScript |
chr() | String.fromCharCode() | Integrado de JavaScript |
len() | String.length | Integrado de JavaScript |
str() | Number.toString() | Integrado de JavaScript |
strl() | Number.toString() | Integrado de JavaScript |
val() | Number() | Integrado de JavaScript |
abs() | Math.abs() | Integrado de JavaScript |
atn() | Math.atan() | Integrado de JavaScript |
csng() | No aplicable | |
cdbl() | No aplicable | |
cint() | No aplicable | |
cos() | Math.cos() | Integrado de JavaScript |
exp() | Math.exp() | Integrado de JavaScript |
fix() | Number.toFixed() | Integrado de JavaScript |
int() | Math.trunc() | Integrado de JavaScript |
log() | Math.log() | Integrado de JavaScript |
sgn() | Math.sign() | Integrado de JavaScript |
sgnl() | Math.sign() | Integrado de JavaScript |
sin() | Math.sin() | Integrado de JavaScript |
tan() | Math.tan() | Integrado de JavaScript |
sqr() | Math.sqrt() | Integrado de JavaScript |
Left(target_string, n) | target_string.substr(0, n)* | Integrado de JavaScript |
Right(target_string, n) | target_string.substr(target_string.length - n)* target_string.substr(-n)* | Integrado de JavaScript |
StringI() | String.repeat() | Integrado de JavaScript |
Mid(target_string, start_position, length | target_string.substr(start_position, length)* | Integrado de JavaScript |
Instr() | String.indexOf() | Integrado de JavaScript |
GetInterface() | Acceder a interfaces de objetos como cadenas | |
Wait() | No aplicable en JavaScript, a menos que la función se utilice sin referencia a puertos y únicamente para retrasar la ejecución durante un tiempo, en cuyo caso, utilice setTimeout(). | Integrado de JavaScript |
ReadAsciiFile() | readFileSync()** | Node.js® |
WriteAsciiFile() | fs.writeFile()** | Node.js® |
ListDir() | fs.readDir()** | Node.js® |
MatchFiles() | fs.readDir()** Se necesita código JavaScript adicional para completar la coincidencia. | Node.js® |
LCase() | String.toLowerCase() | Integrado en JavaScript |
UCase() | String.toUpperCase() | Integrado en JavaScript |
DeleteFile() | fs.unlink()** | Node.js® |
DeleteDirectory() | fs.rmdir()** | Node.js® |
CreateDirectory() | fs.mkdir()** | Node.js® |
RebootSystem() | system.reboot() | API de JavaScript de BrightSign |
ShutdownSystem() | No disponible | |
UpTime() | OS.uptime() | Node.js® |
FormatDrive() | No hay un equivalente exacto. | |
EjectDrive() | No disponible | |
CopyFile() | fs.copyFile()** | Node.js® |
MoveFile() | fs.rename()** | Node.js® |
MapFilenameToNative() | No aplicable | |
strtoi() | parseInt() strtoi() analiza en base 10, mientras que JavaScript admite cualquier base. | Integrado en JavaScript |
rnd() | Integrado en JavaScript | |
RunGarbageCollector() | No aplicable | |
GetDefaultDrive() | No aplicable | Node.js® |
SetDefaultDrive() | process.chdir() | Node.js® |
EnableZoneSupport() | No aplicable | |
EnableAudioMixer() | No aplicable | |
Pi() | Math.PI | Integrado en JavaScript |
ParseJson() | JSON.parse() BrightScript devuelve Invalid en el caso de cadenas problemáticas, mientras que JavaScript lanza una excepción. | Integrado en JavaScript |
FormatJson() | JSON.stringify() JSON.stringify debe invocarse con un reemplazador personalizado, por ejemplo, Cyclic_object_value o WebReflection/flatted#flatted | Integrado en JavaScript |
* substr toma parámetros como (from, length). substring toma parámetros como (from, to). slice toma parámetros como (from, to).
** Las operaciones asíncronas son siempre preferibles.
Objetos principales
API de BrightScript | Equivalente en JavaScript | Biblioteca |
|---|---|---|
roArray | No aplicable | |
roAssociativeArray | No aplicable | |
roBoolean | No aplicable | |
roByteArray | Blob() (JavaScript ahora tiene typed arrays; por ejemplo, Uint8Array) | |
roDouble | No aplicable | |
roFunction | No aplicable | |
roInt, roFloat, roString | No aplicable | |
roList | Usar la función integrada de JavaScript | |
roMessagePort | No aplicable | |
roRegex | RegExp() | |
roXMLElement | DOMParser() | |
roXMLList | DOMParser() |
Objetos de presentación
API de BrightScript | Equivalente en JavaScript | Biblioteca |
|---|---|---|
roAudioEventMx | No disponible | |
roAudioOutput | salida de audioaudiooutput | |
roAudioPlayer | Use la etiqueta audio de HTML | |
roCanvasWidget | No aplicable | |
roClockWidget | No aplicable | |
roHdmiInputChanged | videoinput.VideoInputConfiguration.hdmiinputchanged | API de JavaScript de BrightSignBrightSign JavaScript API |
roHdmiOutputChanged | videooutput.VideoOutputConfiguration.hotplugevent | API de JavaScript de BrightSignBrightSign JavaScript API |
roHTMLWidget | widget HTMLhtmlwidget | |
roImageBuffer | No aplicable | |
roImagePlayer | | |
roImageWidget | | |
roRectangle | No aplicable | |
roStreamQueue | No disponible | |
roTextField | No aplicable | |
roTextWidget | No aplicable | |
roTouchEvent | TouchEvent() | Web API |
roTouchScreen | No disponible | |
SetResolution() | El navegador realiza la asignación | |
AddRectangle() | Asignar propiedades de cursor CSS al cursor de hardware | |
AddCircleRegion() | Asignar propiedades de cursor CSS al cursor de hardware | |
ClearRegions() | No aplicable | |
GetDeviceName() | No aplicable | |
SetCursorPosition() | Simular eventos del cursor del mouse en JavaScript | |
SetCursorBitmap() | Asignar propiedades de cursor CSS al cursor de hardware | |
EnableCursor() | Asignar propiedades de cursor CSS al cursor de hardware | |
EnableRollover() | No aplicable | |
EnableRegion() | Asignar propiedades de cursor CSS al cursor de hardware | |
SetRollOverOrigin() | Asignar propiedades de cursor CSS al cursor de hardware | |
IsMousePresent() | pointer.isMousePresent() | |
SetMouseRotation() | No aplicable | |
EnableSerialTouchscreen() | No disponible | |
SetSerialTouchscreenConfiguration() | No disponible | |
GetDiagnosticInfo() | pointerCalibration.getDiagnosticInfoHTML() | |
StartCalibration() | pointerCalibration.startCalibration() | |
GetCalibrationStatus() | pointerCalibration.getCalibrationStatus() | |
ClearStoredCalibration() | pointerCalibration.clearStoredCalibration() | |
StartEventLogging() | pointerCalibration.startEventLogging() | |
StopEventLogging() | pointerCalibration.stopEventLogging() | |
ClearEventLogs() | No aplicable (sin información en el registro) | |
SetCalibrationRanges() | pointerCalibration.setCalibrationRanges() | |
roVIdeoInput | MediaDevices.getUserMedia() | Web API |
roVideoMode | | |
SetMode() | videomodeconfiguration.setMode() | |
SetModeForNextBoot() | No aplicable (use @brightsign/videomodeconfiguration SetMode()) | |
GetModeForNextBoot() | No aplicable (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 | objetos BS-JavaScript |
GetSafeY() | BSVideoMode.safeY | Objetos BS-JavaScript |
SafeWidth() | BSVideoMode.safeWidth | Objetos BS-JavaScript |
SafeHeight() | BSVideoMOde.safeHeight | Objetos BS-JavaScript |
SetGraphicsZOrder | No aplicable | |
PauseGraphics() | compositor.pause() | |
ResumeGraphics() | compositor.resume() | |
SetImageSizeThreshold() | system.setImageSizeThreshold() | |
AdjustGraphicsColor() | videooutput.adjustGraphicColor() | |
ConfigureHdmiInput() | videoinput.ApplyConfig() | |
SetHdmiMetadata() | No disponible y posiblemente no aplicable | |
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() devuelve información EDID como una cadena codificada en hexadecimal. | |
GetEdidIdentity() | videooutput.getEdidIdentity() | |
SetMpcdi() | videooutput.setMpcdi() | |
SetSyncDomain() | videooutput.setSyncDomain() | |
roVideoPlayer | Use elementos <video> con propiedades de BrightSign | |
Objetos de archivo
Use la API de archivos de Node.js.
Objetos de hash y almacenamiento
API de BrightScript | Equivalente en JavaScript | Biblioteca |
|---|---|---|
roBlockCipher | API de Crypto de Node.js | |
roBrightPackage | API de Zlib de Node.js | |
roDiskErrorEvent | No disponible | |
roDiskMonitor | No disponible | |
roHashGenerator | API de Crypto de Node.js | |
roPassKey | API de Crypto de Node.js | |
roRegistry | registro | |
GetSectionList() | registry.read() | |
Delete() | registry.write() | |
Flush() | No aplicable; las escrituras del registro se vacían implícitamente | |
roRegistrySection | registro | |
Read() | registry.read() | |
Write() | registry.write() | |
Exists() | No aplicable (USE read seguido de una verificación truthy en la clave del registro) | |
GetKeyList() | No aplicable (Use read seguido de 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 | No disponible | |
Objetos de administración de contenido
API de BrightScript | Equivalente en JavaScript | Biblioteca |
|---|---|---|
roAssetCollection | No disponible | |
roAssetFetcher | ||
roAssetPool | ||
roAssetPoolFiles | | |
roAssetRealizer | ||
roSyncSpec | No aplicable | |
Objetos de red
API de BrightScript | Equivalente en JavaScript | Biblioteca |
|---|---|---|
roDatagramReceiver | API Dgram de Node.js | |
roDatagramSender | API Dgram de Node.js | |
roDatagramSocket | API Dgram de Node.js | |
roHttpServer | Node.js | |
roKeyStore | keystore | |
roMediaServer | node-media-server | |
roMediaStreamer | No disponible | |
roMimeStream | No aplicable | |
roNetworkAdvertisement | No aplicable (usar 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() | No disponible | |
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() | No disponible | |
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 | No aplicable (se puede usar node.js en su lugar) | |
roNetworkStatistics | No aplicable (consulte el módulo node net-stat) | |
roPtp | configuración del host (consulte la nota de la versión OS 8.0.94) | |
roRssArticle/roRssParser | No aplicable | |
roRtspStream | Use elementos <video> | |
roSnmpAgent | net-snmp | npm*** |
roStream | No aplicable | |
roSyncManager | BSSyncManagerBSSyncManager | objetos BS-JavaScript |
roTCPServer/roTCPStream | net.socket | Node.js® |
roUPnP | No aplicable | |
roUrlTransfer | http | Node.js® |
*** npm es una marca registrada de npm, Inc.
Objetos de entrada/salida
API de BrightScript | Equivalente en JavaScript | Biblioteca |
|---|---|---|
roBtManager | BSBtManager | Objetos de BS-JavaScript |
roBtClientManager/roBtClient | BSBtManager | |
roCecInterface | cec | |
roChannelManager | obsoleto | |
roControlPort | controlport | Objetos de BS-JavaScript |
roGpioControlPort | controlport | Objetos de BS-JavaScript |
roIRReceiver | BSIRReceiver | Objetos de BS-JavaScript |
roIRTransmitter | Objetos BS-JavaScript | |
roIRRemote | BSIRRemote | |
roKeyboard | teclado | |
roSequenceManager | No aplicable | |
roSerialPort | BSSerialPort | Objetos BS-JavaScript |
Objetos del sistema
API de BrightScript | Equivalente en JavaScript | Biblioteca |
|---|---|---|
roDeviceCustomization | No disponible | |
roDeviceInfo | BSDeviceInfo | |
roResourceManager | No aplica | |
roSystemLog | No disponible | |
Objetos de fecha y hora
API de BrightScript | Equivalente en JavaScript | Biblioteca |
|---|---|---|
roDateTime | Date | Integrado de JavaScript |
roSystemTime | ||
roTimer | .setTimeout()/.setInterval() | Web API |
roTimeSpan | Date | Integrado de JavaScript |