Global Functions and Variables

Global object containing all global functions and variables.


Properties

QualifiersPropertyTypeDescription
ejs.web actionNamespaceController. Es -- Ejscript Controller class as part of the MVC framework. Also contains control helpers for views.
intrinsic const ASCBooleanConditional compilation constant. Used to disable compilation of certain elements.
intrinsic const booleanTypeAlias for the Boolean type.
public CONFIGNamespaceThe CONFIG namespace used to defined conditional compilation directives.
intrinsic const DEPRECATEDBooleanConditional compilation constant. Used to deprecate elements.
intrinsic const DOC_ONLYBooleanConditional compilation constant. Used to enable the compilation of elements only for creating the API documentation.
intrinsic const doubleTypeAlias for the Number type.
intrinsic const falseBooleanBoolean false value.
intrinsic const FUTUREBooleanConditional compilation constant. Used to disable compilation of certain elements.
intrinsic globalObjectGlobal variable space reference. The global variable references an object which is the global variable space. This is useful when guaranteed access to a global variable is required. e.g. global.someName.
intrinsic const InfinityNumberInfinity value.
public internalNamespaceThe internal namespace used to make entities visible within a single module only.
public intrinsicNamespaceThe intrinsic namespace used for entities that are part of and intrinsic to, the Ejscript platform.
public iteratorNamespaceThe iterator namespace used to defined iterators.
intrinsic const NaNNumberInvalid numeric value. If the numeric type is set to an integral type, the value is zero.
intrinsic const NegativeInfinityNumberNegative infinity value.
intrinsic const nullNullNull value. The null value is returned when testing a nullable variable that has not yet had a value assigned or one that has had null explicitly assigned.
intrinsic const numTypeAlias for the Number type.
public publicNamespaceThe public namespace used to make entities visible accross modules.
intrinsic const REGEXPBooleanConditional compilation constant. Used to deprecate elements.
ejs.web sessions Array of all sessions.
intrinsic const stringTypeAlias for the String type.
intrinsic const TODOBooleanConditional compilation constant. Used to disable compilation of certain elements.
intrinsic const trueBooleanTrue value.
intrinsic const undefinedVoidUndefined variable value. The undefined value is returned when testing for a property that has not been defined.
ejs.web viewViewCurrent view in the web framework.
intrinsic const voidTypeVoid type value. This is an alias for Void.

Global Methods

QualifiersMethod
intrinsic assert(condition: Boolean): Boolean
 Assert a condition is true.
public basename(path: String): Path
 Get the base name of a file.
intrinsic breakpoint(): Void
public chdir(dir: Object): Void
 Change the current working directory.
intrinsic cloneBase(klass: Type): Void
 Replace the base type of a type with an exact clone.
public close(file: File, graceful: Boolean): Void
 Close the file and free up all associated resources.
public cp(fromPath: String, toPath: String): Void
 Copy a file.
intrinsic deserialize(obj: String): Object
 Convert a string into an object.
public dirname(path: String): Path
 Get the directory name portion of a file.
intrinsic dump(args: Array): Void
 Dump the contents of objects.
intrinsic error(args: Array): Void
 Write to the standard error.
public exists(path: String): Boolean
 Does a file exist.
public extension(path: String): String
 Get the file extension portion of the file name.
intrinsic formatStack(): String
 Format the current call stack.
public freeSpace(path: String): Number
 Return the free space in the file system.
intrinsic hashcode(o: Object): Number
 Get the object's Unique hash id.
intrinsic input(): String
 Read from the standard input.
intrinsic instanceOf(obj: Object, target: Object): Boolean
public isDir(path: String): Boolean
 Is a file a directory.
intrinsic load(file: String): Void
 Load a script or module.
public ls(path: String, enumDirs: Boolean): Array
 Get a list of files in a directory.
public mkdir(path: String, permissions: Number): Void
 Make a new directory.
public mv(fromFile: String, toFile: String): Void
 Rename a file.
public open(path: String, mode: Number, permissions: Number): File
 Open or create a file.
intrinsic output(args: Array): Void
 Print the arguments to the standard output with a new line appended.
intrinsic parse(input: String, preferredType: Type): Object
 Parse a string and convert to a primitive type.
ejs.db pluralize(name: String): String
intrinsic print(args: Array): Void
 Print the arguments to the standard output with a new line appended.
intrinsic printHash(name: String, o: Object): Void
intrinsic printv(args: Array): Void
 Print variables for debugging.
public pwd(): Path
 Get the current working directory.
