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

twurlrc

v1.0.1

Published

Parse .twurlrc files

Downloads

10

Readme

twurlrc

Package Version

Parse .twurlrc files.

twurl stores Twitter credentials in ~/.twurlrc (in YAML format). This package will parse a .twurlrc file and return credentials suitable for use with oauth-1.0a.

Install

npm install twurlrc

Quick Start

The got package provides an excellent example of how to send a signed OAuth request with oauth-1.0a. A modified version of that example is included below to illustrate how to incorporate twurlrc:

const got = require('got');
const crypto  = require('crypto');
const OAuth = require('oauth-1.0a');
const {consumer, access_token} = require('twurlrc').fromFileSync().defaultCredentials();

const oauth = OAuth({
    consumer,
    signature_method: 'HMAC-SHA1',
    hash_function: (baseString, key) => crypto.createHmac('sha1', key).update(baseString).digest('base64')
});

const url = 'https://api.twitter.com/1.1/statuses/home_timeline.json';

got(url, {
    headers: oauth.toHeader(oauth.authorize({url, method: 'GET'}, access_token)),
    json: true
});

The Twurlrc class is used to get credentials from parsed data.

Call Twurlrc.fromFile or Twurlrc.fromFileSync to create a Twurlrc object and load the contents of the specified file path. If no path is specified ~/.twurlrc is loaded by default.

Call Twurlrc.fromYAMLSync to create a Twurlrc object from a YAML string.

API

Table of Contents

Twurlrc

Get credentials from parsed data.

Parameters

  • data Object object returned by YAML parser
    • data.configuration Object
      • data.configuration.default_profile Array [0]: screen_name, [1]: consumer_key
    • data.profiles Object credentials grouped by screen_name then consumer_key

data

object returned by YAML parser

Type: Object

credentials

Get credentials for the specified profile.

Returns grouped key/secret pairs by default. Disable grouping by passing true for the raw parameter value.

If the consumer_key parameter is omitted or falsy, the "first" consumer_key defined for provided screen_name is used. This fallback is provided for convenience when parsing profiles with a single consumer_key defined. To load credentials from profiles with multiple consumer_keys defined, specifying which consumer_key to load is strongly recommended (as opposed to relying on definition order).

Parameters
  • screen_name string Twitter user screen_name
  • consumer_key string Twitter app consumer_key
  • raw boolean return unmodified credentials object instead of grouping key/secret pairs (optional, default false)
Examples
// get credentials with grouped key/secret pairs
const {consumer, access_token, screen_name} = twurlrc.credentials('my_screen_name', 'my_consumer_key');
// consumer === {key: consumer_key, secret: consumer_secret}
// access_token === {key: token, secret: secret}
// screen_name === 'my_screen_name'
// disable grouping
const {consumer_key, consumer_secret, token, secret, username} = twurlrc.credentials('my_screen_name', 'my_consumer_key', true);

Returns Object

defaultCredentials

Get credentials for the default profile.

Returns grouped key/secret pairs by default. Disable grouping by passing true for the raw parameter value.

Parameters
  • raw boolean return unmodified credentials object instead of grouping key/secret pairs (optional, default false)
Examples
// get default credentials with grouped key/secret pairs
const {consumer, access_token, screen_name} = twurlrc.defaultCredentials();
// consumer === {key: consumer_key, secret: consumer_secret}
// access_token === {key: token, secret: secret}
// screen_name === 'my_screen_name'
// disable grouping
const {consumer_key, consumer_secret, token, secret, username} = twurlrc.defaultCredentials(true);

Returns Object

fromYAMLSync

Create a Twurlrc object from a YAML string.

Parameters
Examples
try {
    const twurlrc = require('twurlrc').fromYAMLSync('YAML STRING');
    // use twurlrc
}
 catch(error) {
    console.error(error.message);
}

Returns Twurlrc

fromFileSync

Create a Twurlrc object from a file path.

Parameters
  • filePath string path to .twurlrc file
Examples
try {
    const twurlrc = require('twurlrc').fromFileSync('/path/to/.twurlrc');
    // use twurlrc
}
 catch(error) {
    console.error(error.message);
}

Returns Twurlrc

fromFile

Asynchronously create a Twurlrc object from a file path.

Parameters
  • filePath string path to .twurlrc file
Examples
const Twurlrc = require('twurlrc');
Twurlrc.fromFile('/path/to/.twurlrc')
     .then((twurlrc) => {
         // use twurlrc
     })
     .catch((error) => console.error(error.message));

Returns Promise

Development

Clone the repository and cd into the resulting directory.

Install Dependencies

npm install

Run Tests

npm test

Note: Tests expect a ~/.twurlrc file to exist. The easiest way to create one is with twurl.

Built With

Contributing

Fork the repo and submit a pull request.

Versioning

SemVer is used for versioning. For the versions available, see the tags on this repository.

Author

Adam Jarret

License

This project is licensed under the MIT License. See the LICENSE.txt file for details.