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

randomorg-js

v1.0.0

Published

Streaming Random.org JSON-RPC Javascript API - for node, command line (cli) and the browser.

Downloads

10

Readme

npm mit license build status coverage status deps status

Streaming Random.org JSON-RPC Javascript API - for node, command line (cli) and the browser.

Install

npm install randomorg-js
npm test

Include in html

After that you can use directly new RandomJs() class.

<script src="https://cdn.rawgit.com/tunnckoCore/randomorg-js/master/dist/randomorg-js.js"></script>

Usage in node.js

For more use-cases see the tests and examples

var RandomJs = require('randomorg-js');
var randomJs = new RandomJs();

var result = randomJs
  .apikey('6b1e65b9-4186-45c2-8981-b77a9842c4f0') // your apikey here
  .headers({'User-Agent': 'https://github.com/tunnckoCore/randomorg-js'})
  .method('generateStrings')
  .params({n:4,length:11})
  .post(function(error, stream, body) {
    console.log('==START==')
    console.log('==error==')
    console.log(error)
    console.log('==stream==')
    console.log(stream)
    console.log('==body==')
    console.log(body)
    console.log('==END==')
  });

Usage in browser

var randomJs = new RandomJs();

var result = randomJs
  .apikey('6b1e65b9-4186-45c2-8981-b77a9842c4f0') // your apikey here
  .method('generateStrings')
  .params({n:4,length:11})
  .post(function(xhr, stream, body) {
    console.log('==START==')
    console.log('==xhr==')
    console.log(xhr)
    console.log('==stream==')
    console.log(stream)
    console.log('==body==')
    console.log(body)
    console.log('==END==')
  });

API

RandomJs(body)

Initialize a new RandomJs instance with [body] (optional) object.
See also https://api.random.org/json-rpc/1/basic

members

params

  • [body] {Object} body object that will send to api
  • [statusCb] {Function} callback that recieves request status
  • return {RandomJs}

.request

Get status of request that will be send to API

params

  • [statusCb] {Function} callback that recieves request status
  • return {RandomJs|Object} returns self or RandomJs._request object

.apikey

Set your API key

params

  • <apikey> {String} your api key with that you will auth to api
  • [statusCb] {Function} callback that recieves request status
  • return {RandomJs}

.jsonrpc

Set version of Random.Org JSON RPC API

params

  • <value> {String} default '2.0'
  • [statusCb] {Function} callback that recieves request status
  • return {RandomJs}

.method

Set which rpc method to use (see https://api.random.org/json-rpc/1/basic)

params

  • <value> {String} default 'generateIntegers'
  • [statusCb] {Function} callback that recieves request status
  • return {RandomJs}

.params

Set params object that will be attached to the request body

params

.id

Set id request body

params

  • <value> {Object} default (0 | Math.random() * 1000)
  • [statusCb] {Function} callback that recieves request status
  • return {RandomJs}

.url

Set url to the api endpoint it's always https://api.random.org/json-rpc/1/invoke

params

  • <value> {String} default https://api.random.org/json-rpc/1/invoke
  • [statusCb] {Function} callback that recieves request status
  • return {RandomJs}

.uri

Short-hand for .url

params

  • <value> {String} same as .url
  • [statusCb] {Function} callback that recieves request status
  • return {RandomJs}

.callback

Callback that will handle the response.

params

  • <fn> {Function} cb(xhrOrErr, stream, body)
  • [statusCb] {Function} callback that recieves request status
  • return {RandomJs}

You must provide function with 3 arguments that are

  • xhrOrErr {Object} if browser, will be xhr request, else error
  • stream {Stream} if browser, will be null, else [request's stream][request-url]
  • body {Object} always, response body object of the request

.headers

Headers that will send with request.
Always append {'Content-Type': 'application/json'} header to others.

params

  • <object> {Object} default {'Content-Type': 'application/json'}
  • [statusCb] {Function} callback that recieves request status
  • return {RandomJs}

.post

Send request to the JSON-RPC API

params

  • [done] {Boolean|Function} if false, will use .callback
  • [statusCb] {Function} callback that recieves request status
  • return {RandomJs}

Author

Charlike Mike Reagent

License MIT license

Copyright (c) 2014 Charlike Mike Reagent, contributors.
Released under the MIT license.


Powered and automated by readdirp + hogan.js, December 30, 2014