javascript

There’s a javascript package that mimics the js API.

It’s useful for things like quickly porting javascript code to python but also if you already know javascript:

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, String, Number
# etc..

As as all of the usual String and Numbers methods you may be familiar with.

Date class

The Date class is available…

from domonic.javascript import Date
print(Date.now())

Array methods

All the javascript array methods you may be familiar with available python

myarr = Array("1", "2", 3, {"4": "four"}, 5, [6])

print(myarr.length)
print(myarr.includes("1"))
print(myarr.includes(3))
print(myarr.includes(10))
print(myarr.indexOf(10))
print(myarr.indexOf("1"))
print(myarr.indexOf([6]))
print(myarr[1])
print(len(myarr))
print(myarr.join('---'))  #  TODO - test some js ones
print(myarr.lastIndexOf("1"))
print(myarr.lastIndexOf(3))
print(myarr.reverse())
print(myarr.slice(0, 1))
print(myarr.splice(1))
# print(myarr.splice(2))
# print(myarr.splice(3))
# print(myarr.splice(4))
print(myarr.splice(3, 3, "a", "b", "c"))
print(myarr)
print(myarr.pop())
print(myarr)
myarr.push(7)
print(myarr)
print(myarr.unshift('z'))
print(myarr)
print(myarr.shift())
print(myarr)
# print(myarr.concat())

# myarr.sort()
# myarr.fill()
# myarr.isArray()?
# myarr.map()
# myarr.reduce()
# myarr.reduceRight()
# myarr.some()

String methods

A whole bunch of familiar string methods for you to enjoy…

mystr = String("Some String")

mystr.toLowerCase() # "some string"
mystr.toUpperCase() # "SOME STRING"
# print(mystr.length)
mystr.repeat(2) # "Some StringSome String"
print(mystr.startsWith('S'))
# mystr.endsWith('g'))

# javascript substr in python
mystr.substr(1) # 'ome String'

# javascript slice in python
# print(mystr.slice(1, 3))
mystr.slice(1, 3) # 'om')

# trim
mystr = String("   Some String   ")
mystr.trim() # "Some String")

# charAt
mystr = String("Some String")
mystr.charAt(1) # 'o'
mystr.charAt(5) # 'S'

# charCodeAt
mystr.charCodeAt(1) # 111
mystr.fromCharCode(111) # 'o'

# test
# mystr.test('a') # True
# mystr.test('b') # False

# replace
# print(mystr.replace('S', 'X'))
mystr.replace('S', 'X') # "Xome String"
mystr.replace(' ', 'X') # "SomeXString"
mystr.replace('S', 'X') != "Xome Xtring"

# search
mystr = String("Some String")
mystr.search('a') # False
mystr.search('o') # True

# substr
print(mystr.substr(1, 2))
mystr.substr(1, 2) # 'om')
mystr.substr(1, 3) # 'ome')
mystr.substr(1, 4) # 'ome ')
mystr.substr(1, 5) # 'ome S')

# toLocaleLowerCase
mystr.toLocaleLowerCase() # 'some string'
mystr.toLocaleLowerCase() # 'some string'

# toLocaleUpperCase
# print(mystr.toLocaleUpperCase())
mystr.toLocaleUpperCase() # 'SOME STRING'

# lastIndex
# print(mystr.lastIndexOf('o'))
mystr.lastIndexOf('o') # 1

assert mystr.padEnd(13) # "Some String  "
assert mystr.padStart(13) # "  Some String"
assert mystr.padStart(13, '-') # "--Some String"

mystr.includes('a') # False
mystr.includes('Some') # True

Plus some obsolete friends to do fancy tricks with!!… i.e

>>> test = String("Hello Wolrd!")
>>> test.blink()
>>> test.sub()
>>> test.sup()
>>> test.div() # ?? hang on?
>>> test.webpage() # ??? err... wait what!!!

You can actually transform a type String into any tag.

Simply call `()` on a stringvar to transform it into a Node

