JavaScriptKit Documentation

Structure JSString

public struct JSString: LosslessStringConvertible, Equatable  

JSString represents a string in JavaScript and supports bridging string between JavaScript and Swift.

Conversion between Swift.String and JSString can be:

// Convert `Swift.String` to `JSString`
let jsString: JSString = ...
let swiftString: String = String(jsString)

// Convert `JSString` to `Swift.String`
let swiftString: String = ...
let jsString: JSString = JSString(swiftString)
%119 JSString JSString ConstructibleFromJSValue ConstructibleFromJSValue JSString->ConstructibleFromJSValue Equatable Equatable JSString->Equatable ConvertibleToJSValue ConvertibleToJSValue JSString->ConvertibleToJSValue ExpressibleByStringLiteral ExpressibleByStringLiteral JSString->ExpressibleByStringLiteral LosslessStringConvertible LosslessStringConvertible JSString->LosslessStringConvertible

Conforms To

ConstructibleFromJSValue

Types conforming to this protocol can be constructed from JSValue.

ConvertibleToJSValue

Objects that can be converted to a JavaScript value, preferably in a lossless manner.

Equatable
ExpressibleByStringLiteral
LosslessStringConvertible

Initializers

init(_:​)

public init(_ stringValue: String)  

Instantiate a new JSString with given Swift.String.

init(string​Literal:​)

public init(stringLiteral value: String)  

Properties

js​Value

public var jsValue: JSValue  

description

public var description: String  

A Swift representation of this JSString. Note that this accessor may copy the JS string value into Swift side memory.

Methods

construct(from:​)

public static func construct(from value: JSValue) -> JSString?  

Operators

==

public static func == (lhs: JSString, rhs: JSString) -> Bool  

Returns a Boolean value indicating whether two strings are equal values.

Parameters

lhs JSString

A string to compare.

rhs JSString

Another string to compare.