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

@feedmepos/custom-attributes

v0.0.1-rc.4

Published

## Package Features

Downloads

147

Readme

@feedmepos/custom-attributes

Package Features

The @feedmepos/custom-attributes package provides a set of tools to manage and filter custom attributes for entities such as restaurants. The main features include:

  1. Filter Builder: FmCustomAttributeFilter A vue component that enables users to build complex filter queries based on custom attributes.
  2. Rule Validation Function: validateRule A function that evaluates MongoDB-style queries against custom attribute data to determine if they match the specified rules.

Rule Validation Function

The mongoQuery function is used to evaluate a set of rules against custom attribute data. It takes two parameters: the data to be evaluated and the rule to be applied. The function returns a boolean indicating whether the data matches the rule.

Development

pnpm install
pnpm dev

Release Package

Typescript Package

  • Create a new release and tag on GitHub (custom-attributes-v* Eg. custom-attributes-v0.0.0-alpha)
  • The package will be published to npm and github registry by @feedmepos/custom-attributes-action

Dart Package

  • Create a new release and tag on GitHub (custom_attributes_dart@semantic-version eg. [email protected])

Add to existing project

Install packages

pnpm install @feedmepos/custom-attributes

Add style.css to your App.vue

import '@feedmepos/custom-attributes/style.css';

How to use the components

import { FmCustomAttributeFilter } from '@feedmepos/custom-attributes';

<FmCustomAttributeFilter
  :attributes="[
    { key: 'name', type: 'string', entity: 'restaurant' },
    { key: 'region', type: 'string', entity: 'restaurant' },
    { key: 'staffCount', type: 'number', entity: 'restaurant' },
    { key: 'memberCount', type: 'number', entity: 'restaurant' },
  ]"
  :model-value="filter"
  @update:model-value="(v) => (filter = v)"
/>

Filter Data

/**
 * filter = { "logic": "AND", "rules": [ { "logic": "AND", "rules": [ { "property": "name", "operator": "$eq", "value": "123" } ] }, { "logic": "AND", "rules": [ { "property": "region", "operator": "$eq", "value": "123" } ] }, { "logic": "AND", "rules": [ { "property": "name", "operator": "$eq", "value": "123123" }, { "property": "staffCount", "operator": "$eq", "value": 123 } ] } ] }
 *
 * values: FdoCustomAttribute = {
 *   name: '123',
 *   region: '123',
 *   staffCount: 123,
 *   memberCount: 123123
 * }
 */
const testResult = validateRule(values, filter);

const result = restaurants.filter((r) => validateRule(r.customAttribute, filter));

Screenshot

Multiple group

alt text

One group filter

alt text


Type-Safe MongoQuery

This package provides utilities to convert between FDO rules and MongoDB queries, and to validate data against MongoDB-style queries.

Operators

The following MongoDB operators are supported:

  • $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $regex
  • $between (for FDO compatibility, mapped to $gte and $lte)

Supported Operators by Type

String fields Supported: $eq, $ne, $in,$nin, $regex, $gt, $gte, $lt, $lte

Number fields Supported: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin

Boolean fields Supported: $eq, $ne, $in, $nin

Date fields Supported: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin

Array fields Supported:$in, $nin


Usage

1. FdoRuleToMongoQueryBuilder

Converts an FDO rule object to a MongoDB query object.

import { FdoRuleToMongoQueryBuilder } from 'feedmepos/custom-attributes';

const fdoRule = {
  property: 'age',
  operator: '$gt',
  value: 18,
  type: 'number'
};

const mongoQuery = FdoRuleToMongoQueryBuilder.build(fdoRule);
// mongoQuery: { age: { $gt: 18 } }

2. MongoQueryBuilderToFdoRule

Converts a MongoDB query object back to an FDO rule object.

import { MongoQueryBuilderToFdoRule } from '@feedmepos/custom-attributes';

const mongoQuery = { age: { $gt: 18 } };
const fdoRule = MongoQueryBuilderToFdoRule.build(mongoQuery);
// fdoRule: { property: 'age', operator: '$gt', value: 18, type: 'number'}

3. validateMongoQuery

Validates a data object against a MongoDB-style query.

import { validateMongoQuery, MongoQuery } from 'feedmepos/custom-attributes';

const user: User = {
  name: 'John',
  age: 25,
  active: true,
  tags: ['user', 'admin'],
  createdAt: new Date('2024-01-01'),
  profile: { email: '[email protected]', score: 85 }
};

const query: MongoQuery<User> = {
  age: { $gt: 18 },
  active: { $eq: true },
  tags: { $in: ['admin'] },
  profile: { score: { $gte: 80 } }
};

const isValid = validateMongoQuery(user, query); // true

Example Usage of Type-Safe MongoQuery

import { MongoQuery, validateMongoQuery } from '@feedmepos/custom-attributes';

interface Profile {
  email: string;
  score: number;
}
interface User {
  name: string;
  age: number;
  active: boolean;
  tags: string[];
  createdAt: string | Date;
  profile: Profile;
}

const query: MongoQuery<User> = {
  name: { $eq: 'Alice' },
  age: { $gte: 18 },
  profile: { score: { $gt: 80 } },
  tags: { $in: ['admin'] },
  createdAt: { $gte: '2024-01-01' }
};

validateMongoQuery(user, query);

// OR

validateMongoQuery(user, {
  name: { $eq: 'Alice' },
  age: { $gte: 18 },
  profile: { score: { $gt: 80 } },
  tags: { $in: ['admin'] },
  createdAt: { $gte: '2024-01-01' }
});

TypeScript will show errors for:

  • Invalid keys (e.g., 'profile.score' instead of profile: { score: ... })
  • Invalid operators (e.g., { age: { $regex: 'foo' } })
  • Wrong value types (e.g., { age: { $eq: 'Alice' } })
// example of invalid query
const invalidQuery: MongoQuery<User> = {
  name: { $eq: 123, $regex: 456 }, // $eq expects string, $regex expects string
  age: { $regex: 'foo', $gt: 'twenty' }, // $regex not allowed for number, $gt expects number
  active: { $gte: true }, // $gte not allowed for boolean
  tags: { $eq: 'admin', $nin: 'user' }, // $eq not allowed for array, $nin expects string[]
  createdAt: { $regex: 2024, $gt: false }, // $regex expects string, $gt expects string or Date
  profile: {
    score: { $regex: 'foo' }, // $regex not allowed for number
    notAProfileField: { $eq: 1 } // 'notAProfileField' does not exist in Profile
  },
  notAUserField: { $eq: 1 }, // 'notAUserField' does not exist in User
  $and: [
    { name: { $eq: 'Alice' } },
    { 'profile.email': { $eq: '[email protected]' } } // dot notation not allowed
  ]
};

Notes

  • Always use object notation for nested fields (not dot notation).
  • Annotate your query as MongoQuery<YourType>for best type safety.
  • If you use inline objects, use the generic on validateMongoQuery to enforce type checking.