chauncey
Shorten URLs with Bitly.
Usage: chauncey <url> [options]
Options:
-h, --help Show help
Example:
chauncey http://google.com/ Shorten http://google.com/ using Bitly
"Chauncey"?
Chauncey McPufferson is Bitly's mascot :smiley:
Installation
$ npm i -g chauncey
Configuration
First you need a Bitly developer access token. Then you'll need to add the token to your user environment, for example:
$ BITLY_ACCESS_TOKEN=[access token] chauncey http://google.com/
You can also use a .chaunceyrc
file. Chauncey will look for .chaunceyrc
starting in process.cwd()
, then ../
, ../../
, all the way up to the filesystem root. It should have the following content:
export BITLY_ACCESS_TOKEN=[access token]
Usage
Chauncey will output the shortened URL to stdout
:
$ chauncey http://google.com/
http://bit.ly/1jib0Hi
So on OS X, you can do stuff like:
$ chauncey http://google.com/ | pbcopy
API
TODO: what if someone
chauncey(url, [token], [callback])
Shortens url
using the Bitly API.
Arguments
url
- The URL to shorten.token
- Optional Bitly developer access token. If not passed, chauncey will look for token
as described in configuration.callback
- Optionalcallback(err, results)
- Optional A callback which is called after all the iterator
functions have finished, or an error occurs. Results is an array containing
the concatenated results of the iterator
function.
Note: the callbacks do not take an error as their first argument.
Example
async.every(['file1','file2','file3'], fs.exists, function(result){
});
export default ({ url, token, done = () => {} }) => {
try {
token = token || findToken();
} catch (error) {
return done(error);
}
https.get(
https://api-ssl.bitly.com/v3/shorten?access_token=${token}&longUrl=${url}&format=txt
,
(res) => res.pipe(concat({ encoding: 'string' }, (res) => done(null, res)))
).on('error', done);
};
function findToken() {
habitat.load(findNearest('.chaunceyrc'));
const token = habitat.get('BITLY_ACCESS_TOKEN');
if (!token) throw new Error('BITLY_ACCESS_TOKEN not found');
return token;
}
Note
This module uses the Bitly API, but is neither developed nor endorsed by Bitly.
License
MIT