Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aller/labrador-utils

Package Overview
Dependencies
Maintainers
10
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aller/labrador-utils

Labrador utils

  • 0.0.23
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
10
Weekly downloads
 
Created
Source

Labrador Utilities

Greenkeeper badge wercker status Coverage Status

Install

yarn add @aller/labrador-utils

or

npm install @aller/labrador-utils

Modules

Labrador API

Init
const { api } = require('labrador-utils')
const labApi = api({ base: 'http://api.secret.labrador.api.lol', site_id: 1 })
High-level methods
labApi.getArticleById({ id: 9999999, args... }) // {Article}
labApi.getArticlesByTags({ tags:['test', 'bil'], args... }) // [{Article}...]
labApi.getArticlesByTag({ tag: 'test', args... }) // [{Article}...]
labApi.getArticlesBySection({ section: 'mat', args... }) // [{Article}...]
labApi.getFrontPageById({ id: 9999999, args... }) // { FrontPage }
labApi.getFragment({ id: 9999999, args... }, ?clean) // Returns HTML string. If clean is provided, the resulting HTML is parsed throuhg parse5 to ensure valid markup.

Article-based high level methods also have query-specific options e.g:

labApi.getArticleById({
  isFeatured: true,
  visibility_status: 'P'
})
Base methods
labApi.getQuery('/front', { query: 'id:999999', args... }).get() // { result: [{ FrontPage }...] }
labApi.getFrontPage({ query: 'id:9999999', args... }).getResult() // [{ FrontPage }...]
labApi.getArticles({ query: 'tag:test', args... }).getFrist() //  { Article }

All base methods have 3 request methods

get() -> { result: [ { ENTITY }...] }
getResult() -> [ {ENTITY }... ]
getFirst() -> { ENTITY }
Query builder

The base methods use the queryBuilder for parsing of the query-parameter. The queryBuilder takes nested JS objects/arrays as input and generates a query string as output.

labApi.getArticles({
    query: [{ tag: ['nyheter', 'bil'] }, { 'review_score': '*' }], 
}).getResult()
// query: (tag:(nyheter AND bil) AND review_score:*)

// The underlying queryBuilder method can also be directly accessed:
labApi.queryBuilder([{ tags: ['hello', { wat: ['test1', ['hello', 'hello2'], 'OR'] }] }])
// returns the string: '(tags:(hello AND wat:(test1 OR (hello AND hello2))))'

Concepts:

['nyheter', 'bil'] // -> (nyheter AND bil)
['nyheter', 'bil', 'OR'] // -> (nyheter OR bil), the 'OR' keyword needs to be the last el. of the array.
{ tag: ['nyheter', 'bil', 'OR']} // -> (tag:(nyheter OR bil))
// And any nested combination of these three concepts

Additional arguments

All additional args. on all methods, are sent as query params, e.g:

labApi.getArticlesByTags({ 
  tags: ['test', 'bil'], 
  limit: 5, 
  start: 5, 
  order: 'desc', 
  orderBy: 'published'
})

Defaults are found here

FAQs

Package last updated on 15 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc