0.2.0 • Published 7 years ago

asin-matcher v0.2.0

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

ASIN Matcher

A set of simple utility methods that help identify Amazon product links and extract useful information from them.

Installation

npm install --save asin-matcher

Usage

const asinMatcher = require('asin-matcher');
const link = "https://www.amazon.ca/dp/B00IBIUZGW";

// isProductLink tells you if a url is an Amazon product link
asinMatcher.isProductLink(link) // true
asinMatcher.isProductLink("http://www.google.com") // false

// match returns an object containing the interesting parts of the url
asinMatcher.match(link) // {market: "ca", asin: "B00IBIUZGW", idType: "ASIN"}

// getMarket returns the market (i.e. the top level domain) of the product link
asinMatcher.getMarket(link) // "ca"

// getAsin returns the ASIN product link for the url
asinMatcher.getAsin(link) // "B00IBIUZGW"

// getIdType returns the type of ID used in the url. Options are ASIN and ISBN
asinMatcher.getIdType(link) // "ASIN"
asinMatcher.getIdType("https://www.amazon.com/dp/0684801221") // "ISBN"

The npm package includes a d.ts type definition file so if you're using TypeScript (version 2) you won't need to import types separetely.

Tests

npm test

Amazon product links

Amazon product links come in all sorts of shapes and sizes. Here's a (non exhaustive) list of examples (not including query strings):

FormExample
domain/title/dp/ISBNhttps://www.amazon.co.uk/Old-Man-Sea-Ernest-Hemingway/dp/0099908409/
domain/title/dp/ASINhttps://www.amazon.co.uk/Old-Man-Sea-Ernest-Hemingway-ebook/dp/B00FU7V8IG/
domain/d/category/title/ASINhttps://www.amazon.co.uk/d/Digital-Music/3-Netsky/B01CV5VI7U/
domain/dp/ASINhttps://www.amazon.ca/dp/B00IBIUZGW
domain/gp/product/ASINhttps://www.amazon.com/gp/product/B00IBIUZGW
domain/gp/product/ISBNhttps://www.amazon.com/gp/product/0099908409

Plenty of different combinations of path sections can optionally go between the domain name and the part of the path that represents the ASIN. Plus the ASIN can either be a standard Amazon product reference (10 alphanumeric characters starting with a 'B') or an ISBN-10 if the product is a book (10 numerical characters).

After the ASIN, there can be the end of the URL, a slash (followed by other path sections) or a query string (starting with ?).

I've tested this library against a reasonable number of product links and I use it frequently in other applications so I hope it's fairly reliable, but if you find an Amazon link that it doesn't behave with, please create an issue so I can look into it.

0.2.0

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago