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 🙏

© 2025 – Pkg Stats / Ryan Hefner

offer-generator

v0.2.0

Published

Library for generating ODRL Licence offers

Downloads

7

Readme

Offer Generator

A React Component that allows you to construct ODRL licence offers in json-ld format.

Acronyms

| Acronym | Description | | :------ | :---------- | | ODRL | Open Digital Rights Language |

Using the Offer Generator

A full example can be found in the example directory.

Install

Start by installing the offer-generator via npm:

npm install offer-generator --save

Render

The offer-generator package provides two main components:

  • OfferGenerator: The main building tool for constructing an ODRL offer.
  • JsonLDViewer: A helper component that can be used to display the json-ld constructed by the offer builder

Both use bootstrap components and class names. For details on how to customise the css please refer to the Bootstrap documentation.

Offer Generator

This is the main building tool for constructing an ODRL offer.

{OfferGenerator} = require('offer-generator');
class Component extends React.Component {
    render: function () {
        return (
            <div>
                <OfferGenerator />
            </div>
        );
    }
} 
API
onCreate

Pass a function to call when the button is clicked. The function will receive the json-ld offer as a parameter. Use this function to retrieve the end result offer, and process it as needed.

  • Type: function
  • Required: yes
  • Default: undefined
{OfferGenerator} = require('offer-generator');
class Component extends React.Component {
    render: function () {
        return (
            <div>
                <OfferGenerator 
                    onCreate={(json) => {this.setState({json: json})}}
                    />
            </div>
        );
    }
} 
buttonText

This controls the text that is displayed on the main creation button of the builder.

  • Type: string
  • Required: no
  • Default: 'Generate Offer'
{OfferGenerator} = require('offer-generator');
class Component extends React.Component {
    render: function () {
        return (
            <div>
                <OfferGenerator 
                    buttonText='Save Offer'
                    />
            </div>
        );
    }
} 
assigner

This provides a default assigner id for the offer builder. If provided then the assigner will be displayed but will not be editable within the builder.

  • Type: string
  • Required: no
  • Default: undefined
{OfferGenerator} = require('offer-generator');
class Component extends React.Component {
    render: function () {
        return (
            <div>
                <OfferGenerator 
                    assigner='my-test-assigner'
                    />
            </div>
        );
    }
} 
initialOffer

This provides an initial offer to populate the offer builder with on initialisation.

  • Type: json-ld object
  • Required: no
  • Default: undefined
{OfferGenerator} = require('offer-generator');
class Component extends React.Component {
    render: function () {
        return (
            <div>
                <OfferGenerator 
                    initialOffer={this.state.offer}
                    />
            </div>
        );
    }
} 

JSON-ld Viewer

{JsonLdViewer} = require('offer-generator');
class Component extends React.Component {
    render: function () {
        return (
            <div>
                <JsonLdViewer
                      jsonld={this.state.jsonld}
                    />
            </div>
        );
    }
} 
API
jsonld

Pass the json ld to display.

  • Type: json-ld object
  • Required: yes
  • Default: undefined

Developing the Offer Generator

The UI is implemented completely in JavaScript using

Getting Started

Download & install node & npm or use your package manager of choice e.g.

brew install node

Install dependencies

npm install

Build

Transpile code using babel

npm run build

Build example application for deployment

Either run this

cd example
npm install
npm run build

Build example application for testing during development

  • Remove node_modules sub-directory from example directory.
  • In example/src/index.js, change

{OfferGenerator, JsonLdViewer} = require('offer-generator');

to

{OfferGenerator, JsonLdViewer} = require('../../src');

  • In top level directory either run this
npm run build-example

or this, if you require automatic rebuild of the bundle whenever there are file changes

npm run build-example:watch

Running the example

You need a web server to serve index.html. We recommend you use python's HTTP Server e.g:

python -m SimpleHTTPServer

You should be able to view the application at http://localhost:8000.

Tests

Unit tests are written using mocha, which can be run with

npm test

Publish to npm

The offer-viewer has been published to npm under the OpenPermissions account. To publish a new version, increase the version number in package.json and run

npm publish ./