-
Notifications
You must be signed in to change notification settings - Fork 0
API Reference
Complete API reference for all Phantom.js operations.
Initialize Phantom.js with optional configuration.
Parameters:
-
options(Object, optional): Configuration object-
silent(Boolean, optional): Enable/disable silent mode (default: true)
-
Returns: phantom object (for chaining)
Example:
phantom.init({ silent: false });Get the current version string.
Returns: String (e.g., "0.0.9")
Access configuration object.
Properties:
-
silent(Boolean): Silent mode setting
Save a value to the channel map.
Parameters:
-
key(String): Map key -
value(Any): Value to save
Throws: Error("Invalid operation") if key is null or map is unavailable
Get a value from the channel map.
Parameters:
-
key(String): Map key
Returns: Value or null if not found
Throws: Error("Invalid operation") if key is null or map is unavailable
Check if a key exists in the channel map.
Parameters:
-
key(String): Map key
Returns: Boolean
Throws: Error("Invalid operation") if map is unavailable
Delete a key from the channel map.
Parameters:
-
key(String): Map key
Throws: Error("Invalid operation") if key is null or map is unavailable
Same API as Channel Map:
phantom.maps.global.save(key, value)phantom.maps.global.get(key)phantom.maps.global.exists(key)phantom.maps.global.delete(key)
Same API as Channel Map:
phantom.maps.connector.save(key, value)phantom.maps.connector.get(key)phantom.maps.connector.exists(key)phantom.maps.connector.delete(key)
Same API as Channel Map, but only available in response context:
phantom.maps.response.save(key, value)phantom.maps.response.get(key)phantom.maps.response.exists(key)phantom.maps.response.delete(key)
Note: Throws error if not in response context.
Get a configuration value.
Parameters:
-
key(String): Configuration key
Returns: Configuration value or null
Check if a configuration key exists.
Parameters:
-
key(String): Configuration key
Returns: Boolean
Note: save() and delete() always throw errors (read-only).
All string operations are under phantom.strings.operation.*
Check if string contains substring.
Parameters:
-
input(String): Input string -
stringToFind(String): Substring to find
Returns: Boolean
Alias for find.
Get string length.
Parameters:
-
input(String): Input string
Returns: Number
Check if string is empty.
Parameters:
-
input(String): Input string
Returns: Boolean
Check if string is empty or only whitespace.
Parameters:
-
input(String): Input string
Returns: Boolean
Convert to uppercase.
Parameters:
-
input(String): Input string
Returns: String
Convert to lowercase.
Parameters:
-
input(String): Input string
Returns: String
Capitalize first letter, lowercase rest.
Parameters:
-
input(String): Input string
Returns: String
Reverse a string.
Parameters:
-
input(String): Input string
Returns: String
Check if string starts with prefix.
Parameters:
-
input(String): Input string -
prefix(String): Prefix to check
Returns: Boolean
Check if string ends with suffix.
Parameters:
-
input(String): Input string -
suffix(String): Suffix to check
Returns: Boolean
Pad string on the left.
Parameters:
-
input(String): Input string -
padChar(String, optional): Character to pad with (default: space) -
count(Number): Number of characters to pad
Returns: String
Pad string on the right.
Parameters:
-
input(String): Input string -
padChar(String, optional): Character to pad with (default: space) -
count(Number): Number of characters to pad
Returns: String
Pad string on both sides.
Parameters:
-
input(String): Input string -
padChar(String, optional): Character to pad with (default: space) -
count(Number): Number of characters to pad on each side
Returns: String
Remove whitespace from left.
Parameters:
-
input(String): Input string
Returns: String
Remove whitespace from right.
Parameters:
-
input(String): Input string
Returns: String
Remove whitespace from both sides.
Parameters:
-
input(String): Input string
Returns: String
Replace first occurrence.
Parameters:
-
input(String): Input string -
searchString(String): String to search for -
replaceString(String): Replacement string
Returns: String
Replace all occurrences.
Parameters:
-
input(String): Input string -
searchString(String): String to search for -
replaceString(String): Replacement string
Returns: String
Split string by delimiter.
Parameters:
-
input(String): Input string -
delimiter(String): Delimiter
Returns: Array of strings
Extract substring.
Parameters:
-
input(String): Input string -
start(Number): Start index -
end(Number, optional): End index (if omitted, returns to end)
Returns: String
Insert/delete characters.
Parameters:
-
input(String): Input string -
start(Number): Start position -
deleteCount(Number): Number of characters to delete -
insertString(String, optional): String to insert
Returns: String
Compare two strings lexicographically.
Parameters:
-
a(String): First string -
b(String): Second string
Returns: Number (-1 if a < b, 0 if a === b, 1 if a > b)
Join two strings with delimiter.
Parameters:
-
a(String): First string -
b(String): Second string -
joinCharacters(String, optional): Delimiter (default: empty string)
Returns: String
Repeat string N times.
Parameters:
-
input(String): Input string -
count(Number): Number of times to repeat
Returns: String
Remove all occurrences of substring.
Parameters:
-
input(String): Input string -
stringToRemove(String): Substring to remove
Returns: String
All number operations are under phantom.numbers.operation.*
Parse value to number (strict).
Parameters:
-
value(Any): Value to parse
Returns: Number
Throws: Error("Invalid operation") if value is not a valid number
Check if value is a valid number.
Parameters:
-
value(Any): Value to check
Returns: Boolean
Add two numbers.
Parameters:
-
a(Number): First number -
b(Number): Second number
Returns: Number
Throws: Error("Invalid operation") if inputs are invalid
Subtract two numbers.
Parameters:
-
a(Number): First number -
b(Number): Second number
Returns: Number
Throws: Error("Invalid operation") if inputs are invalid
Multiply two numbers.
Parameters:
-
a(Number): First number -
b(Number): Second number
Returns: Number
Throws: Error("Invalid operation") if inputs are invalid
Divide two numbers.
Parameters:
-
a(Number): Dividend -
b(Number): Divisor
Returns: Number
Throws: Error("Invalid operation") if inputs are invalid or divisor is zero
Calculate modulo (remainder).
Parameters:
-
dividend(Number): Dividend -
divisor(Number): Divisor
Returns: Number
Throws: Error("Invalid operation") if inputs are invalid or divisor is zero
Round to specified decimal places.
Parameters:
-
value(Number): Value to round -
decimals(Number, optional): Number of decimal places (default: 0)
Returns: Number
Throws: Error("Invalid operation") if value is invalid
Round up to nearest integer.
Parameters:
-
value(Number): Value to round
Returns: Number
Throws: Error("Invalid operation") if value is invalid
Round down to nearest integer.
Parameters:
-
value(Number): Value to round
Returns: Number
Throws: Error("Invalid operation") if value is invalid
Truncate decimal part.
Parameters:
-
value(Number): Value to truncate
Returns: Number
Throws: Error("Invalid operation") if value is invalid
Format number with fixed decimals (returns string).
Parameters:
-
value(Number): Value to format -
decimals(Number): Number of decimal places (0-20)
Returns: String
Throws: Error("Invalid operation") if value is invalid or decimals out of range
Calculate power (base^exponent).
Parameters:
-
base(Number): Base number -
exponent(Number): Exponent
Returns: Number
Throws: Error("Invalid operation") if inputs are invalid
Calculate square root.
Parameters:
-
value(Number): Value (must be >= 0)
Returns: Number
Throws: Error("Invalid operation") if value is invalid or negative
Get absolute value.
Parameters:
-
value(Number): Value
Returns: Number
Throws: Error("Invalid operation") if value is invalid
Get minimum of two numbers.
Parameters:
-
a(Number): First number -
b(Number): Second number
Returns: Number
Throws: Error("Invalid operation") if inputs are invalid
Get maximum of two numbers.
Parameters:
-
a(Number): First number -
b(Number): Second number
Returns: Number
Throws: Error("Invalid operation") if inputs are invalid
Generate random number in range.
Parameters:
-
min(Number, optional): Minimum value (default: 0) -
max(Number, optional): Maximum value (default: 1)
Returns: Number (between min inclusive and max exclusive)
Throws: Error("Invalid operation") if min > max
Generate random integer in range.
Parameters:
-
min(Number, optional): Minimum value (default: 0) -
max(Number, optional): Maximum value (default: 1)
Returns: Integer (between min and max inclusive)
Throws: Error("Invalid operation") if min > max
Check if number is between two values (inclusive).
Parameters:
-
value(Number): Value to check -
min(Number): Minimum value -
max(Number): Maximum value
Returns: Boolean
Throws: Error("Invalid operation") if inputs are invalid
Clamp value between min and max.
Parameters:
-
value(Number): Value to clamp -
min(Number): Minimum value -
max(Number): Maximum value
Returns: Number
Throws: Error("Invalid operation") if inputs are invalid or min > max
Get sign of number.
Parameters:
-
value(Number): Value
Returns: Number (-1 for negative, 0 for zero, 1 for positive)
Throws: Error("Invalid operation") if value is invalid
Check if number is even.
Parameters:
-
value(Number): Value to check
Returns: Boolean
Throws: Error("Invalid operation") if value is invalid
Check if number is odd.
Parameters:
-
value(Number): Value to check
Returns: Boolean
Throws: Error("Invalid operation") if value is invalid
Check if number is positive.
Parameters:
-
value(Number): Value to check
Returns: Boolean
Throws: Error("Invalid operation") if value is invalid
Check if number is negative.
Parameters:
-
value(Number): Value to check
Returns: Boolean
Throws: Error("Invalid operation") if value is invalid
Check if number is zero.
Parameters:
-
value(Number): Value to check
Returns: Boolean
Throws: Error("Invalid operation") if value is invalid
All operations that can fail will throw Error("Invalid operation") with the following conditions:
- Invalid input types (e.g., non-numeric strings to number operations)
- Division by zero
- Null/undefined where not allowed
- Operations on read-only maps
- Invalid ranges (e.g., min > max)
Always wrap operations in try-catch blocks when appropriate.
All JSON operations are under phantom.json.operation.*
Parse JSON string to object.
Parameters:
-
jsonString(String): JSON string to parse
Returns: Object or Array
Throws: Error("Invalid operation") if string is invalid JSON
Convert object to JSON string.
Parameters:
-
obj(Object or Array): Object to stringify
Returns: String
Throws: Error("Invalid operation") if obj is null or undefined
Get value by key path (supports nested keys with dot notation).
Parameters:
-
obj(Object): Object to query -
keyPath(String): Key path (e.g., "user.name")
Returns: Value or null if not found
Throws: Error("Invalid operation") if obj is null or keyPath is invalid
Set value by key path. Returns new object (doesn't modify original).
Parameters:
-
obj(Object): Object to modify -
keyPath(String): Key path (e.g., "user.name") -
value(Any): Value to set
Returns: New object with updated value
Throws: Error("Invalid operation") if obj is null or keyPath is invalid
Check if key path exists.
Parameters:
-
obj(Object): Object to check -
keyPath(String): Key path to check
Returns: Boolean
Throws: Error("Invalid operation") if obj is null or keyPath is invalid
Remove key from object. Returns new object (doesn't modify original).
Parameters:
-
obj(Object): Object to modify -
keyPath(String): Key path to remove
Returns: New object with key removed
Throws: Error("Invalid operation") if obj is null or keyPath is invalid
Get all keys from object.
Parameters:
-
obj(Object): Object
Returns: Array of strings
Throws: Error("Invalid operation") if obj is null, not an object, or is an array
Get all values from object.
Parameters:
-
obj(Object): Object
Returns: Array of values
Throws: Error("Invalid operation") if obj is null, not an object, or is an array
Get size of object (number of keys) or length of array.
Parameters:
-
obj(Object or Array): Object or array
Returns: Number
Throws: Error("Invalid operation") if obj is null or not an object/array
Merge two objects. Second object overwrites first.
Parameters:
-
obj1(Object): First object -
obj2(Object): Second object (overwrites obj1)
Returns: Merged object
Throws: Error("Invalid operation") if inputs are invalid or are arrays
Check if object or array is empty.
Parameters:
-
obj(Object or Array): Object or array
Returns: Boolean
Throws: Error("Invalid operation") if obj is not an object/array
Check if value is an array.
Parameters:
-
obj(Any): Value to check
Returns: Boolean
Check if value is an object (not array).
Parameters:
-
obj(Any): Value to check
Returns: Boolean
- Getting Started - Learn the basics
- Examples - Usage examples
- Best Practices - Best practices guide
Phantom - A product of David Labs.