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

cn-links

v1.12.0

Published

This package implements functions to deal with links for agents and Chinese marketplaces

Downloads

486

Readme

User Guide

This package implements functions to deal with links for

  • taobao.com
  • weidian.com
  • tmall.com
  • 1688.com
  • wegobuy.com
  • superbuy.com
  • pandabuy.com
  • cssbuy.com
  • hagobuy.com
  • sugargoo.com

Features include:

  • conversion
  • sanitization
  • checking

This is aimed at developers.

Keywords

The verbs in the function names indicate what kind of function you are dealing with.

  • detect: returns typed string
  • extract: returns a part of an input
  • filter: returns multiple parts of an input
  • generate: generates a new URL
  • is: returns a boolean
  • to: ultimate function that combines all different method to get from the start, no matter what it looks like, to the end result

Choices

I made a few controversial choices.

  • Instead of returning strings, all generate functions return a URL object, which of course can be converted back to a string with the .href property
  • Inputs are either strings or URL objects.

Terminology

  • Agent Link: Link to a shopping agent
  • Marketplace: A shopping platfrom (taobao, weidian, 1688, tmall)
  • Raw Link: We call the link to a marketplace a raw link.
  • Marketplace Link, Proper Link, Sanizited links: aliases for raw links
  • Non-Link Marketplace: These are related marketplaces (such as Yupoo). I try to include them in typing, checks and filters, but the actual link transformation that this package promises does not work for them due to the nature of the link.

Usage / Examples

Version 1.0 has the ambition to implement strong typing. The is-functions do the heavy lifting and can be used to typeguard AgentURLs and RawURLs. So a common design pattern you will see is.

const link = 'https://weidian.com/item.html?itemId=3053526244&vc_cps_track=1459920903_0_0';


if (isRawLink(link)) {
    const rawLink: RawURL = new URL(link);
    // Now you have a strongly typed URL object

    // This would be fine, and you can do everything with this object. Just when you use rawLink.href it will not be sanitized. To avoid this, it's recommended to instead use
    const rawLink = toRaw(link)

    // Possible continuation
    const agent: Agent = 'wegobuy';
    const agentLink = toAgent(rawLink, agent);
}

Roadmap

This is a very early release, that's just an export of functions used in the RepArchive browser addon.

  • v0.1 functional approach
  • v1.0 strong typing
  • v1.0 object oriented approach

Repository name is also subject to change.

Disclaimer:

Links in the test are just used as examples. This is random. It is not a recommendation or promotion of these links.