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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@andrevantunes/andrevds-constraints

v1.6.1

Published

![License](https://img.shields.io/static/v1?label=Licence&message=MIT&color=yellow) ![Coverage](https://img.shields.io/static/v1?label=Coverage&message=100%&color=success) ![Build](https://img.shields.io/static/v1?label=Build&message=Success&color=lemon)

Readme

Constraints | André Antunes Vieira

License Coverage Build Version

Biblioteca para segmentação de públicos a partir de um entrada de objeto chave-valor.

Como usar

Para adicionar o constraints aos projetos, rode o seguinte comando:

yarn add @andrevantunes/andrevds-constraints

Importando a biblioteca e aplicando em um exemplo simples de uso:

import constraints from "@andrevantunes/andrevds-constraints";

const input = { my_key: "my_value" };
const rules = { key: "my_key", value: "my_value", operation: "equal" };

constraints(input, rules); // true

No exemplo acima, o método constraints verifica se o input contém uma chave (my_key) como o valor igual à my_value. Retornando um valor boleano true para o caso de satisfazer todas as regras (rules) ou false para o contrário.

Os seguintes operadores estão disponíveis:

| operation | pode ser combinado? | caso |-|-|- | equal | false | compara os valores do input com a regra (default) value1 === value2 | not | false | compara os valores do input com a regra value1 !== value2 | less | false | compara os valores numéricos do input com a regra number1 < number2 | greater | false | compara os valores numéricos do input com a regra number1 < number2 | contains | false | verifica se o valor do input está contido dentro de uma string ou array | not-contains | false | verifica se o valor do input NÃO está contido dentro de uma string ou array | and | true | compara dois grupos de casos (right e left) | or | true | compara dois grupos de casos (right e left)

As entradas sempre devem ser um object simples com chave-valor, em que os valores podem ser dos tipos:

  • boolean
  • number
  • string
  • undefined
  • null
  • array
const input = {
  first: true,
  secondary: 15,
  third: "third",
  fourth: undefined,
  fifth: null,
};

As regras podem ser simples, como apresentado anteriormente, ou mais complexas ao se usar um operador (or ou and) contendo dois braços (right e left) para as condições. A condição por sua vez, pode ser uma regra simples ou também pode conter uma estrutura de braços como o exemplo abaixo:

const rules = {
  operation: "or",
  left: { key: "first", value: true },
  right: { key: "secondary", value: 15 },
};

Abaixo segue um exemplo mais complexo:

const rules = {
  operation: "and",
  left: { key: "first", value: true },
  right: {
    operation: "or",
    left: { key: "secondary", value: 15 },
    right: { key: "third", value: "third" },
  },
};

Utilizando operadores simples:

import constraints from "@andrevantunes/andrevds-constraints";

const input = { my_key: "my_value" };
const rules = { operation: "not", key: "my_key", value: "another_value_value" };

constraints(input, rules); // true

Como publicar

Esse projeto utiliza o conventional commits como padrão de escrita de commits. Com base nessas regras, sempre que um PR é mesclado no branch main, uma nova versão do pacote é publicada no npm.

Como testar

Para rodar os testes basta executar o seguinte comando:

$ yarn test

// or

$ yarn test:watch