public read(file: File, count: Number): ByteArray
 Read data bytes from a file and return a byte array containing the data.
public rm(path: String): Void
 Remove a file from the file system.
public rmdir(path: String, recursive: Boolean): Void
 Removes a directory.
intrinsic serialize(obj: Object, maxDepth: Number, all: Boolean, base: Boolean): String
 Encode an object as a string.
public tempname(directory: String): File
 Create a temporary file.
intrinsic typeOf(o): String
 Return the name of a type.
public write(file: File, items: Array): Number
 Write data to the file.

Method Detail

intrinsic assert(condition: Boolean): Boolean

Assert a condition is true.

Description
This call tests if a condition is true by testing to see if the supplied expression is true. If the expression is false, the interpreter will throw an exception.
Parameters
condition: Boolean JavaScript expression evaluating or castable to a Boolean result.
Returns
True if the condition is.
Specified
Ejs-11.

public basename(path: String): Path

Get the base name of a file.

Description
Returns the base name portion of a file name. The base name portion is the trailing portion without any directory elements.
Returns
A string containing the base name portion of the file name.

intrinsic breakpoint(): Void

public chdir(dir: Object): Void

Change the current working directory.

Parameters
dir: Object Directory String or path to change to

intrinsic cloneBase(klass: Type): Void

Replace the base type of a type with an exact clone.

Parameters
klass: Type Class in which to replace the base class.
Specified
Ejs-11.

public close(file: File, graceful: Boolean): Void

Close the file and free up all associated resources.

Parameters
file: File Open file object previously opened via $open or $File
graceful: Boolean if true, then close the file gracefully after writing all pending data. [default: true]

public cp(fromPath: String, toPath: String): Void

Copy a file.

Description
If the destination file already exists, the old copy will be overwritten as part of the copy operation.
Parameters
fromPath: String Original file to copy.
toPath: String New destination file path name.

Throws

IOError: if the copy is not successful.


intrinsic deserialize(obj: String): Object

Convert a string into an object.

Description
This will parse a string that has been encoded via serialize. It may contain nested objects and arrays. This is a static method.
Parameters
Returns
The fully constructed object or undefined if it could not be reconstructed.

Throws

IOError: If the object could not be reconstructed from the string.

Specified
Ejs-11.

public dirname(path: String): Path

Get the directory name portion of a file.

Description
The dirname name portion is the leading portion including all directory elements and excluding the base name. On some systems, it will include a drive specifier.
Returns
A string containing the directory name portion of the file name.

intrinsic dump(args: Array): Void

Dump the contents of objects.

Description
Used for debugging, this routine serializes the objects and prints to the standard output.
Parameters
args: Array Variable number of arguments of any type

intrinsic error(args: Array): Void

Write to the standard error.

Description
This call writes the arguments to the standard error with a new line appended. It evaluates the arguments, converts the result to strings and prints the result to the standard error. Arguments are converted to strings by calling their toSource method.
Parameters
args: Array Data to write
Specified
Ejs-11.

public exists(path: String): Boolean

Does a file exist.

Description
Return true if the specified file exists and can be accessed.
Parameters
path: String Filename path to examine.
Returns
True if the file can be accessed.

public extension(path: String): String

Get the file extension portion of the file name.

Parameters
path: String Filename path to examine
Returns
String containing the file extension.

intrinsic formatStack(): String

Format the current call stack.

Description
Used for debugging and when creating exception objects.
Specified
Ejs-11.

public freeSpace(path: String): Number

Return the free space in the file system.

Parameters
path: String
Returns
The number of 1M blocks (1024 * 1024 bytes) of free space in the file system.

intrinsic hashcode(o: Object): Number

Get the object's Unique hash id.

Description
All objects have a unique object hash.
Returns
This property accessor returns a long containing the object's unique hash identifier.

intrinsic input(): String

Read from the standard input.

Description
This call reads a line of input from the standard input.
Returns
A string containing the input. Returns null on EOF.

intrinsic instanceOf(obj: Object, target: Object): Boolean

public isDir(path: String): Boolean

Is a file a directory.

Description
Return true if the specified path exists and is a directory.
Parameters
path: String Directory path to examine.
Returns
True if the file can be accessed.

intrinsic load(file: String): Void

Load a script or module.

Parameters
file: String path name to load. File will be interpreted relative to EJSPATH if it is not found as an absolute or relative file name.

public ls(path: String, enumDirs: Boolean): Array

Get a list of files in a directory.

