Socket
Socket
Sign inDemoInstall

blacklight-querystring

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blacklight-querystring

parse/stringify Blacklight search querystrings


Version published
Maintainers
1
Created
Source

blacklight-querystring

Build Status NPM Version

Parse/stringify Blacklight query strings to/from normalized search objects. Uses qs under the hood.

npm install blacklight-querystring

usage

var blqs = require('blacklight-querystring')

blqs.parse(queryString)

Parses a query string generated by Blacklight into an object with query, facets, and options keys. Values are uri-decoded and numeric-ish strings are parsed into numbers.

query is the search query used against Blacklight. The value is url-decoded. (default: '')

var parsed = blqs.parse('q=cats+AND+dogs')
console.log(parsed.query)

// {
//   query: 'cats AND dogs',
// }

facets contains facet values found in the query string with the key wrapped in f[ and ][]. (default: {})

var parsed = blqs.parse('f%5Bformat_physical%5D%5B%5D=Videocassette+(VHS)')
console.log(parsed.facets)

// {
//   facets: {
//     format_physical: [
//       'Videocassette (VHS)'
//     ]
//   }
// }

options contains values that are neither the query or facets. Keys/values using object notation are parsed into objects. (default: {})

var parsed = blqs.parse('per_page=25&range%5Bpub_date%5D%5Bstart%5D=1991')
console.log(parsed.options)

// {
//   per_page: 25,
//   range: {
//     pub_date: {
//       begin: 1990
//     }
//   }
// }

blqs.stringify(obj)

Converts an object with keys query, facets, and options into a query string recognized by Blacklight. A query key is converted to the key k in the query string, and facets to f.

var obj = {
  query: 'cats AND dogs',
  facets: {
    format_physical: [
      'Videocassette (VHS)'
    ],
  },
  options: {
    per_page: 25,
    range: {
      pub_date: {
        begin: 1990
      }
    }
  }
}

console.log(blqs.stringify(queryObj))

// 'q=cats+AND+dogs&f%5Bformat_physical%5D%5B%5D=Videocassette+%28VHS%29&per_page=25&range%5Bpub_date%5D%5Bbegin%5D=1990'

license

GPL-3.0

FAQs

Package last updated on 20 Oct 2016

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