Skip to content

Commit

Permalink
fill README more
Browse files Browse the repository at this point in the history
  • Loading branch information
hmsk committed Jun 16, 2024
1 parent 8d24d61 commit faea636
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,32 @@ A Ruby wrapper for [QuickJS](https://bellard.org/quickjs) to run JavaScript code
gem install quickjs
```

```
```rb
gem 'quickjs'
```

## Features
## Usage

### Evaluate JavaScript code
### `Quickjs.evalCode`: Evaluate JavaScript code

```rb
require 'quickjs'

Quickjs.evalCode('const fn = (n, pow) => n ** pow; fn(2,8);') # => 256
Quickjs.evalCode('const fn = (name) => `Hi, ${name}!`; fn("Itadori");') # => "Hi, Itadori!
Quickjs.evalCode("const isOne = (n) => 1 === n; func(1);") #=> true (TruleClass)
Quickjs.evalCode("const isOne = (n) => 1 === n; func(3);") #=> false (FalseClass)

# If the result returns 'object' for typeof, consumes it via JSON.stringify (JS) -> JSON.parse (Ruby)
Quickjs.evalCode("[1,2,3]") #=> [1, 2, 3] (Array)
Quickjs.evalCode("({ a: '1', b: 1 })") #=> { 'a' => '1', 'b' => 1 } (Hash)

Quickjs.evalCode("null") #=> nil
Quickjs.evalCode('const obj = {}; obj.missingKey;') # => :undefined (Quickjs::Value::Undefined)
Quickjs.evalCode("Number('whatever')") #=> :NaN (Quickjs::Value::NAN)
```

## License

Every file in `ext/quickjsrb/quickjs` is licensed under [the MIT License Copyright 2017-2021 by Fabrice Bellard and Charlie Goron](/ext/quickjsrb/quickjs/LICENSE). For otherwise, [the MIT License, Copyright 2024 by Kengo Hamasaki](/LICENSE).
Every file in `ext/quickjsrb/quickjs` is licensed under [the MIT License Copyright 2017-2021 by Fabrice Bellard and Charlie Goron](/ext/quickjsrb/quickjs/LICENSE).
For otherwise, [the MIT License, Copyright 2024 by Kengo Hamasaki](/LICENSE).

0 comments on commit faea636

Please sign in to comment.