>>> test = String("time to take a mo")
>>> test('div', _style="font-color:red;")
>>> str(test('div', _style="font-color:red;"))

passing it the tag and attributes…

Object methods

Object is useful for making dicts a bit more js-like…

o = Object()
o.prop = 'hi'
str(o)

But also contains a growing list of methods you may know from javascript.

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}")

fetch

There’s a fetch implementation that uses promises. With additional mulithreaded and pooled versions.

from domonic.javascript import *

urls = ['http://google.com', 'http://linkedin.com', 'http://eventual.technology']  # use your own domains

print('run 1')
results = window.fetch(urls[0])
results.then(lambda r: print(r.text))
print('run 1 FINISHED')

def somefunc(response):
        print("I'm a callback", response.ok)
        return response

mydata = window.fetch(urls[0]).then(somefunc)
print(mydata)
print(mydata.data)
print(mydata.data.text)

# fetch more than one
results = window.fetch_set(urls)
print(results)
print(list(results))
for r in results:
        if r is not None:
                print(r.ok)
                # print(r.text)

# multi-threaded
results = window.fetch_threaded(urls)
print(results)
print(list(results))
for r in results:
        if r is not None:
                print(r.ok)
                # print(r.text)

# pooled
results = window.fetch_pooled(urls, timeout=2)
print(results)
for r in results:
        if r is not None:
                print(r.ok)
                # print(r.text)

print('run 4')
results = window.fetch(urls[0])
print(results)
results.then(lambda r: print(r.text) if r is not None else None)

All fetch methods use requests and will pass all the kwargs along should you need to modify

keywords

If you `import *` you will get the js keywords… i.e.

print(true)  # True
print(false) # False
print(undefined) # None
print(null) # None

As well as a function which evaluates python strings…

sup = function('''print("hi")''')
sup()

Typed arrays

js style typed arrays are even available

Styling

Styling gets passed to the style tag on render.

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>

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

domonic.javascript

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

javascript array

at(index: int)[source]

[takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array.]

Parameters

index ([type]) – [position of item]

Returns

[item at the given position]

Return type

[type]

concat(*args)[source]

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

Returns

[returns a copy of the joined arrays]

Return type

[list]

copyWithin(target, start=0, end=None)[source]

Copies array elements within the array, from start to end

entries()[source]

[Returns a key/value pair Array Iteration Object]

Yields

[type] – [key/value pair]

every(func)[source]

[Checks if every element in an array pass a test]

Parameters

func ([type]) – [test function]

Returns

[if every array elemnt passed the test]

Return type

[bool]

fill(value=None, start=None, end=None)[source]

[Fills elements of an array from a start index to an end index with a static value]

filter(func)[source]

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

find(func)[source]

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

findIndex(value)[source]

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

findLast(callback)[source]

[Returns the last element in an array that passes a test]

findLastIndex(callback)[source]

[Returns the last index of an element in an array that passes a test]

flat(depth=1)[source]

[Flattens an array into a single-dimensional array or a depth of arrays]

flatMap(fn)[source]

[Maps a function over an array and flattens the result]

forEach(func)[source]

Calls a function for each array element

static from_(obj)[source]

Creates a new Array instance from an array-like or iterable object.

groupBy(callback) dict[source]

[Groups the elements of an array according to the result of calling a callback function on each element]

Parameters

callback (callable) – [the callback recieves the following paramters(value, index, target)]

Returns

[a dictionary of arrays]

Return type

[dict]

includes(value)[source]

