Domonic: Javascript

There is a javascript package being started that mirrors the js API:

from domonic.javascript import Math
print(Math.random())

from domonic.javascript import Array
myArr=Array(1,2,3)
print(myArr.splice(1))

from domonic.javascript import URL
url = URL('https://somesite.com/blog/article-one#some-hash')
print(url.protocol)
print(url.host)
print(url.pathname)
print(url.hash)

# from domonic.javascript import Global
# Global.decodeURIComponent(...
# Global.encodeComponent(...

# from domonic.javascript import Date
# etc..

setInterval

You can use setInterval and clearInterval with params

x=0

def hi(inc):
    global x
    x = x+inc
    print(x)

test = window.setInterval(hi, 1000, 2)
import time
time.sleep(5)
window.clearInterval(test)
print(f"Final value of x:{x}")

You can update a-tags the same way as it inherits from URL:

from domonic.html import *

atag = a(_href="https://somesite.com:8000/blog/article-one#some-hash")
print('href:',atag.href)
print('protocol:',atag.protocol)
print('port:',atag.port)

atag.protocol = "http"
atag.port = 8983
print(atag)

Styling

mytag = div("hi", _id="test")
mytag.style.backgroundColor = "black"
mytag.style.fontSize = "12px"
print(mytag)
# <div id="test" style="background-color:black;font-size:12px;">hi</div>

several other undocumented features. Take a look at the code.

domonic.javascript

class domonic.javascript.Array(*args)[source]

javascript array

concat(value)[source]

Joins two or more arrays, and returns a copy of the joined arrays

copyWithin()[source]

Copies array elements within the array, to and from specified positions

entries()[source]

Returns a key/value pair Array Iteration Object

every(test)[source]

Checks if every element in an array pass a test

fill()[source]

Fill the elements in an array with a static value

filter(func)[source]

Creates a new array with every element in an array that pass a test even_numbers = someArr.filter( lambda x: x % 2 == 0 )

find()[source]

Returns the value of the first element in an array that pass a test

findIndex()[source]

Returns the index of the first element in an array that pass a test

forEach()[source]

Calls a function for each array element

includes(value)[source]

Check if an array contains the specified element

indexOf(value)[source]

Search the array for an element and returns its position

isArray()[source]

Checks whether an object is an array

join(value)[source]

Joins all elements of an array into a string

keys()[source]

Returns a Array Iteration Object, containing the keys of the original array

lastIndexOf(value)[source]

Search the array for an element, starting at the end, and returns its position

length

Sets or returns the number of elements in an array

map()[source]

Creates a new array with the result of calling a function for each array element

pop()[source]

Removes the last element of an array, and returns that element

push(value)[source]

Adds new elements to the end of an array, and returns the new length

reduce()[source]

Reduce the values of an array to a single value (going left-to-right)

reduceRight()[source]

Reduce the values of an array to a single value (going right-to-left)

reverse()[source]

Reverses the order of the elements in an array

shift()[source]

removes the first element from an array and returns that removed element

slice(start, stop, step=1)[source]

Selects a part of an array, and returns the new array

some()[source]

Checks if any of the elements in an array pass a test

sort()[source]

Sorts the elements of an array

splice(start, delete_count=None, *items)[source]

Selects a part of an array, and returns the new array

toString()[source]

Converts an array to a string, and returns the result

unshift(*args)[source]

Adds new elements to the beginning of an array, and returns the new length

class domonic.javascript.Date(date: str = None, formatter='python')[source]

javascript date

UTC()[source]

Returns the number of milliseconds in a date since midnight of January 1, 1970, according to UTC time

getDate()[source]

Returns the day of the month (from 1-31)

getDay()[source]

Returns the day of the week (from 0-6)

getFullYear()[source]

Returns the year

getHours()[source]

Returns the hour (from 0-23)

getMilliseconds()[source]

Returns the milliseconds (from 0-999)

getMinutes()[source]

Returns the minutes (from 0-59)

getMonth()[source]

Returns the month (from 0-11)

getSeconds()[source]

Returns the seconds (from 0-59)

getTime()[source]

Returns the number of milliseconds since midnight Jan 1 1970, and a specified date

getUTCDate()[source]

Returns the day of the month, according to universal time (from 1-31)

getUTCDay()[source]

Returns the day of the week, according to universal time (from 0-6)

getUTCFullYear()[source]

Returns the year, according to universal time

getUTCHours()[source]

Returns the hour, according to universal time (from 0-23)

getUTCMilliseconds()[source]

Returns the milliseconds, according to universal time (from 0-999)

getUTCMinutes()[source]

Returns the minutes, according to universal time (from 0-59)

getUTCMonth()[source]

Returns the month, according to universal time (from 0-11)

getUTCSeconds()[source]

Returns the seconds, according to universal time (from 0-59)

getYear()[source]

Deprecated. Use the getFullYear() method instead

now()[source]

Returns the number of milliseconds since midnight Jan 1, 1970

parse(date_string)[source]

Parses a date string and returns the number of milliseconds since January 1, 1970

setDate(day)[source]

Sets the day of the month of a date object

setFullYear(year)[source]

