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

opizo-api

v0.1.1

Published

opizo.com shortener api module for node.js

Downloads

8

Readme

opizo-api

NPM

opizo.com shortener api module for node.js. (client)
All functions return a promise

Persian version of readme

Installation

with npm:

$ npm install --save opizo-api   

or with yarn:

$ yarn add opizo-api

Example

Request to get short url:

const opizo = require('opizo-api');

// Not need to setUsername you can use without login

// Just request to short a url
opizo('http://example.com')
  .then((result) => {
    console.log(`Short url: ${result.shortUrl}\nRequested url: ${result.url}`);
  })
  .catch((err) => {
    console.log(err.message, err.rp.message); console.log(`Requested url: ${err.result.url}`);
  });

Request to get short url and file info:

const opizo = require('opizo-api');

// Optional (you can leave it blank or just don't call this function)
// username on here or set as environment varialbe
opizo.setUser('')

// Request to short a url and get file name and size info
opizo.extra('http://bayanbox.ir/thumb/8633283754319788500/GitHub-Logo.jpg')
  .then(result => {
    console.log(`Short url: ${result.shortUrl}\nRequested url: ${result.url}`);
    console.log(`fileName: ${result.fileInfo.name}\nfileSize: ${result.fileInfo.sizeInMB}`);
  })
  .catch(err => {
    console.log(err.message, err.rp.message);
    console.log(`Requested url: ${err.result.url}`);
  });

functions

Use main function, when you require module you can use it as function like below(opizo is the variable name but after required it is main function):

const opizo = require('opizo-api');
  • opizo(your-url): request short link
  • opizo.extra(your-url): request short link & file info
  • opizo.setUse(your-username): optional, set the username to make your link manageable, you can also use environment variable like this:
$ export OPIZO_USERNAME='your-user-name-here'

or just don't call this function.

Result object

On main function returned result object have below property:

  • url: Requested url
  • shortUrl: short url if request not failed

On extra function returned result object have below property:

  • url: Requested url
  • shortUrl: Short url if request not failed
  • fileInfo: File info if request not failed
    • name: File name if exists
    • sizeInMB: File size in pretty format
    • contentLength: File size in kb

err object

Error object on catch have below property:

  • code: Internal error code
  • message: Internal error message
  • result: This is result object
  • rp: More details
    • code: Error code
    • message: Error message