[Check if an array contains the specified item

Parameters

value ([any]) – [any value]

Returns

[a boolean]

Return type

[bool]

indexOf(value)[source]

Search the array for an element and returns its position

static isArray(thing)[source]

[Checks whether an object is an array]

Parameters

thing ([type]) – [thing to check]

Returns

[True if the object is list, tuple or Array]

Return type

[bool]

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

property length

Sets or returns the number of elements in an array

map(func)[source]

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

Parameters

func ([type]) – [a function to call on each array element]

Returns

[a new array]

Return type

[list]

static of(*args)[source]

Creates a new Array instance with a variable number of arguments, regardless of number or type of the arguments.

pop()[source]

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

prototype

alias of Array

push(value)[source]

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

reduce(callback, initialValue=None)[source]

Reduces the array to a single value (going left-to-right) callback recieve theses parameters: previousValue, currentValue, currentIndex, array

reduceRight(callback, initialValue=None)[source]

Reduces the array to a single value (going right-to-left) callback recieve theses parameters: previousValue, currentValue, currentIndex, array

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]

Returns

[the removed array element]

Return type

[type]

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

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

Parameters
  • start ([int]) – [index to slice from]

  • stop ([int], optional) – [index to slice to]. Defaults to end of the array.

  • step (int, optional) – [description]. Defaults to 1.

Returns

[new array]

Return type

[type]

some(func)[source]

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

sort(func=None)[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

toSource()[source]

Returns the source 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]

Returns

[the length of the array]

Return type

[int]

class domonic.javascript.Boolean(value=False)[source]

[Creates a Boolean Object. Warning this is NOT a boolean type. for that use Global.Boolean()]

class domonic.javascript.Date(date=None, *args, formatter='python', **kwargs)[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 : Sunday-Saturday)

Returns

An integer number, between 0 and 6, corresponding to the day of the week for the given date, according to local time: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on

Return type

int

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 A number representing the milliseconds elapsed between 1 January 1970 00:00:00 UTC and self.date

getTimezoneOffset()[source]

Returns the difference, in minutes, between a date as evaluated in the UTC time zone, and the same date as evaluated in the local time zone

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

static now()[source]

Returns the number of milliseconds since midnight Jan 1, 1970

static parse(date_string)[source]

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

setDate(day: int)[source]

Sets the day of the month of a date object

Parameters

day (int) – An integer representing the day of the month.

Returns

milliseconds between epoch and updated date.

Return type

int

setFullYear(yearValue: int, monthValue: Optional[int] = None, dateValue: Optional[int] = None)[source]

Sets the year of a date object

Parameters
  • yearValue (_type_) – _description_

  • monthValue (int, optional) – _description_. Defaults to None.

  • dateValue (int, optional) – _description_. Defaults to None.

Returns

milliseconds between epoch and updated date.

Return type

int

setHours(hoursValue: int, minutesValue: Optional[int] = None, secondsValue: Optional[int] = None, msValue: Optional[int] = None)[source]

Sets the hour of a date object

Parameters
  • hoursValue (int) – an integer between 0 and 23

  • minutesValue (int, optional) – an integer between 0 and 59

  • secondsValue (int, optional) – an integer between 0 and 59,

  • msValue (int, optional) – a number between 0 and 999,

Returns

milliseconds between epoch and updated date.

Return type

int

setMilliseconds(milliseconds: int)[source]

Sets the milliseconds of a date object

Parameters

milliseconds (int) – Milliseconds to set i.e 123

setMinutes(minutesValue: int, secondsValue: Optional[int] = None, msValue: Optional[int] = None)[source]

Set the minutes of a date object

Parameters
  • minutesValue (int, optional) – an integer between 0 and 59

  • secondsValue (int, optional) – an integer between 0 and 59,

  • msValue (int, optional) – a number between 0 and 999,

Returns

milliseconds between epoch and updated date.

Return type

int

setMonth(monthValue: int, dayValue: Optional[int] = None)[source]

Sets the month of a date object

Parameters
  • monthValue (int) – a number from 0 to 11 indicating the month.

  • dayValue (int, optional) – an optional day of the month. Defaults to 0.

Returns

milliseconds between epoch and updated date.

Return type

int

setSeconds(secondsValue: int, msValue: Optional[int] = None)[source]

Sets the seconds of a date object

