npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hublo/query

v1.1.0

Published

## generateSearch

Downloads

77

Readme

Important to do when using

generateSearch

You must provide a generated search function by using the setGenerateSearch method of the package. It must always have a default similar to the following. For your custom generation you can do as many things as you want.

function generateSearch(query: any, key: any): string {
  switch (key) {
    case 'jobProfiles':
      return (
        'jobprofiles:' +
        query[key]
          .map((e: any): string =>
            e.job !== -1
              ? e.specialtys.length > 0
                ? e.specialtys
                    .map((spec: any): string =>
                      e.institutions && e.institutions.length > 0
                        ? e.institutions.map((i: any): string =>
                            ('' + e.job).concat(
                              spec !== -1
                                ? 's' + spec + (i !== -1 ? 's' + i : '')
                                : i !== -1
                                ? 'ss' + i
                                : '',
                            ),
                          )
                        : ('' + e.job).concat(spec !== -1 ? 's' + spec : ''),
                    )
                    .join(',')
                : e.institutions && e.institutions.length > 0
                ? e.institutions.map((i: any): string =>
                    ('' + e.job).concat(i !== -1 ? 'ss' + i : ''),
                  )
                : ''
              : '',
          )
          .filter((e: any): boolean => e !== '')
          .join(',')
      )
    default:
      return '' + key + ':' + query[key]
  }
}

formatterslist

you can extend the formatters list with the extendFormatterslist method of the package. here's a quick example

// value will be the value of the variable isRadhiAGoodGuy in this example
// values are always string.
function booleanParser(value: string) {
  return value === 'true'
}
const formatterslist = {
  isRadhiAGoodGuy: booleanParser,
}
// Will do an object assign to add the new values you're using on top of the other parsers already defined in the package (check below for more)
extendFormatterslist(formatterslist)

List of formatters present in the module

let formatterslist = {
  statut: splitStringAndParseInt,
  job: splitStringAndParseInt,
  jobProfilesPending: jobProfileParser2,
  jobsSpecialtiesPending: jobProfileParser2,
  specialty: splitStringAndParseInt,
  institution: splitStringAndParseInt,
  admin: splitStringAndParseInt,
  missionmotifcreationcategory: splitStringAndParseInt,
  originInstitution: splitStringAndParseInt,
  mission: splitStringAndParseInt,
  id: splitStringAndParseInt,
  worker: splitStringAndParseInt,
  beginAt: unixRangeParser,
  endAt: operatorNumberParser,
  createdAt: operatorNumberParser,
  jobprofiles: jobProfileParser,
  searchname: searchNameParser,
  populate: splitString,
  isDeletedFromNetwork: booleanParser,
  isDeletedFromNetworkByInstitutions: isDeletedFromNetworkParser,
  isCanceled: booleanParser,
  isFullTime: booleanParser,
  isExpress: booleanParser,
  isLongMission: booleanParser,
  isPastMission: booleanParser,
  isPlanning: booleanParser,
  isValidated: booleanParser,
  isFilled: booleanParser,
  isNight: idBooleanParser,
  isDay: idBooleanParser,
  isDayRefused: idBooleanParser,
  isNightRefused: idBooleanParser,
  isSignedPerAdmin: booleanParser,
  isSignedPerWorker: booleanParser,
  isBlockedByAdmin: institutionServiceBooleanParser,
  isRefusedByWorker: institutionServiceBooleanParser,
  isWorkerNotified: idBooleanParser,
  isAllowedDay: idBooleanParser,
  isAllowedNight: idBooleanParser,
  isAllowedService: institutionServiceBooleanParser,
  service: splitStringAndParseInt,
  range: rangeParser,
  rangeBeginAt: rangeParser,
  nbPotentialWorkers: operatorNumberParser,
  isAccepted: booleanParser,
  isRefused: booleanParser,
  acceptedBy: splitStringAndParseInt,
  createdBy: splitStringAndParseInt,
  idInInstitution: splitString,
  isViaEmailCSVOption: booleanParser,
  isPoleCSVOption: booleanParser,
  isRecupCSVOption: booleanParser,
  isTwoLinesForMissionOnTwoDaysCSVOption: booleanParser,
  idInfoOnWorkersCSVOption: splitStringAndParseInt,
  inCluster: splitStringAndParseInt,
  didWorkerSignUp: booleanParser,
  contract: splitStringAndParseInt,
  isCancelled: booleanParser,
  isFused: booleanParser,
  isSigned: booleanParser,
  isCancelledOrFused: booleanParser,
  isSignedOrNew: booleanParser,
  isDayMission: booleanParser,
  isPublicHoliday: booleanParser,
  isSunday: booleanParser,
}

For more information please check the source code to see how parsers work

Luxury

There's also an express middleware to put the req.query request parameters in req.parameters after parse with your configuration.

Version @hublo/query

1.1.0

  • Add jobsSpecialties to paramParser

1.0.0

  • migrated from npm-hublo-query to @hublo/query

Version

4.0.0

  • Full cleanup (pnpm, formatting, packages, etc)

3.1.1

  • Add options to skip group by clause

3.1.0

  • Add jobsSpecialtiesPending to paramParser

2.1.1

  • Escape single quotes in search input in queries

2.0.0

  • Use "like" instead of "similar to". "Similar to" doesn't support comparing all characters.
  • Fix where clause, string was truncated

1.0.0-beta.10

  • Add isDayMission, isPublicHoliday, isSunday

1.0.0-beta.5

  • Add package pg to dependencies
  • Add package pg-native to dependencies

1.0.0-beta.3

  • Add package pg-native

1.0.0-beta.1

  • change paramParser for idInInstitution: expecting string instead of integer

1.0.0-beta.0

  • new name the package changes its name to npm-hublo-query