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

linkclipper

v2.0.0

Published

A URL shortener

Downloads

27

Readme

LinkClipper

View the NPM package here.

LinkClipper is a package to help developers to easily shorten any URLs that they want to display to users in their apps.

For example you may have a resource-sharing app where users can submit their own links to share with others, and you have a page where you want to display a list of resources to the users, where each resource has a title, link, description, tags etc. However you don't want to show the full link address (such as 'https://www.stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array'), you just want to show the site name (such as 'stackoverflow.com'). LinkClipper can handle this URL shortening for you automatically.

A screenshot summarising the above use-case.

Contents

  1. Purpose

  2. Usage

  3. Testing

  4. Future plans

  5. Acknowledgements

  6. Contributors

Purpose

With this project our goals were to:

  • Create a simple package that would be helpful for other developers.
  • Learn npm publishing: how to publish a package, how to manage version control, among others.
  • Learn Test Driven Development.

We believe we achieved all of those goals, especially the one about TDD. We've learned how useful tests can be as a guide to how we want the finished product to work. As can be seen from our 'index.test.js' file, we anticipated there being many different possible inputs for the URL string, as URLs can be written in a variety of ways. For example, a user may either include or exclude the 'http://' protocol in their URL string.

As such we saw this as a good opportunity to practice following the Test Driven Development method for building our package, as we could then be confident that our function was behaving as intended for all of the possible inputs at every step in the development process.

We also took this as an opportunity to practice following Test-Driven Development, and have created a comprehensive test suite using Jest. This approach helped us to ensure that LinkClipper is robust across all the possible test cases (i.e. all possible combinations of links with or without protocols, 'www', domain names and paths).

Usage

Installation

npm i linkclipper

Syntax

clipper(url, start, end)

Parameters

url

The URL string to be shortened.

start

The extent to which to clip the beginning of the URL string. The options are:

  • none: Does not clip the beginning of the URL.

  • shorten: Removes the protocol from the beginning of the URL (e.g. http://, https://, ftp://).

  • remove: Removes the protocol and the 'www' subdomain from the beginning of the URL.

end [Optional]

The extent to which to clip the end of the URL string. Currently the only option is 'shorten'. If omitted, the end of the URL string will not be clipped.

  • shorten: Removes the path from the end of the URL (i.e. everything that comes after '.com' or other domain).

  • remove: Removes the path and the TLDs from the end of the URL (e.g. everything from '.com' onwards).

Return value

A new string containing the clipped URL. The original string is not modified.

Examples

import clipper from 'linkclipper';

const url = 'https://www.stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array';

clipper(url, 'none') // OUTPUT: 'https://www.stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array'

clipper(url, 'shorten') // OUTPUT: 'www.stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array'

clipper(url, 'remove') // OUTPUT: 'stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array'

clipper(url, 'none', 'shorten') // OUTPUT: 'https://www.stackoverflow.com'

clipper(url, 'shorten', 'shorten') // OUTPUT: 'www.stackoverflow.com'

clipper(url, 'remove', 'shorten') // OUTPUT: 'stackoverflow.com'

clipper(url, 'none', 'remove') // OUTPUT: 'https://www.stackoverflow'

clipper(url, 'shorten', 'remove') // OUTPUT: 'www.stackoverflow'

clipper(url, 'remove', 'remove') // OUTPUT: 'stackoverflow'

Testing

Tests for LinkClipper are located in index.test.js. To run the tests use your terminal to execute:

npm run test

Future plans

  • Included in version 2.0

    Include an option for just obtaining the site name (e.g. 'github').

  • KNOWN BUG:

    ❗LinkClipper does not currently account for URLs such as broadway.com where the site name also happens to be a TLD❗

Acknowledgements

Contributors

Back to top