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

msgs-map-creator

v1.2.1

Published

Make messages by plain text.

Downloads

5

Readme

Message Map Creator

Msgs Map Creator

This package is a command line tool that allows you to create messages.

Install

npm install --dev msgs-map-creator
yarn add --dev msgs-map-creator

Usage

You are free to use the follow template or start a command line. Just create a json file in your root project (mmcconfig.json)

File Structure The mmcconfig.json file consists of the following properties:

  • filePaths: An array of objects that specify the input and output paths of your project's files. The objects in this array should have two properties: inputPath and outputPath. The inputPath property specifies the path of the input file and the outputPath property specifies the path of the output file.

  • headerDescription: A string that provides a description for the header in your output file.

  • prettyOutput: A boolean that specifies whether to format the output file in a readable manner or not. If set to true, the output file will be formatted in a readable manner, and if set to false, the output file will not be formatted.

  • hashType: A string that specifies the type of hash to be used in your project. This property can be set to one of the following values: "md5", "sha1", "sha256", "sha512".

  • chosenLanguagePath: The lang path to get the value from the key.

{
  "filePaths": [
    {
      "inputPath": "/tmp/es.json",
      "outputPath": "/tmp/es.ts"
    },
    {
      "inputPath": "/tmp/en-us.json",
      "outputPath": "/tmp/en-us.ts"
    },
    {
      "inputPath": "/tmp/pt-br.json",
      "outputPath": "/tmp/pt-br.ts"
    }
  ],
  "headerDescription": "This file is auto-generated. Do not edit.",
  "prettyOutput": true,
  "hashType": "md5",
  "chosenLanguagePath": "en-us"
}

To use the package, run the following command in the command line:

Execution

npx msgs-map-creator

The package accepts the following options:

  • --keep-conf or -k: Allows you to keep the previous configuration and use it for the current run.
  • npx msgs-map-creator -- -k

Retrieving the value from the original text

import { getValue } from 'msgs-map-creator';
console.log(getValue('original super text'));

The function will return the value according the config file (mmcconfig.json).

Creating Custom Messages

This topic explains the rule for creating customized messages from an original message.

It's only indicated in situations where there are no mapped status returns from some API, it should not be used as in the following example:

API RESPONSE

{
  "message": "Bad request",
  "error_code": 45
}
export enum ErrorCode {
  //...
  44 = 'Foo bar',
  45 = 'Error creating item. Please check the submitted data and try again.',
  46 = 'Foo bar',
  //...
}

In the above case, it is possible to map the returns through the "error_code" key, there is no need to use the resource.

Util Case

The example below is indicated for the case where we only receive a generic return message and we want to customize it.

Response:

{
  "message": "Conflict in registering the purchase. Purchase already registered in the program previously."
}

In this case we can use the message response to create a key from map using a hash and customizing it to return a new message. Like:

It's required a path input/output to handle it.

Input (input.json)

[
  {
    "input": "Conflict in registering the purchase. Purchase already registered in the program previously.",
    "output": "This invoice has already been sent previously."
  }
]

Output (input.ts or .js)

const outPutMessages = {
  '981adff0f66066d65186ae4204f0a830d8942c7c':
    'This invoice has already been sent previously.',
};

You can merge with the current map like:

// i18n file
export { enUs, ...outPutMessages }

I'm working hard to improve the cli, there are a known issues which will be fixed in the next releases, at the moment you can use the template to avoid some errors in the in handle user input paths. But if the paths exist you probably will have success 🚀

Feel free to improve it!