0.1.9 • Published 2 years ago

facebook-url v0.1.9

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

facebook-url

Parse, sanitize and craft any Facebook URL

Getting started

npm i facebook-url -D

yarn add facebook-url -D

Usage

const { parse, craft } = require('facebook-url');

const url = 'https://www.facebook.com/EcoFriendlyMaidService/services/?service_id=1368411153266622'
const link = parse(url, { lazy: false }); // lazy=false by default;
// > link as 2 may accessors: { matches, data }

console.log(link.matches.aPage)
// > true

console.log(link.matches)
/* > {
  aPage: true,
  aPageServices: true,
  aUrl: true,
  aFacebookDomain: true,
  aPagePosts: false,
  aPageGroups: false,
  aPageJobs: false,
  aPageEvents: false,

  {...}
}
*/


console.log(link.data)
/* > {
  matched: true,
  url: URL {
    href: 'https://www.facebook.com/EcoFriendlyMaidService/services/?service_id=1368411153266622',
    origin: 'https://www.facebook.com',
    protocol: 'https:',
    username: '',
    password: '',
    host: 'www.facebook.com',
    hostname: 'www.facebook.com',
    port: '',
    pathname: '/EcoFriendlyMaidService/services/',
    search: '?service_id=1368411153266622',
    searchParams: URLSearchParams { 'service_id' => '1368411153266622' },
    hash: ''
  },
  domain: {
    name: 'www',
    hostname: 'www.facebook.com',
    interestingToQuery: true,
    queryPriority: 0
  },
  language: { code: 'en', name: 'English', native: 'English' },
  user: {
    identifier: 'EcoFriendlyMaidService',
    id: undefined,
    slug: 'EcoFriendlyMaidService'
  },
  page: {
    identifier: 'EcoFriendlyMaidService',
    id: undefined,
    slug: 'EcoFriendlyMaidService'
  },
  service: {
    identifier: '1368411153266622',
    id: '1368411153266622',
    slug: undefined
  }
}
*/

console.log(craft(link).aPage())
// > https://www.facebook.com/EcoFriendlyMaidService

console.log(craft(link).aPageAbout())
// > https://www.facebook.com/EcoFriendlyMaidService/about

console.log(craft(link).aPage({ page: '136820153266622'}))
// > https://www.facebook.com/136820153266622

Running the build

All the different build steps are orchestrated via npm scripts. Npm scripts basically allow us to call (and chain) terminal commands via npm.

Npm ScriptDescription
testRun tests using jest and 300 samples
test-minRun tests using jest and 10 samples
test-allRun tests using jest and all sample

Eslint rules

Eslint is a code linter that helps catch minor code quality and style issues. All rules are configured through .eslintrc.

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago