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

@digital-generation/gen-characteristics

v1.1.2

Published

This library helps people to add characteristics to objects and describe those objects based on their characteristics and the inherited characteristics.

Downloads

24

Readme

gen-characteristics-repository

This project is an API that helps people to add characteristics to objects and describe those objects based on their characteristics and the inherited characteristics.

Use Case

Let's explain it with an example: Imagine you are a food-lover that share your insights about places/food and everything related.

So you describe the food with some attributes such as:

| Attribute | Allowed Values | | --- | --- | | isSpicy | true/false | | stars | 1,2,3,4,5 | | isHealthy | true/false | | cost | cheap. medium, expensive. |

Because some of this attributes/characteristics are shared by the food places you make a hierachy that describes the groups and also the food to save time. So you create a hierachy like this: | Scope | Allowed Values | | --- | --- | | Zone | Fancy Zone, Gym restaurant, Fastfood Foodcourt, Foodtruck, street places.| | Kind of food | Mexican food, Vietnamese food, Fast Food.| | Place | All the places you can imagine|

So each time you want to describe a new food discovery you atached the characterics that are already setted for the Zone, and kind of food that you assign.

Let's say that you discover one of the most incredible "taquerías" in Mexico City. The taquería is called Orinoco (this is really serious even when it's an example) so let's describe it:

| Scope | ScopeInstance | Characteristic | Value | | --- | --- | --- | --- | | Zone | Fancy Zone | cost | expensive | | Kind of food | Mexican food | isHealthy | true | | Kind of food | Mexican food | isSpicy | true | | Place | Taquería Orinoco | stars | 5 | | Place | Taquería Orinoco | isHealthy | false | | Place | Taquería Orinoco | cost | medium |

Know that we know the characteristics of the Place, Kind of food and Zone what's the next step?

Well basically here's the problem.

If we ask for the isHealthy characteristic for: Taquería Orinoco that is a Kind of food: Mexican food, and that is located in a Fancy Zone. What should be the isHealthy value if the Taqueria Orinoco isHealthy characteristic is false but the MexicanFood isHealthy characteristic is true? It's confusing right?

We can use priorities to give high importance to some scope characterics. So let's say that we prioritize in the following way: Place, Kind of food, Zone.

Now we know that the whole characteristics that describe Taquería Orinoco that is a Kind of food: Mexican food, and that is located in a Fancy Zone are:

  • stars: 5,
  • isHealthy: false
  • cost: medium
  • ~~cost: expensive~~ * This characteristic is overrided because Place cost has higher priority
  • ~~isHealthy: true~~ * This characteristic is overrided because Place isHealthy has higher priority
  • isSpicy: true * This is inherited from Mexican Food

This API can help you to manage this kind of use cases.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

Setting database

Let's start with installing all the project dependencies

$ npm install

Run this command with your own parameters

node_modules/.bin/sequelize db:migrate --url [YOUR CONNECTION STRING]

Process Environment variables

You will need to set this variables before running this project:

| Variable Name | Description | |---|---| | DB_USER | User to get acccess to your database. | | DB_PASS | Password to get access to your database. | | DB_NAME | Name of the schema that contains all the model | | DB_ENDPOINT_URL | Endpoint of the mysql server | | NODE_ENV | Use "development" for local purpose | | DB_PORT | Port of the mysql server | | API_PORT | Port where you want to raise this API |

Installing

To include this library into your project use npm

npm install --save gen-characteristics

Usage

const genCharacteristics = require('./src/index');

const example = async () => {
  await genCharacteristics.setDatabaseConfig(process.env.DB_USER,
    process.env.DB_PASS,
    process.env.DB_DATABASE,
    {
      host: process.env.DB_HOST,
      dialect: 'mysql',
      logging: false,
    });

  console.log('setCharacteristicObject', await genCharacteristics.setCharacteristicForObject([
    {
      scope: 'Country',
      characteristic: 'requiredStage',
      referenceId: 'sg',
      value: 'true',
    }]));
  console.log('getCharacteristicForObject', await genCharacteristics.getCharacteristicForObject(
    {
      Country: ['sg'],
      Stage: ['2', '3', '4', '11', '12'],
    },
    ['requiredStage'],
  ));
};

example();