Parameters
  • secondsValue (int) – _description_

  • msValue (int, optional) – _description_. Defaults to None.

Returns

milliseconds between epoch and updated date.

Return type

int

setTime(milliseconds: Optional[int] = None)[source]

Sets the date and time of a date object

Parameters

milliseconds (_type_, optional) – _description_. Defaults to None.

Returns

_description_

Return type

_type_

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

toString()[source]

Returns a string representation of the date

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

exception domonic.javascript.Error(message, *args, **kwargs)[source]

Raise Errors

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

a Function object

apply(thisArg=None, args=None, **kwargs)[source]

[calls a function with a given this value, and arguments provided as an array]

Parameters

thisArg ([type]) – [The value of this provided for the call to func.]

Returns

[result of calling the function.]

Return type

[type]

bind(thisArg, *args, **kwargs)[source]

[creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.]

Parameters
  • thisArg ([type]) – [The value to be passed as the this parameter to the target

  • called.] (function func when the bound function is) –

Returns

[A copy of the given function with the specified this value, and initial arguments (if provided).]

Return type

[type]

call(thisArg=None, *args, **kwargs)[source]

[calls a function with a given this value and arguments provided individually.]

Parameters

thisArg ([type]) – [description]

Returns

[result of calling the function.]

Return type

[type]

toString()[source]

[Returns a string representing the source code of the function. Overrides the]

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 clearTimeout(timeoutID)[source]

[cancels a timer set with setTimeout()]

Parameters

timeoutID ([str]) – [the identifier returned by setTimeout()]

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 eval(pythonstring)[source]

Evaluates a string and executes it as if it was script code

static isFinite(x) bool[source]

Returns true if x is a finite number

static isNaN(x)[source]

Determines whether a value is an illegal number

static parseFloat(x: str)[source]

Parses a string and returns a floating point number

static parseInt(x: str)[source]

Parses a string and returns an integer

static require(path: str)[source]

Loads a script from a file

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

[sets a timer which executes a function or evaluates an expression after a specified delay]

Parameters
  • callback (function) – [method to be executed after the delay]

  • t ([int]) – [milliseconds]

Returns

[an identifier for the timer]

Return type

[str]

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.Map(collection)[source]

Map holds key-value pairs and remembers the original insertion order of the keys.

clear()[source]

Removes all key-value pairs from the Map object.

delete(key: str) bool[source]

Returns true if an element in the Map object existed and has been removed, or false if the element does not exist. Map.prototype.has(key) will return false afterwards.

entries()[source]

Returns a new Iterator object that contains an array of [key, value] for each element in the Map object in insertion order.

get(key: str, default=None)[source]

Returns the value associated to the key, or undefined if there is none.

has(key: str) bool[source]

Returns a boolean asserting whether a value has been associated to the key in the Map object or not.

keys()[source]

Returns a new Iterator object that contains the keys for each element in the Map object in insertion order.

set(key: str, value)[source]

Sets the value for the key in the Map object. Returns the Map object.

values()[source]

Returns a new Iterator object that contains the values for each element in the Map object in insertion order.

class domonic.javascript.Math(obj=None, *args, **kwargs)[source]

Math class that mirrors javascript implementation.

i.e. you can pass strings and it will also work, Math.abs(‘-1’)

static hypot(*args)[source]

returns the square root of the sum of squares of its arguments

static log2(*args)[source]

returns the square root of the sum of squares of its arguments

static loglp(*args)[source]

returns the natural logarithm (base e) of 1 + a number, that is

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

javascript Number methods

NEGATIVE_INFINITY = inf

Represents negative infinity (returned on overflow) Number

POSITIVE_INFINITY = -inf

Represents infinity (returned on overflow) Number

isInteger()[source]

Checks whether a value is an integer

isSafeInteger()[source]

Checks whether a value is a safe integer

toExponential(num=None)[source]

Converts a number into an exponential notation

toFixed(digits: int)[source]

[formats a number using fixed-point notation.]

