summaryrefslogtreecommitdiff
path: root/ext/js/core.js
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-11-09 13:30:31 +0000
committerGitHub <noreply@github.com>2023-11-09 13:30:31 +0000
commit5c5a167b4792af379cdacf633513cebf20728cd2 (patch)
tree5b6be3620a557d0b9177047003f6d742d9d2a32d /ext/js/core.js
parentb64f51c3b13a46af4dd7f1e43048ac19c781ca7b (diff)
parent0f4d36938fd0d844f548aa5a7f7e7842df8dfb41 (diff)
Merge pull request #307 from themoeway/modernize
Modernize codebase
Diffstat (limited to 'ext/js/core.js')
-rw-r--r--ext/js/core.js34
1 files changed, 17 insertions, 17 deletions
diff --git a/ext/js/core.js b/ext/js/core.js
index 1e749c7d..fb164795 100644
--- a/ext/js/core.js
+++ b/ext/js/core.js
@@ -21,7 +21,7 @@
* @param {*} error An error object to convert.
* @returns {{name: string, message: string, stack: string, data?: *}|{value: *, hasValue: boolean}} A simple object which can be serialized by `JSON.stringify()`.
*/
-function serializeError(error) {
+export function serializeError(error) {
try {
if (typeof error === 'object' && error !== null) {
const result = {
@@ -48,7 +48,7 @@ function serializeError(error) {
* @param {{name: string, message: string, stack: string, data?: *}|{value: *, hasValue: boolean}} serializedError A simple object which was initially generated by serializeError.
* @returns {Error|*} A new `Error` instance.
*/
-function deserializeError(serializedError) {
+export function deserializeError(serializedError) {
if (serializedError.hasValue) {
return serializedError.value;
}
@@ -66,7 +66,7 @@ function deserializeError(serializedError) {
* @param {*} value The value to check.
* @returns {boolean} `true` if the value is an object and not an array, `false` otherwise.
*/
-function isObject(value) {
+export function isObject(value) {
return typeof value === 'object' && value !== null && !Array.isArray(value);
}
@@ -76,7 +76,7 @@ function isObject(value) {
* @param {string} string The string to convert to a valid regular expression.
* @returns {string} The escaped string.
*/
-function escapeRegExp(string) {
+export function escapeRegExp(string) {
return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
}
@@ -85,7 +85,7 @@ function escapeRegExp(string) {
* @param {string} string The string to reverse.
* @returns {string} The returned string, which retains proper UTF-16 surrogate pair order.
*/
-function stringReverse(string) {
+export function stringReverse(string) {
return [...string].reverse().join('');
}
@@ -95,7 +95,7 @@ function stringReverse(string) {
* @returns {*} A new clone of the value.
* @throws An error if the value is circular and cannot be cloned.
*/
-const clone = (() => {
+export const clone = (() => {
// eslint-disable-next-line no-shadow
function clone(value) {
if (value === null) { return null; }
@@ -168,7 +168,7 @@ const clone = (() => {
* @param {*} value2 The second value to check.
* @returns {boolean} `true` if the values are the same object, or deeply equal without cycles. `false` otherwise.
*/
-const deepEqual = (() => {
+export const deepEqual = (() => {
// eslint-disable-next-line no-shadow
function deepEqual(value1, value2) {
if (value1 === value2) { return true; }
@@ -239,7 +239,7 @@ const deepEqual = (() => {
* @param {number} length The number of bytes the string represents. The returned string's length will be twice as long.
* @returns {string} A string of random characters.
*/
-function generateId(length) {
+export function generateId(length) {
const array = new Uint8Array(length);
crypto.getRandomValues(array);
let id = '';
@@ -253,7 +253,7 @@ function generateId(length) {
* Creates an unresolved promise that can be resolved later, outside the promise's executor function.
* @returns {{promise: Promise, resolve: Function, reject: Function}} An object `{promise, resolve, reject}`, containing the promise and the resolve/reject functions.
*/
-function deferPromise() {
+export function deferPromise() {
let resolve;
let reject;
const promise = new Promise((resolve2, reject2) => {
@@ -269,7 +269,7 @@ function deferPromise() {
* @param {*} [resolveValue] The value returned when the promise is resolved.
* @returns {Promise} A promise with two additional properties: `resolve` and `reject`, which can be used to complete the promise early.
*/
-function promiseTimeout(delay, resolveValue) {
+export function promiseTimeout(delay, resolveValue) {
if (delay <= 0) {
const promise = Promise.resolve(resolveValue);
promise.resolve = () => {}; // NOP
@@ -312,7 +312,7 @@ function promiseTimeout(delay, resolveValue) {
* and `timeout` is a boolean indicating whether the cause was a timeout or not.
* @throws The promise throws an error if animation is not supported in this context, such as in a service worker.
*/
-function promiseAnimationFrame(timeout=null) {
+export function promiseAnimationFrame(timeout=null) {
return new Promise((resolve, reject) => {
if (typeof cancelAnimationFrame !== 'function' || typeof requestAnimationFrame !== 'function') {
reject(new Error('Animation not supported in this context'));
@@ -362,7 +362,7 @@ function promiseAnimationFrame(timeout=null) {
* @param {...*} extraArgs Additional arguments which are passed to the `handler` function.
* @returns {boolean} `true` if the function is invoked asynchronously, `false` otherwise.
*/
-function invokeMessageHandler({handler, async}, params, callback, ...extraArgs) {
+export function invokeMessageHandler({handler, async}, params, callback, ...extraArgs) {
try {
let promiseOrResult = handler(params, ...extraArgs);
if (async === 'dynamic') {
@@ -387,7 +387,7 @@ function invokeMessageHandler({handler, async}, params, callback, ...extraArgs)
/**
* Base class controls basic event dispatching.
*/
-class EventDispatcher {
+export class EventDispatcher {
/**
* Creates a new instance.
*/
@@ -462,7 +462,7 @@ class EventDispatcher {
/**
* Class which stores event listeners added to various objects, making it easy to remove them in bulk.
*/
-class EventListenerCollection {
+export class EventListenerCollection {
/**
* Creates a new instance.
*/
@@ -551,7 +551,7 @@ class EventListenerCollection {
* Class representing a generic value with an override stack.
* Changes can be observed by listening to the 'change' event.
*/
-class DynamicProperty extends EventDispatcher {
+export class DynamicProperty extends EventDispatcher {
/**
* Creates a new instance with the specified value.
* @param {*} value The value to assign.
@@ -657,7 +657,7 @@ class DynamicProperty extends EventDispatcher {
* This class handles logging of messages to the console and triggering
* an event for log calls.
*/
-class Logger extends EventDispatcher {
+export class Logger extends EventDispatcher {
/**
* Creates a new instance.
*/
@@ -759,4 +759,4 @@ class Logger extends EventDispatcher {
/**
* This object is the default logger used by the runtime.
*/
-const log = new Logger();
+export const log = new Logger();