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

open-issue

v0.2.0

Published

Open a new issue with preformatted content

Downloads

11

Readme

open-issue

Did you know that by opening the correct url, you can create a new issue on GitHub with already predefined content? Just click here to see it in action (please, do not actually create the issue). This lib will provide you an API to create such url and eventually open it in the browser. The goal is to have your users easily create issues on your project.

Install

npm install open-issue --save

API

Node (or Browserify)

var issue = require('open-issue');
// Init an empty issue
var newOne = issue()
  // A Github issue
  .provider('github')
  // For a specify repository
  .repository('pauldijou/open-issue')
  // With a nice title
  .title('We just crashed everything')
  // And some labels
  .labels('bug', 'fatal')
  // For the next milestone?
  .milestone('fake')
  // Assign a poor developer
  .assign('pauldijou')
  // Append some text
  .append('This is a test.')
  // Or some code
  .appendCode('function () { return true; }', 'javascript')
  // More text
  .append('The end!');

// Generate the final url
newOne.url();

// Open a new tab in the browser
newOne.open();

Browser

<!DOCTYPE html>
<html>
<head></head>
<body>
  <div><input id="title" type="text" name="title" placeholder="Issue title"></div>
  <div><textarea id="body" name="body" rows="8" cols="40"></textarea></div>
  <div><button id="open" type="button" name="button">Open issue</button></div>

  <!-- For dev purpose only, install the file locally before going to production -->
  <script type="text/javascript" src="https://rawgit.com/pauldijou/open-issue/master/index.js"></script>
  <script type="text/javascript">
    document.getElementById('open').addEventListener('click', function () {
      OpenIssue()
        .provider('github')
        .repository('pauldijou/open-issue')
        .title(document.getElementById('title').value)
        .append(document.getElementById('body').value)
        .open();
    });
  </script>
</body>
</html>

See it in action (you might need to click on "Run with JS")

Shortcuts

issue.github('pauldijou/open-issue');
// Same as
issue()
  .provider('github')
  .repository('pauldijou/open-issue')

Configuration

By default, each append will be separated by \n\n. You can change that.

var newOne = issue.github('pauldijou/open-issue').append('1').append('2').append('3');

console.log(newOne.url());
// https://github.com/pauldijou/open-issue/issues/new?body=1%0A%0A2%0A%0A3

issue.separator('\n');

console.log(newOne.url());
// https://github.com/pauldijou/open-issue/issues/new?body=1%0A2%0A3

issue.separator('');

console.log(newOne.url());
// https://github.com/pauldijou/open-issue/issues/new?body=123

Real world use-case

Node CLI

You can run all examples by doing npm run examples.

Help your users report an unexpected crash.

// Extract stack and hide user paths
function parseError(error) {
  // If this file is at the root of your project
  var pathRegexp = new RegExp(__dirname, 'g');
  var display = '';
  if (error.code) { display += 'Error code: ' + error.code + '\n\n' };
  if (error.stack) { display += error.stack.replace(pathRegexp, ''); }
  if (!display) { display = error.toString(); }
  return display;
}

// Open the issue if user is ok
function openIssue(e) {
  require('open-issue')
    .github('pauldijou/open-issue')
    .title('Unexpected error')
    .labels('bug', 'fatal')
    .append('The following error occured:')
    .appendCode(parseError(e))
    .append('You can also add custom infos if necessary...')
    .open();
}

process.on('uncaughtException', function(e) {
  console.log('[ERROR] An unexpected error occured.\n');

  var readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
  });

  // Ask user if (s)he wants to open an issue
  readline.question('Would you like to open an issue to help fixing the problem? Y/n\n(this will open a new tab in your browser)\n', function(answer) {
    if (!answer || answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes') {
      openIssue(e);
      console.log('\nThanks a lot for your help!');
    }

    readline.close();
  });
});

Test

npm test

License

This software is licensed under the Apache 2 license, quoted below.

Copyright 2015 Paul Dijou (http://pauldijou.fr).

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.