Parameters

digits ([int]) – [The number of digits to appear after the decimal point

Returns

[A string representing the given number using fixed-point notation.]

Return type

[str]

toPrecision(precision)[source]

[returns a string representing the Number object to the specified precision.]

Parameters

precision ([int]) – [An integer specifying the number of significant digits.]

Returns

[A string representing a Number object in fixed-point or exponential notation rounded to precision significant digits]

Return type

[str]

toString(base: int)[source]

[returns a string representing the specified Number object.]

Parameters

base (int) – [An integer in the range 2 through 36 specifying the base to use for representing numeric values.]

Returns

[a string representing the specified Number object]

Return type

[str]

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

The Reflect object provides the following static functions which have the same names as the proxy handler methods. Some of these methods are also the same as corresponding methods on Object, although they do have some subtle differences between them.

static apply(target, thisArgument, argumentsList)[source]

Calls a target function with arguments as specified by the argumentsList parameter. See also Function.prototype.apply().

static construct(target, argumentsList, newTarget)[source]

The new operator as a function. Equivalent to calling new target(…argumentsList). Also provides the option to specify a different prototype.

static defineProperty(target, propertyKey, attributes)[source]

Similar to Object.defineProperty(). Returns a Boolean that is true if the property was successfully defined.

static deleteProperty(target, propertyKey)[source]

The delete operator as a function. Equivalent to calling delete target[propertyKey].

static get(target, propertyKey, receiver)[source]

Returns the value of the property. Works like getting a property from an object (target[propertyKey]) as a function.

static getOwnPropertyDescriptor(target, propertyKey)[source]

Similar to Object.getOwnPropertyDescriptor(). Returns a property descriptor of the given property if it exists on the object, undefined otherwise.

getPrototypeOf()

Returns the prototype (internal [[Prototype]] property) of the specified object.

static has(target, propertyKey)[source]

Returns a Boolean indicating whether the target has the property. Either as own or inherited. Works like the in operator as a function.

static ownKeys(target)[source]

Returns an array of the target object’s own (not inherited) property keys.

static preventExtensions(target)[source]

Similar to Object.preventExtensions(). Returns a Boolean that is true if the update was successful.

static set(target, propertyKey, value, receiver)[source]

A function that assigns values to properties. Returns a Boolean that is true if the update was successful.

static setPrototypeOf(target, prototype)[source]

A function that sets the prototype of an object. Returns a Boolean that is true if the update was successful.

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 methods

big()[source]

[wraps the string in big tags]

Returns

[the string in big tags]

Return type

[str]

blink()[source]

[wraps the string in blink tags]

Returns

[the string in blink tags]

Return type

[str]

bold()[source]

[wraps the string in bold tags]

Returns

[the string in bold tags]

Return type

[str]

charAt(index: int) str[source]

[Returns the character at the specified index (position)]

Parameters

index (int) – [index position]

Returns

[the character at the specified index. if the index is out of range, an empty string is returned.]

Return type

[str]

charCodeAt(index: int) int[source]

Returns the Unicode of the character at the specified index

codePointAt(index: int)[source]

[Returns the Unicode code point at the specified index (position)]

Parameters

index (int) – [index position]

Returns

[the Unicode code point at the specified index (position)]

Return type

[type]

compile(pattern: str)[source]

Searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced. only replaces first one.

concat(*args, seperator: str = '') str[source]

[concatenates the string arguments to the calling string and returns a new string.]

Parameters

seperator (str, optional) – []. Defaults to “”.

Returns

[A new string containing the combined text of the strings provided.]

Return type

[type]

div(*args, **kwargs)[source]

[wraps the string in a div tag]

Returns

[the string in a div tag]

Return type

[str]

endsWith(x: str, start: Optional[int] = None, end: Optional[int] = None) bool[source]

Checks whether a string ends with specified string/characters

fixed()[source]

[wraps the string in fixed tags]

Returns

[the string in fixed tags]

Return type

[str]

fontcolor(color: str)[source]

[wraps the string in font tags with a specified color]

Parameters

color (str) – [the color to use]

Returns

[the string in font tags]

Return type

[str]

fontsize(size: str)[source]

[wraps the string in font tags with a specified size]

Parameters

size (str) – [the size to use]

Returns

[the string in font tags]

Return type

[str]

fromCharCode(*codes) str[source]

returns a string created from the specified sequence of UTF-16 code units

static fromCodePoint(codePoint: int)[source]

Converts a Unicode code point into a string

includes(searchValue: str, position: int = 0) bool[source]

[returns true if the specified string is found within the calling String object,]

Parameters
  • searchValue (str) – [The string value to search for.]

  • position (int, optional) – [the position to search from]. Defaults to 0.

Returns

[a boolean value indicating whether the search value was found.]

Return type

[type]

indexOf(searchValue: str, fromIndex: int = 0)[source]

[returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex ]

Parameters
  • searchValue (str) – [The string value to search for.]

  • fromIndex (int) – [An integer representing the index at which to start the search]

Returns

[The index of the first occurrence of searchValue, or -1 if not found.]

Return type

[type]

italics()[source]

[wraps the string in italics tags]

Returns

[the string in italics tags]

Return type

[str]

lastIndexOf(searchValue: str, fromIndex: int = 0)[source]

returns the last index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex

link(url: str)[source]

[wraps the string in a link tag]

Parameters

url (str) – [the url to use]

Returns

[the string in a link tag]

Return type

[str]

localeCompare(comparisonString: str, locale: Optional[str] = None, *args) int[source]

method returns a number indicating whether a reference string comes before, or after, or is the same as the given string in sort order

match(pattern: str)[source]

Searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced. only replaces first one.

matchAll(pattern: str)[source]

Searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced. only replaces first one.

padEnd(length: int, padChar: str = ' ') str[source]

[Pads the end of a string with a specified character (repeated, if needed) to create a new string.]

Parameters
  • length (int) – [the length of the resulting string]

  • padChar (str, optional) – [the character to use for padding. Defaults to ” “].

Returns

[the padded string]

Return type

[str]

padStart(length: int, padChar: str = ' ') str[source]

[Pads the start of a string with a specified character]

Parameters
  • length (int) – [the length of the resulting string]

  • padChar (str, optional) – [the character to use for padding. Defaults to ” “].

Returns

[the padded string]

Return type

[str]

static raw(string)[source]

Returns the string as-is

repeat(count: int) str[source]

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

replace(old: str, new) str[source]

Searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced. only replaces first one.

replaceAll(old: str, new: str)[source]

[returns a new string where the specified values are replaced. ES2021]

Parameters
  • old ([str]) – [word to remove]

  • new ([str]) – [word to replace it with]

Returns

[new string with all occurences of old word replaced]

Return type

[str]

search(searchValue: str, position: int = 0) bool[source]

[returns true if the specified string is found within the calling String object,] starting at the specified position. :param searchValue: [The string value to search for.] :type searchValue: str :param position: [the position to search from]. Defaults to 0. :type position: int, optional

Returns

[a boolean value indicating whether the search value was found.]

Return type

[type]

slice(start: int = 0, end: Optional[int] = None) str[source]

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

small()[source]

[wraps the string in small tags]

Returns

[the string in small tags]

Return type

[str]

split(expr) list[source]

[can split a string based on a regex]

Parameters

expr ([str]) – [valid regex or string to split on]

Returns

[list of str]

Return type

[list]

startsWith(x: str, start: Optional[int] = None, end: Optional[int] = None) bool[source]

Checks whether a string begins with specified characters

strike()[source]

[wraps the string in strike tags]

Returns

[the string in strike tags]

Return type

[str]

sub()[source]

[wraps the string in sub tags]

Returns

[the string in sub tags]

Return type

[str]

substr(start: int = 0, end: Optional[int] = None)[source]

Extracts the characters from a string, beginning at a specified start position, and through the specified number of character

substring(start: int, end: Optional[int] = None) str[source]

Extracts the characters from a string, between two specified indices

sup()[source]

[wraps the string in sup tags]

Returns

[the string in sup tags]

Return type

[str]

static toCharCode(char: str)[source]

Converts a Unicode string into a code point

static toCodePoint(char: str)[source]

Converts a Unicode string into a code point

toLocaleLowerCase() str[source]

Converts a string to lowercase letters, according to the host’s locale

toLocaleUpperCase() str[source]

Converts a string to uppercase letters, according to the host’s locale

toLowerCase() str[source]

Converts a string to lowercase letters

toUpperCase() str[source]

Converts a string to uppercase letters

trim()[source]

Removes whitespace from both ends of a string

trimEnd(length: int)[source]

[Removes whitespace from the end of a string]

Parameters

length (int) – [the length of the resulting string]

Returns

[the trimmed string]

Return type

[type]

trimStart(length: int)[source]

[Removes whitespace from the beginning of a string.]

Parameters

length (int) – [the length of the resulting string]

Returns

[the trimmed string]

Return type

[str]

webpage()[source]

[wraps the string in a webpage]

Returns

[the string as a webpage]

Return type

[str]

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

window

static alert(msg)[source]

Displays an alert box with a message and an OK button

static atob(dataString)[source]

Decodes a base-64 encoded string

static btoa(dataString)[source]

Encodes a string in base-64

clearTimeout()

[cancels a timer set with setTimeout()]

Parameters

timeoutID ([str]) – [the identifier returned by setTimeout()]

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

Displays a dialog box that prompts the visitor for input

static requestAnimationFrame(callback)[source]

[requests a frame of an animation]

Parameters

callback (callable) – [the callback function]

Returns

[description]

Return type

[type]

setTimeout(t, *args, **kwargs)

[sets a timer which executes a function or evaluates an expression after a specified delay]

Parameters
  • callback (function) – [method to be executed after the delay]

  • t ([int]) – [milliseconds]

Returns

[an identifier for the timer]

Return type

[str]

class domonic.javascript.Worker(script)[source]

[A background task that can be created via script, which can send messages back to its creator. Creating a worker is done by calling the Worker(“path/to/worker/script”) constructor.] TODO - JSWorker - Node :param object: [takes a path to a python script] :type object: [str]

postMessage()[source]

Sends a message — consisting of any object — to the worker’s inner scope.

terminate()[source]

Immediately terminates the worker. This does not let worker finish its operations; it is halted at once. ServiceWorker instances do not support this method.

domonic.javascript.as_signed(value, bits)[source]

Converts an unsigned integer to a signed integer.

domonic.javascript.clearTimeout(timeoutID)

[cancels a timer set with setTimeout()]

Parameters

timeoutID ([str]) – [the identifier returned by setTimeout()]

domonic.javascript.decodeURI(x)

Decodes a URI

domonic.javascript.decodeURIComponent(x)

Decodes a URI component

domonic.javascript.encodeURI(x)

Encodes a URI

domonic.javascript.encodeURIComponent(x)

Encodes a URI component

domonic.javascript.function(python_str: str) str[source]

[evals a string i.e.

sup = function(‘’’print(hi)’’’) sup()

]

Parameters

python_str ([str]) – [some valid python code as a string]

domonic.javascript.parseFloat(x: str)

Parses a string and returns a floating point number

domonic.javascript.parseInt(x: str)

Parses a string and returns an integer

domonic.javascript.setTimeout(callback, t, *args, **kwargs)

[sets a timer which executes a function or evaluates an expression after a specified delay]

Parameters
  • callback (function) – [method to be executed after the delay]

  • t ([int]) – [milliseconds]

Returns

[an identifier for the timer]

Return type

[str]

domonic.javascript.window

alias of Window