Description
The returned array contains the base file name portion only.
Parameters
path: String Directory path to enumerate.
enumDirs: Boolean If set to true, then dirList will include sub-directories in the returned list of files. [default: false]
Returns
An Array of strings containing the filenames in the directory.

public mkdir(path: String, permissions: Number): Void

Make a new directory.

Description
Makes a new directory and all required intervening directories. If the directory already exists, the function returns without throwing an exception.
Parameters
path: String Filename path to use.

Throws

IOError: if the directory cannot be created.


public mv(fromFile: String, toFile: String): Void

Rename a file.

Description
If the new file name exists it is removed before the rename.
Parameters

Throws

IOError: if the original file does not exist or cannot be renamed.


public open(path: String, mode: Number, permissions: Number): File

Open or create a file.

Parameters
path: String Filename path to open
mode: Number optional file access mode with values ored from: Read, Write, Append, Create, Open, Truncate. Defaults to Read. [default: Read]
permissions: Number optional permissions. Defaults to App.permissions
Returns
A File object which implements the Stream interface.

Throws

IOError: if the path or file cannot be opened or created.


intrinsic output(args: Array): Void

Print the arguments to the standard output with a new line appended.

Description
This call evaluates the arguments, converts the result to strings and prints the result to the standard output. Arguments are converted to strings by calling their toString method.
Parameters
args: Array Variables to print
Specified
Ejs-11.

intrinsic parse(input: String, preferredType: Type): Object

Parse a string and convert to a primitive type.

Parameters
preferredType: Type

ejs.db pluralize(name: String): String

intrinsic print(args: Array): Void

Print the arguments to the standard output with a new line appended.

Description
This call evaluates the arguments, converts the result to strings and prints the result to the standard output. Arguments are converted to strings by calling their toString method. This method invokes $output as its implementation.
Parameters
args: Array Variables to print
Specified
Ejs-11.

intrinsic printHash(name: String, o: Object): Void

intrinsic printv(args: Array): Void

Print variables for debugging.

Parameters
args: Array Variables to print
Specified
Ejs-11.

public pwd(): Path

Get the current working directory.

Returns
A Path containing the current working directory.

public read(file: File, count: Number): ByteArray

Read data bytes from a file and return a byte array containing the data.

Parameters
file: File Open file object previously opened via $open or $File
Returns
A byte array containing the read data.

Throws

IOError: if the file could not be read.


public rm(path: String): Void

Remove a file from the file system.

Parameters
path: String Filename path to delete.

Throws

IOError: if the file exists and cannot be removed.


public rmdir(path: String, recursive: Boolean): Void

Removes a directory.

Parameters
path: String Filename path to remove.
recursive: Boolean [default: false]

Throws

IOError: if the directory exists and cannot be removed.


intrinsic serialize(obj: Object, maxDepth: Number, all: Boolean, base: Boolean): String

Encode an object as a string.

Description
This function returns a literal string for the object and all its properties. If.
Parameters
maxDepth: Number The depth to recurse when converting properties to literals. If set to zero, the depth is infinite.
all: Boolean Encode non-enumerable and class fixture properties and functions. [default: false]
base: Boolean Encode base class properties. [default: false]
Returns
This function returns an object literal that can be used to reinstantiate an object.

Throws

TypeError: If the object could not be converted to a string.

Specified
Ejs-11.

public tempname(directory: String): File

Create a temporary file.

Description
Creates a new, uniquely named temporary file.
Parameters
directory: String Directory in which to create the temp file.
Returns
A closed File object after creating an empty temporary file.

intrinsic typeOf(o): String

Return the name of a type.

Description
This is a fixed version of the standard "typeof" operator. It returns the real Ejscript underlying type. This is implemented as a wrapper around Reflect(o).typeName.
Parameters
o Object or value to examine.
Returns
A string type name. If the object to examine is a type object, then return the name of the base type. If the object is Object, then return null.
Specified
Ejs-11.

public write(file: File, items: Array): Number

Write data to the file.

Description
If the stream is in sync mode, the write call blocks until the underlying stream or endpoint absorbes all the data. If in async-mode, the call accepts whatever data can be accepted immediately and returns a count of the elements that have been written.
Parameters
file: File Open file object previously opened via $open or $File
items: Array The data argument can be ByteArrays, strings or Numbers. All other types will call serialize first before writing. Note that numbers will not be written in a cross platform manner. If that is required, use the BinaryStream class to write Numbers.
Returns
The number of bytes written.

Throws

IOError: if the file could not be written.