{"id":13416749,"url":"https://github.com/robertkrimen/otto","last_synced_at":"2025-09-09T20:49:28.498Z","repository":{"id":4941834,"uuid":"6098927","full_name":"robertkrimen/otto","owner":"robertkrimen","description":"A JavaScript interpreter in Go (golang)","archived":false,"fork":false,"pushed_at":"2025-03-31T07:42:01.000Z","size":2342,"stargazers_count":8287,"open_issues_count":48,"forks_count":592,"subscribers_count":186,"default_branch":"master","last_synced_at":"2025-05-05T17:34:35.746Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://godoc.org/github.com/robertkrimen/otto","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"kirualex/KAProgressLabel","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robertkrimen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-10-06T01:48:39.000Z","updated_at":"2025-05-04T14:35:29.000Z","dependencies_parsed_at":"2023-02-10T09:50:22.429Z","dependency_job_id":"eea51bd2-5e03-4266-bf44-0cb20247a46a","html_url":"https://github.com/robertkrimen/otto","commit_stats":{"total_commits":665,"total_committers":61,"mean_commits":"10.901639344262295","dds":"0.30225563909774433","last_synced_commit":"2b00d85b5e89a4cdfa13386676de64d0c401d50a"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertkrimen%2Fotto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertkrimen%2Fotto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertkrimen%2Fotto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertkrimen%2Fotto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertkrimen","download_url":"https://codeload.github.com/robertkrimen/otto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252542926,"owners_count":21765052,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T22:00:21.334Z","updated_at":"2025-09-09T20:49:28.484Z","avatar_url":"https://github.com/robertkrimen.png","language":"Go","funding_links":[],"categories":["Popular","Misc","开源类库","Go","Embeddable Scripting Languages","Open source library","嵌入式脚本语言","\u003cspan id=\"嵌入式脚本语言-embeddable-scripting-languages\"\u003e嵌入式脚本语言 Embeddable Scripting Languages\u003c/span\u003e","嵌入式腳本語言","Golang"],"sub_categories":["解释器","Advanced Console UIs","Interpreter","高级控制台界面","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","高級控制台界面","Database"],"readme":"# otto\n\n[![GoDoc Reference](https://pkg.go.dev/badge/github.com/robertkrimen/otto.svg)](https://pkg.go.dev/github.com/robertkrimen/otto)\n\n## Basic Usage\n\nPackage otto is a JavaScript parser and interpreter written natively in Go.\n\nTo use import it with the following:\n\n```go\nimport (\n   \"github.com/robertkrimen/otto\"\n)\n```\n\nRun something in the VM\n\n```go\nvm := otto.New()\nvm.Run(`\n    abc = 2 + 2;\n    console.log(\"The value of abc is \" + abc); // 4\n`)\n```\n\nGet a value out of the VM\n\n```go\nif value, err := vm.Get(\"abc\"); err == nil {\n    if value_int, err := value.ToInteger(); err == nil {\n        fmt.Println(value_int)\n    } else {\n        fmt.Printf(\"Error during conversion: %v\\n\", err)\n    }\n} else {\n    fmt.Printf(\"Error getting value: %v\\n\", err)\n}\n```\n\nSet a number\n\n```go\nvm.Set(\"def\", 11)\nvm.Run(`\n    console.log(\"The value of def is \" + def);\n    // The value of def is 11\n`)\n```\n\nSet a string\n\n```go\nvm.Set(\"xyzzy\", \"Nothing happens.\")\nvm.Run(`\n    console.log(xyzzy.length); // 16\n`)\n```\n\nGet the value of an expression\n\n```go\nvalue, _ = vm.Run(\"xyzzy.length\")\n{\n    // value is an int64 with a value of 16\n    value, _ := value.ToInteger()\n}\n```\n\nAn error happens\n\n```go\n_, err = vm.Run(\"abcdefghijlmnopqrstuvwxyz.length\")\nif err != nil {\n    // err = ReferenceError: abcdefghijlmnopqrstuvwxyz is not defined\n    // If there is an error, then value.IsUndefined() is true\n    ...\n}\n```\n\nSet a Go function\n\n```go\nvm.Set(\"sayHello\", func(call otto.FunctionCall) otto.Value {\n    fmt.Printf(\"Hello, %s.\\n\", call.Argument(0).String())\n    return otto.Value{}\n})\n```\n\nSet a Go function that returns something useful\n\n```go\nvm.Set(\"twoPlus\", func(call otto.FunctionCall) otto.Value {\n    right, _ := call.Argument(0).ToInteger()\n    result, _ := vm.ToValue(2 + right)\n    return result\n})\n```\n\nUse the functions in JavaScript\n\n```go\nresult, _ = vm.Run(`\n    sayHello(\"Xyzzy\");      // Hello, Xyzzy.\n    sayHello();             // Hello, undefined\n\n    result = twoPlus(2.0); // 4\n`)\n```\n\n## Parser\n\nA separate parser is available in the parser package if you're interested\nin only building an AST.\n\n[![GoDoc Reference](https://pkg.go.dev/badge/github.com/robertkrimen/otto/parser.svg)](https://pkg.go.dev/github.com/robertkrimen/otto/parser)\n\nParse and return an AST\n\n```go\nfilename := \"\" // A filename is optional\nsrc := `\n    // Sample xyzzy example\n    (function(){\n        if (3.14159 \u003e 0) {\n            console.log(\"Hello, World.\");\n            return;\n        }\n\n        var xyzzy = NaN;\n        console.log(\"Nothing happens.\");\n        return xyzzy;\n    })();\n`\n\n// Parse some JavaScript, yielding a *ast.Program and/or an ErrorList\nprogram, err := parser.ParseFile(nil, filename, src, 0)\n```\n\n## Setup\n\nYou can run (Go) JavaScript from the command line with\n[otto](http://github.com/robertkrimen/otto/tree/master/otto).\n\n```shell\ngo install github.com/robertkrimen/otto/otto@latest\n```\n\nRun JavaScript by entering some source on stdin or by giving otto a filename:\n\n```shell\notto example.js\n```\n\n## Underscore\n\nOptionally include the JavaScript utility-belt library, underscore, with this\nimport:\n\n```go\nimport (\n    \"github.com/robertkrimen/otto\"\n    _ \"github.com/robertkrimen/otto/underscore\"\n)\n\n// Now every otto runtime will be initialized with Underscore.\n```\n\nFor more information: [underscore](http://github.com/robertkrimen/otto/tree/master/underscore)\n\n## Caveat Emptor\n\nThe following are some limitations with otto:\n\n* `use strict` will parse, but does nothing.\n* The regular expression engine ([re2/regexp](https://pkg.go.dev/regexp)) is not fully compatible with the ECMA5 specification.\n* Otto targets ES5. Some ES6 features, e.g. Typed Arrays, are not supported. Pull requests to add functionality are always welcome.\n\n### Regular Expression Incompatibility\n\nGo translates JavaScript-style regular expressions into something that is\n\"regexp\" compatible via `parser.TransformRegExp`. Unfortunately, RegExp requires\nbacktracking for some patterns, and backtracking is not supported by Go\n[re2](https://github.com/google/re2/wiki/syntax).\n\nTherefore, the following syntax is incompatible:\n\n```plaintext\n(?=)  // Lookahead (positive), currently a parsing error\n(?!)  // Lookahead (backhead), currently a parsing error\n\\1    // Backreference (\\1, \\2, \\3, ...), currently a parsing error\n```\n\nA brief discussion of these limitations: [Regexp (?!re)](https://groups.google.com/forum/?fromgroups=#%21topic/golang-nuts/7qgSDWPIh_E)\n\nMore information [about re2](https://github.com/google/re2)\n\nIn addition to the above, re2 (Go) has a different definition for `\\s`: `[\\t\\n\\f\\r\n]`. The JavaScript definition, on the other hand, also includes `\\v`, Unicode\n\"Separator, Space\", etc.\n\n### Halting Problem\n\nIf you want to stop long running executions (like third-party code), you can use\nthe interrupt channel to do this:\n\n```go\npackage main\n\nimport (\n    \"errors\"\n    \"fmt\"\n    \"os\"\n    \"time\"\n\n    \"github.com/robertkrimen/otto\"\n)\n\nvar halt = errors.New(\"Stahp\")\n\nfunc main() {\n    runUnsafe(`var abc = [];`)\n    runUnsafe(`\n    while (true) {\n        // Loop forever\n    }`)\n}\n\nfunc runUnsafe(unsafe string) {\n    start := time.Now()\n    defer func() {\n        duration := time.Since(start)\n        if caught := recover(); caught != nil {\n            if caught == halt {\n                fmt.Fprintf(os.Stderr, \"Some code took too long! Stopping after: %v\\n\", duration)\n                return\n            }\n            panic(caught) // Something else happened, repanic!\n        }\n        fmt.Fprintf(os.Stderr, \"Ran code successfully: %v\\n\", duration)\n    }()\n\n    vm := otto.New()\n    vm.Interrupt = make(chan func(), 1) // The buffer prevents blocking\n    watchdogCleanup := make(chan struct{})\n    defer close(watchdogCleanup)\n\n    go func() {\n        select {\n        case \u003c-time.After(2 * time.Second): // Stop after two seconds\n            vm.Interrupt \u003c- func() {\n                panic(halt)\n            }\n        case \u003c-watchdogCleanup:\n        }\n        close(vm.Interrupt)\n    }()\n\n    vm.Run(unsafe) // Here be dragons (risky code)\n}\n```\n\nWhere is `setTimeout` / `setInterval`?\n\nThese timing functions are not part of the [ECMA-262 specification](https://ecma-international.org/publications-and-standards/standards/ecma-262/).\nThey typically belong to the window object in a browser environment. While it is\npossible to implement similar functionality in Go, it generally requires wrapping\nOtto in an event loop.\n\nFor an example of how this could be done in Go with otto, see [natto](http://github.com/robertkrimen/natto).\n\nHere is some more discussion of the issue:\n\n* [What is Node.js?](http://book.mixu.net/node/ch2.html)\n* [Reentrancy (computing)](http://en.wikipedia.org/wiki/Reentrancy_%28computing%29)\n* [Perl Safe Signals](https://metacpan.org/pod/Perl::Unsafe::Signals)\n\n## Usage\n\n```go\nvar ErrVersion = errors.New(\"version mismatch\")\n```\n\n### type Error\n\n```go\ntype Error struct {}\n```\n\nAn Error represents a runtime error, e.g. a `TypeError`, a `ReferenceError`, etc.\n\n### func (Error) Error\n\n```go\nfunc (err Error) Error() string\n```\n\nError returns a string representation of the error\n\n```plaintext\n    TypeError: 'def' is not a function\n```\n\n### func (Error) String\n\n```go\nfunc (err Error) String() string\n```\n\nString returns a description of the error and a trace of where the error\noccurred.\n\n```plaintext\n    TypeError: 'def' is not a function\n        at xyz (\u003canonymous\u003e:3:9)\n        at \u003canonymous\u003e:7:1/\n```\n\n### type FunctionCall\n\n```go\ntype FunctionCall struct {\n    This         Value\n    ArgumentList []Value\n    Otto         *Otto\n}\n```\n\nFunctionCall is an encapsulation of a JavaScript function call.\n\n### func (FunctionCall) Argument\n\n```go\nfunc (self FunctionCall) Argument(index int) Value\n```\n\nArgument will return the value of the argument at the given index.\n\nIf no such argument exists, undefined is returned.\n\n### type Object\n\n```go\ntype Object struct {}\n```\n\nObject is the representation of a JavaScript object.\n\n### func (Object) Call\n\n```go\nfunc (self Object) Call(name string, argumentList ...interface{}) (Value, error)\n```\n\nCall a method on the object.\n\nIt is essentially equivalent to:\n\n```go\nvar method, _ := object.Get(name)\nmethod.Call(object, argumentList...)\n```\n\nAn undefined value and an error will result if:\n\n1. There is an error during conversion of the argument list\n2. The property is not actually a function\n3. An (uncaught) exception is thrown\n\n### func (Object) Class\n\n```go\nfunc (self Object) Class() string\n```\n\nClass will return the class string of the object.\n\nThe return value will (generally) be one of:\n\n```plaintext\n    Object\n    Function\n    Array\n    String\n    Number\n    Boolean\n    Date\n    RegExp\n```\n\n### func (Object) Get\n\n```go\nfunc (self Object) Get(name string) (Value, error)\n```\n\nGet the value of the property with the given name.\n\n### func (Object) Keys\n\n```go\nfunc (self Object) Keys() []string\n```\n\nGet the keys for the object\n\nThis is equivalent to calling Object.keys on the object.\n\n### func (Object) Set\n\n```go\nfunc (self Object) Set(name string, value interface{}) error\n```\n\nSet the property of the given name to the given value.\n\nAn error will result if setting the property triggers an exception (e.g.\nread-only) or if there is an error during conversion of the given value.\n\n### func (Object) Value\n\n```go\nfunc (self Object) Value() Value\n```\n\nValue will return self as a value.\n\n### type Otto\n\n```go\ntype Otto struct {\n    // Interrupt is a channel for interrupting the runtime. You can use this to halt a long running execution, for example.\n    // See \"Halting Problem\" for more information.\n    Interrupt chan func()\n}\n```\n\nOtto is the representation of the JavaScript runtime. Each instance of Otto has\na self-contained namespace.\n\n### func New\n\n```go\nfunc New() *Otto\n```\n\nNew will allocate a new JavaScript runtime\n\n### func Run\n\n```go\nfunc Run(src interface{}) (*Otto, Value, error)\n```\n\nRun will allocate a new JavaScript runtime, run the given source on the\nallocated runtime, and return the runtime, resulting value, and error (if any).\n\nsrc may be a string, a byte slice, a bytes.Buffer, or an io.Reader, but it MUST\nalways be in UTF-8.\n\nsrc may also be a Script.\n\nsrc may also be a Program, but if the AST has been modified, then runtime\nbehavior is undefined.\n\n### func (Otto) Call\n\n```go\nfunc (self Otto) Call(source string, this interface{}, argumentList ...interface{}) (Value, error)\n```\n\nCall the given JavaScript with a given this and arguments.\n\nIf this is nil, then some special handling takes place to determine the proper\nthis value, falling back to a \"standard\" invocation if necessary (where this is\nundefined).\n\nIf source begins with \"new \" (A lowercase new followed by a space), then Call\nwill invoke the function constructor rather than performing a function call. In\nthis case, the this argument has no effect.\n\n```go\n// value is a String object\nvalue, _ := vm.Call(\"Object\", nil, \"Hello, World.\")\n\n// Likewise...\nvalue, _ := vm.Call(\"new Object\", nil, \"Hello, World.\")\n\n// This will perform a concat on the given array and return the result\n// value is [ 1, 2, 3, undefined, 4, 5, 6, 7, \"abc\" ]\nvalue, _ := vm.Call(`[ 1, 2, 3, undefined, 4 ].concat`, nil, 5, 6, 7, \"abc\")\n```\n\n### func (*Otto) Compile\n\n```go\nfunc (self *Otto) Compile(filename string, src interface{}) (*Script, error)\n```\n\nCompile will parse the given source and return a Script value. If there is an error during compilation, it will return nil and an error.\n\n```go\nscript, err := vm.Compile(\"\", `var abc; if (!abc) abc = 0; abc += 2; abc;`)\nvm.Run(script)\n```\n\n### func (*Otto) Copy\n\n```go\nfunc (in *Otto) Copy() *Otto\n```\n\nCopy will create a copy/clone of the runtime.\n\nCopy is useful for saving some time when creating many similar runtimes.\n\nThis method works by walking the original runtime and cloning each object,\nscope, stash, etc. into a new runtime.\n\nBe on the lookout for memory leaks or inadvertent sharing of resources.\n\n### func (Otto) Get\n\n```go\nfunc (self Otto) Get(name string) (Value, error)\n```\n\nGet the value of the top-level binding of the given name.\n\nIf there is an error (like the binding does not exist), then the value will be\nundefined.\n\n### func (Otto) Object\n\n```go\nfunc (self Otto) Object(source string) (*Object, error)\n```\n\nObject will run the given source and return the result as an object.\n\nFor example, accessing an existing object:\n\n```go\nobject, _ := vm.Object(`Number`)\n```\n\nOr, creating a new object:\n\n```go\nobject, _ := vm.Object(`({ xyzzy: \"Nothing happens.\" })`)\n```\n\nOr, creating and assigning an object:\n\n```go\nobject, _ := vm.Object(`xyzzy = {}`)\nobject.Set(\"volume\", 11)\n```\n\nIf there is an error (like the source does not result in an object), then nil\nand an error is returned.\n\n### func (Otto) Run\n\n```go\nfunc (self Otto) Run(src interface{}) (Value, error)\n```\n\nRun will run the given source (parsing it first if necessary), returning the\nresulting value and error (if any)\n\nsrc may be a string, a byte slice, a bytes.Buffer, or an io.Reader, but it MUST\nalways be in UTF-8.\n\nIf the runtime is unable to parse source, then this function will return\nundefined and the parse error (nothing will be evaluated in this case).\n\nsrc may also be a Script.\n\nsrc may also be a Program, but if the AST has been modified, then runtime\nbehavior is undefined.\n\n### func (Otto) Set\n\n```go\nfunc (self Otto) Set(name string, value interface{}) error\n```\n\nSet the top-level binding of the given name to the given value.\n\nSet will automatically apply ToValue to the given value in order to convert it\nto a JavaScript value (type Value).\n\nIf there is an error (like the binding is read-only, or the ToValue conversion\nfails), then an error is returned.\n\nIf the top-level binding does not exist, it will be created.\n\n### func (Otto) ToValue\n\n```go\nfunc (self Otto) ToValue(value interface{}) (Value, error)\n```\n\nToValue will convert an interface{} value to a value digestible by\notto/JavaScript.\n\n### type Script\n\n```go\ntype Script struct {}\n```\n\nScript is a handle for some (reusable) JavaScript. Passing a Script value to a\nrun method will evaluate the JavaScript.\n\n### func (*Script) String\n\n```go\nfunc (self *Script) String() string\n```\n\n### type Value\n\n```go\ntype Value struct {}\n```\n\nValue is the representation of a JavaScript value.\n\n### func FalseValue\n\n```go\nfunc FalseValue() Value\n```\n\nFalseValue will return a Value representing the bool value false.\n\nIt is equivalent to:\n\n```go\nToValue(false)\n```\n\n### func  NaNValue\n\n```go\nfunc NaNValue() Value\n```\n\nNaNValue will return a value representing NaN.\n\nIt is equivalent to:\n\n```go\nToValue(math.NaN())\n```\n\n### func  NullValue\n\n```go\nfunc NullValue() Value\n```\n\nNullValue will return a Value representing null.\n\n### func  ToValue\n\n```go\nfunc ToValue(value interface{}) (Value, error)\n```\n\nToValue will convert an interface{} value to a value digestible by\notto/JavaScript\n\nThis function will not work for advanced types (struct, map, slice/array, etc.)\nand you should use Otto.ToValue instead.\n\n### func  TrueValue\n\n```go\nfunc TrueValue() Value\n```\n\nTrueValue will return a value representing true.\n\nIt is equivalent to:\n\n```go\nToValue(true)\n```\n\n### func UndefinedValue\n\n```go\nfunc UndefinedValue() Value\n```\n\nUndefinedValue will return a Value representing undefined.\n\n### func (Value) Call\n\n```go\nfunc (value Value) Call(this Value, argumentList ...interface{}) (Value, error)\n```\n\nCall the value as a function with the given this value and argument list and\nreturn the result of invocation. It is essentially equivalent to:\n\n```js\n    value.apply(thisValue, argumentList)\n```\n\nA value of undefined and an error will result if:\n\n1. There is an error during conversion of the argument list\n2. The value is not actually a function\n3. An (uncaught) exception is thrown\n\n### func (Value) Class\n\n```go\nfunc (value Value) Class() string\n```\n\nClass will return the class string of the value or the empty string if value is\nnot an object.\n\nThe return value will (generally) be one of:\n\n```plaintext\n    Object\n    Function\n    Array\n    String\n    Number\n    Boolean\n    Date\n    RegExp\n```\n\n### func (Value) Export\n\n```go\nfunc (self Value) Export() (interface{}, error)\n```\n\nExport will attempt to convert the value to a Go representation and return it\nvia an interface{} kind.\n\nExport returns an error, which will always be nil. It is included for backwards\ncompatibility.\n\nIf a reasonable conversion is not possible, then the original value is returned.\n\n```plaintext\n    undefined   -\u003e nil (FIXME?: Should be Value{})\n    null        -\u003e nil\n    boolean     -\u003e bool\n    number      -\u003e A number type (int, float32, uint64, ...)\n    string      -\u003e string\n    Array       -\u003e []interface{}\n    Object      -\u003e map[string]interface{}\n```\n\n### func (Value) IsBoolean\n\n```go\nfunc (value Value) IsBoolean() bool\n```\n\nIsBoolean will return true if value is a boolean (primitive).\n\n### func (Value) IsDefined\n\n```go\nfunc (value Value) IsDefined() bool\n```\n\nIsDefined will return false if the value is undefined, and true otherwise.\n\n### func (Value) IsFunction\n\n```go\nfunc (value Value) IsFunction() bool\n```\n\nIsFunction will return true if value is a function.\n\n### func (Value) IsNaN\n\n```go\nfunc (value Value) IsNaN() bool\n```\n\nIsNaN will return true if value is NaN (or would convert to NaN).\n\n### func (Value) IsNull\n\n```go\nfunc (value Value) IsNull() bool\n```\n\nIsNull will return true if the value is null, and false otherwise.\n\n### func (Value) IsNumber\n\n```go\nfunc (value Value) IsNumber() bool\n```\n\nIsNumber will return true if value is a number (primitive).\n\n### func (Value) IsObject\n\n```go\nfunc (value Value) IsObject() bool\n```\n\nIsObject will return true if value is an object.\n\n### func (Value) IsPrimitive\n\n```go\nfunc (value Value) IsPrimitive() bool\n```\n\nIsPrimitive will return true if value is a primitive.\n\n### func (Value) IsString\n\n```go\nfunc (value Value) IsString() bool\n```\n\nIsString will return true if value is a string (primitive).\n\n### func (Value) IsUndefined\n\n```go\nfunc (value Value) IsUndefined() bool\n```\n\nIsUndefined will return true if the value is undefined, and false otherwise.\n\n### func (Value) Object\n\n```go\nfunc (value Value) Object() *Object\n```\n\nObject will return the object of the value, or nil if value is not an object.\n\nThis method will not do any implicit conversion. For example, calling this\nmethod on a string primitive value will not return a String object.\n\n### func (Value) String\n\n```go\nfunc (value Value) String() string\n```\n\nString will return the value as a string.\n\nThis method will return the empty string if there is an error.\n\n### func (Value) ToBoolean\n\n```go\nfunc (value Value) ToBoolean() (bool, error)\n```\n\nToBoolean will convert the value to a boolean (bool).\n\n```plaintext\n    ToValue(0).ToBoolean() =\u003e false\n    ToValue(\"\").ToBoolean() =\u003e false\n    ToValue(true).ToBoolean() =\u003e true\n    ToValue(1).ToBoolean() =\u003e true\n    ToValue(\"Nothing happens\").ToBoolean() =\u003e true\n```\n\nIf there is an error during the conversion process (like an uncaught exception),\nthen the result will be false and an error.\n\n### func (Value) ToFloat\n\n```go\nfunc (value Value) ToFloat() (float64, error)\n```\n\nToFloat will convert the value to a number (float64).\n\n```plaintext\n    ToValue(0).ToFloat() =\u003e 0.\n    ToValue(1.1).ToFloat() =\u003e 1.1\n    ToValue(\"11\").ToFloat() =\u003e 11.\n```\n\nIf there is an error during the conversion process (like an uncaught exception),\nthen the result will be 0 and an error.\n\n### func (Value) ToInteger\n\n```go\nfunc (value Value) ToInteger() (int64, error)\n```\n\nToInteger will convert the value to a number (int64).\n\n```plaintext\n    ToValue(0).ToInteger() =\u003e 0\n    ToValue(1.1).ToInteger() =\u003e 1\n    ToValue(\"11\").ToInteger() =\u003e 11\n```\n\nIf there is an error during the conversion process (like an uncaught exception),\nthen the result will be 0 and an error.\n\n### func (Value) ToString\n\n```go\nfunc (value Value) ToString() (string, error)\n```\n\nToString will convert the value to a string (string).\n\n```plaintext\n    ToValue(0).ToString() =\u003e \"0\"\n    ToValue(false).ToString() =\u003e \"false\"\n    ToValue(1.1).ToString() =\u003e \"1.1\"\n    ToValue(\"11\").ToString() =\u003e \"11\"\n    ToValue('Nothing happens.').ToString() =\u003e \"Nothing happens.\"\n```\n\nIf there is an error during the conversion process (like an uncaught exception),\nthen the result will be the empty string (\"\") and an error.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertkrimen%2Fotto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertkrimen%2Fotto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertkrimen%2Fotto/lists"}