spies-url-parser

1.0.5 • Public • Published

spies url parser

Codeship codecov Dependency Status devDependency Status

Why?

Urls on Spies.dk contain the query parameters of the options people selected when they performed their holiday search.

What?

When a search is performed on Spies.dk the options selected are stored as query parameters in the url.

Things we need to extract from the URL params

  • Departure Airport
  • Destination
  • Duration of Holiday
  • Departure date
  • Adults
  • Children

How?

Usage

Install from npm

npm install spies-url-parser --save

In Your React (or Browserified) Code

var spies_url_parser = require('spies-url-parser');
var parsed = spies_url_parser(url); // e.g: document.referrer (if user came from Spies)
console.log(parsed); // see below for sample output

#### In Browser JS (without browserify/webpack)

<script src="https://cdn.rawgit.com/numo-labs/spies-url-parser/master/index.js"></script>
<script>
var parsed = spies_url_parser(document.referrer); // e.g: document.referrer
console.log(parsed); // see below for sample output
</script>

Example 1 - Destination: Anywhere

When a user selects the following options:

  • From: København
  • Where: Anywhere (destination)
  • How long: 1 week
  • Departure date: 01-07-2016
  • Adults: 2
  • Children: 2

The url is:

http://www.spies.dk/bestil-pakkerejse?QueryDepID=12678
&QueryCtryID=-1&QueryAreaID=0&QueryResID=-1
&QueryDepDate=20160701&QueryDur=8&CategoryId=2
&QueryRoomAges=|42,42,9,10&QueryUnits=1

Which we parse as:

{
  "departure_airport": "København - CPH",
  "pax_mix": {
    "passengers": [
      "1974-4-11",
      "1974-4-11",
      "2007-4-11",
      "2006-4-11"
    ],
    "adults": 2,
    "children": 2
  },
  "duration_weeks": 1,
  "departure_date": "2016-07-01"
}

Example 2 - Destination Selected: Spain > Canary Islands

For the following: query in the Spies UI:

spies-going-to-canaria

the URL is: http://www.spies.dk/bestil-pakkerejse?QueryDepID=12676&QueryCtryID=4826&QueryAreaID=8775&QueryResID=0&QueryDepDate=20160921&QueryDur=8&CategoryId=2&QueryRoomAges=|42,42,7,3&QueryUnits=1

and parsed parameters are:

{
  "departure_airport": "Billund - BLL",
  "pax_mix": {
    "passengers": [
      "1974-4-11",
      "1974-4-11",
      "2009-4-11",
      "2013-4-11"
    ],
    "adults": 2,
    "children": 2
  },
  "duration_days": "8",
  "departure_date": "2016-09-21",
  "destination": "4826,8775"
}

Readme

Keywords

none

Package Sidebar

Install

npm i spies-url-parser

Weekly Downloads

1

Version

1.0.5

License

ISC

Last publish

Collaborators

  • nelsonic