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

@grupojaque/model-lang-info

v1.1.2

Published

Basic node module

Downloads

3

Readme

Model Lang Info

This hook is a helper for the local practice of having a secondary model for storing translatable information of certain model (e.g Service and ServiceInfo)

pipeline status coverage report

Setup

Requirements

Modules

Initialization

You need to require it after the sequelize startup, with the models created by Sequelize and its corresponding configuration.
require('index.js')(models, config)

Configuration

Configuration values

The configuration file should have the following format.

| Key | Description | | ---- | ----------- | | languageCodes | An array of the supported languages codes in the project |

Example

  {
    "languageCodes": ["es", "en"]
  }
Additional configurations

You must specify in the model options the name of the secondary model as follows:

  • model.js Specify the name of the secondary model. optionally you can specify the name of the functions to be use for getting formats, if not specified, it will use basicFormat
  ...
  { // model options
    hasLangModel: "ModelInfo",
    formatFunction: "modelFormat", // optional
    infoFormatFunction: "secondaryModelFormat", // optional
  }
  ...

If no option is provided the hook will ignore the model.

Usage

Instance functions

formatWithInfo(isForLanding)

This function will take the format of the instance (it should be already defined) and will add the basic format of each modelinfo populated as an object with the corresponding language code as key.

  • isForLanding: if isForLanding exists instead of adding every populated modelInfo, it assign the format of the first modelInfo (as found in the populated array, it is also recomended to be the only one) into the basic format of the model
createInfoModels(creationData)

This function will create some modelInfos associated to this instace, it will take the language to be associated form the keys of the object.

  • creationData: Object with the creation data of the modelInfos to be created, it must have the objects with the creation data with keys corresponding to the language. Example:
  {
    "es": {
      title: "Título del modelo",
      description: "Descripción del modelo"
    },
    "en": {
      title: "Model title",
      description: "Model description"
    }
  }

updateInfoModels(updateData)

This funtion will update existent modelInfos, the update data will be in the same format of the creation function.

  • updateData: object with the same format of the creation function.

Scope

withInfo(langModelName, languageId)

Is a scope that includes the modelInfo, it's necessary to pass the name of the modelInfo, if languageId is provided it includes only the modelInfo with the matching language.

Contributors

  • Emilio Martínez
  • Jorge Álvarez
  • Susana Hahn