npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rivescript-rsgb

v1.0.0

Published

RiveScript-Go bindings for JavaScript

Downloads

5

Readme

RSGB for JavaScript

This is a "binding" of the RiveScript Go module to JavaScript. It's compiled using gopherjs.

I learned how to do this from the bluemonday-js project on GitHub. See their README for the background of how this works.

This module should be available via npm if you're brave enough to try it:

npm install rivescript-rsgb

For production use you should be better off using the native JavaScript implementation of RiveScript at https://github.com/aichaos/rivescript-js.

API Differences

There are a couple of differences in the API to this module versus the native JavaScript version of RiveScript. Refer to the GoDoc for the RiveScript Go module for API usage. Briefly, most of the functions you're used to now begin with a capital letter, as that's the convention for exported functions in Go. For example, SetUservar() rather than setUservar().

Also, only the exported functions of the RiveScript Go module are available to JavaScript, so you e.g. can't assign bot.Debug = true to turn on debug mode. Instead, use the following functions to configure the bot:

var bot = new RiveScript(); // The constructor takes no parameters
bot.SetDebug(true);  // Activate debug mode
bot.SetUTF8(true);    // Enable UTF-8 support
bot.SetDepth(100);   // Change recursion depth
bot.SetStrict(true); // Strict syntax parsing (it's true by default)

// To override the Unicode punctuation symbols call this function and pass it
// the *string literal* regexp (not a Regexp object; these don't translate well
// into Go)
bot.SetUnicodePunctuation('[.,!?;:]')

Usage

var RiveScript = require("rivescript-rsgb"),
    fs = require("fs");

var bot = new RiveScript();

// No system calls are supported for gopherjs so LoadDirectory/LoadFile won't
// work... we have to use Stream() to input all the RiveScript documents.
bot.Stream(fs.readFileSync("rs-standard.rive", "utf8"));
bot.SortReplies();

var username = "local-user";
var reply = bot.Reply(username, "hello, bot");
console.log("Bot>", reply);

Building

These steps assume you already have a working Golang development environment.

First, install gopherjs and the source to rivescript-go:

$ go get -u github.com/gopherjs/gopherjs
$ go get github.com/aichaos/rivescript-go

Grunt commands (needs grunt-cli, e.g. npm install -g grunt-cli):

  • grunt test: Run the unit tests
  • grunt dist: Browserify and minify the JavaScript. This should make the module available to be served on a web page. The output goes into the dist/ directory.
  • grunt clean: Removes the dist/ directory.

Caveats

System calls aren't supported by gopherjs, so the RiveScript module can't access files from disk. This means LoadFile() and LoadDirectory() calls will fail. The alternative is for your JavaScript to load the files on its own, and pass their contents in via Stream().

Object macros aren't supported at this time but may be investigated in the future.

The file sizes of the compiled JavaScript files are substantially larger than the native JS version (at time of writing we're talking 1.8M versus 64K!). Minified it's 900KB larger than the native JavaScript version.

LICENSE

The MIT License (MIT)

Copyright (c) 2015 Noah Petherbridge

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

SEE ALSO

The official RiveScript website, http://www.rivescript.com/

The native JavaScript port of RiveScript, https://github.com/aichaos/rivescript-js