Sets the year of a date object

setHours(hours)[source]

Sets the hour of a date object

setMilliseconds(milliseconds)[source]

Sets the milliseconds of a date object

setMinutes(minutes)[source]

Set the minutes of a date object

setMonth(month)[source]

Sets the month of a date object

setSeconds(seconds)[source]

Sets the seconds of a date object

setTime()[source]

Sets a date to a specified number of milliseconds after/before January 1, 1970

setUTCDate(day)[source]

Sets the day of the month of a date object, according to universal time

setUTCFullYear(year)[source]

Sets the year of a date object, according to universal time

setUTCHours(hour)[source]

Sets the hour of a date object, according to universal time

setUTCMilliseconds(milliseconds)[source]

Sets the milliseconds of a date object, according to universal time

setUTCMinutes(minutes)[source]

Set the minutes of a date object, according to universal time

setUTCMonth(month)[source]

Sets the month of a date object, according to universal time

setUTCSeconds(seconds)[source]

Set the seconds of a date object, according to universal time

setYear(year)[source]

Deprecated. Use the setFullYear() method instead

toDateString()[source]

Converts the date portion of a Date object into a readable string

toGMTString()[source]

Deprecated. Use the toUTCString() method instead

toISOString()[source]

Returns the date as a string, using the ISO standard

toJSON()[source]

Returns the date as a string, formatted as a JSON date

toLocaleDateString()[source]

Returns the date portion of a Date object as a string, using locale conventions

toLocaleString()[source]

Converts a Date object to a string, using locale conventions

toLocaleTimeString()[source]

Returns the time portion of a Date object as a string, using locale conventions

toTimeString()[source]

Converts the time portion of a Date object to a string

toUTCString()[source]

Converts a Date object to a string, according to universal time

class domonic.javascript.Global[source]

javascript global methods

NaN()[source]

“Not-a-Number” value

static Number(x)[source]

Converts an object’s value to a number

static String(x)[source]

Converts an object’s value to a string

static decodeURI(x)[source]

Decodes a URI

static decodeURIComponent(x)[source]

Decodes a URI component

static encodeURI(x)[source]

Encodes a URI

static encodeURIComponent(x)[source]

Encodes a URI component

static isFinite()[source]

Determines whether a value is a finite, legal number

static isNaN(x)[source]

Determines whether a value is an illegal number

static parseFloat(x)[source]

Parses a string and returns a floating point number

static parseInt(x)[source]

Parses a string and returns an integer

undefined()[source]

Indicates that a variable has not been assigned a value

class domonic.javascript.Job(interval, execute, *args, **kwargs)[source]
run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class domonic.javascript.Math[source]

Math class that mirrors javascript implementation

class domonic.javascript.Navigator(*args, **kwargs)[source]

navigator

class domonic.javascript.Number(x='', *args, **kwargs)[source]

javascript Number methods

isInteger()[source]

Checks whether a value is an integer

isSafeInteger()[source]

Checks whether a value is a safe integer

toExponential(num)[source]

Converts a number into an exponential notation

toFixed(num)[source]

Formats a number with x numbers of digits after the decimal point

toPrecision(num)[source]

Formats a number to x length

exception domonic.javascript.ProgramKilled[source]
class domonic.javascript.Screen[source]

screen

availHeight()[source]

Returns the height of the screen (excluding the Windows Taskbar)

availWidth()[source]

Returns the width of the screen (excluding the Windows Taskbar)

colorDepth()[source]

Returns the colorDepth

height()[source]

Returns the total height of the screen

pixelDepth()[source]

Returns the pixelDepth

width()[source]

Returns the total width of the screen

class domonic.javascript.String(x='', *args, **kwargs)[source]

javascript string method

charAt(index)[source]

Returns the character at the specified index (position)

charCodeAt(index)[source]

Returns the Unicode of the character at the specified index

endsWith(x, start, end)[source]

Checks whether a string ends with specified string/characters

fromCharCode(code)[source]

Converts Unicode values to characters

repeat(count)[source]

Returns a new string with a specified number of copies of an existing string

replace(old, new)[source]

Searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced

startsWith(x, start, end)[source]

Checks whether a string begins with specified characters

substring()[source]

Extracts the characters from a string, between two specified indices

toLowerCase()[source]

Converts a string to lowercase letters

toUpperCase()[source]

Converts a string to uppercase letters

trim()[source]

Removes whitespace from both ends of a string

class domonic.javascript.URL(url: str = '', *args, **kwargs)[source]

a tag extends from URL

hash

” hash Sets or returns the anchor part (#) of a URL

class domonic.javascript.Window(*args, **kwargs)[source]

window

static alert(msg)[source]

Displays an alert box with a message and an OK button

static prompt(msg, default_text='')[source]

Displays a dialog box that prompts the visitor for input

static setTimeout(function, t, *args, **kwargs)[source]

Calls a function or evaluates an expression after a specified number of milliseconds

class domonic.javascript.js_object[source]
valueOf()[source]

Returns the primitive value of an array Array, Boolean, Date, Number, String

domonic.javascript.window

alias of domonic.javascript.Window