Socket
Socket
Sign inDemoInstall

gotiny

Package Overview
Dependencies
2
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    gotiny

SDK for GoTiny: A lightweight link shortener API


Version published
Maintainers
1
Install size
403 kB
Created

Readme

Source

GoTiny SDK

SDK for GoTiny: A lightweight link shortener API

Table of Contents

  • Installation
  • Usage
  • Automatic URL Parsing
  • About GoTiny Links
  • Privacy
  • License
  • Other Repositories

Installation

npm install gotiny

Usage

To create a new GoTiny link, pass the long url as an argument in the gotiny.set() function.

const gotiny = require("gotiny")

// Using Then

gotiny.set("https://amazon.com/very-long-url")
  .then(res => console.log(res))
  .catch(err => console.log(err))

// Using Async/Await

const createShortLink = async (input) => {

  try {
    const res = await gotiny.set(input)
    console.log(res)
  } catch (err) {
    console.log(err)
  }

}

createShortLink("https://amazon.com/very-long-url")

The response will always be an array of objects, each of which contains a tiny link, formatted in different ways.

  • long: The original url that was used to create the GoTiny link
  • code: The short code used to identify the GoTiny link
  • tiny: The short link created by GoTiny
  • link: The short link created by GoTiny, prefixed by the http-protocol

Example response:

// gotiny.set("https://amazon.com/very-long-url")

;[
  {
    long: "https://amazon.com/very-long-url",
    code: "y68hxc",
    tiny: "gotiny.cc/y68hxc",
    link: "https://gotiny.cc/y68hxc",
  },
]

Note that you’re not required to use the long attribute in your code. GoTiny will automatically resolve the short link in the users web browser to point to the original url.

Options

Options are provided by passing an object as a second argument to the gotiny.set() function. Options currently supported are:

KeyTypeDescription
customstringShould consist of 4-32 lowercase letters, numbers, hyphen and/or underscore symbols
useFallbackbooleanSet to false if you don't want to generate a random code when a custom code can't be used
gotiny.set("https://amazon.com/very-long-url", {
  custom: "amazon", // generate gotiny.cc/amazon
  useFallback: false // don't use randomly generated code when "amazon" can't be used
})

To resolve a GoTiny link, pass the link as an argument in the gotiny.get() function

const gotiny = require("gotiny")

// Using Then

gotiny.get("https://gotiny.cc/y68hxc")
  .then(res => console.log(res))
  .catch(err => console.log(err))

// Using Async/Await

const resolveShortLink = async (input) => {

  try {
    const res = await gotiny.get(input)
    console.log(res)
  } catch (err) {
    console.log(err)
  }

}

resolveShortLink("https://gotiny.cc/y68hxc")

Alternatively, you can omit the http-protocol or pass just the GoTiny code to the gotiny.get() function.

Automatic URL Parsing

GoTiny automatically filters URLs from the user input. This way, you as a developer won't have to provide a clean link, but can just feed an entire paragraph into GoTiny. It will create a short url from every url that it finds and include it in the response array.

Example response:

// gotiny.set("The top 3 most popular websites are youtube.com, www.google.com and apple.com.")

[
  {
    long: "youtube.com",
    code: "86df6c",
    tiny: "gotiny.cc/86df6c",
    link: "https://gotiny.cc/86df6c",
  },
  {
    long: "www.google.com",
    code: "6wrsnf",
    tiny: "gotiny.cc/6wrsnf",
    link: "https://gotiny.cc/6wrsnf",
  },
  {
    long: "apple.com",
    code: "c56ned",
    tiny: "gotiny.cc/c56ned",
    link: "https://gotiny.cc/c56ned",
  },
];

The unique links that GoTiny generates are always 16 characters long, including the domain name. GoTiny links are all lowercase and don't include characters that could be confused with each other (e.g. o/0 or 1/i/l).

Privacy

GoTiny does not collect, handle or store any user information.

License

MIT

Other Repositories

FAQs

Last updated on 14 Nov 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc