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

@herbsjs/suma2text

v1.1.4

Published

A tool to translate suma error codes to natural language.

Downloads

361

Readme

CI build codecov

suma2text

suma2text it's a tool to parse error codes to string, you can use in all your solution.

Suma and suma2text native, you can translate all suma error codes, one by one or all entity error array.

Installing

    $ npm install @herbsjs/suma2text

Using

If your use is simple, you can just require suma2text, and execute this configure function, by default the language will be English from the united states (ISO CODE en-US).

const suma2text = require('@herbsjs/suma2text')()

const suma2text.toText({ notDefined: true })
/*
    Not defined
*/

You also can add a different language or customize the existing, just pass the following parameters on require function.

const suma2text = require('@herbsjs/suma2text')({
    useDefault: 'ts-ME',
    languages: [{
            name: 'ts-ME',
            definitions: {
                types: [
                    { key: 'Number',  translation: 'Numeric' },
                    { key: 'String',  translation: 'Characters'}
                ]
                codes: [
                    { key: 'cantBeEmpty', translation: 'Wont should be empty' },
                    { key: 'wrongType', translation: 'Please the value correct is {0}' }
                ]
            }
        },
        {
            name: 'en-US',
            definitions: {
                types: [
                    { key: 'Number', translation: 'Digit' },
                    { key: 'String', translation: 'Char Array' }
                ],
                codes: [
                    { key: 'cantBeEmpty', translation: 'Wont should be empty' },
                    { key: 'wrongType', translation: 'The value correct is {0}'}
                ]
            }
        }
    ]
})

//fully custumized language
const suma2text.toText({ wrongType: String }, 'ts-ME')
/*
   Please the value correct is Characters
*/
const suma2text.toText({ notGreaterThan: 10 }, 'ts-ME')
/*
   Will be thrown a not implemented code exception
*/

//existing language, but some custumization
const suma2text.toText({ wrongType: String }, 'en-US')
/*
   The value correct is Char Array
*/
const suma2text.toText({ notGreaterThan: 10 }, 'en-US')
/*
   Not greater than 10
*/

But, the perfect choice is to use with herbs.js, all suma codes are integrated into here, and we made for it, you can pass all your validation in a suma2text class, validate, and just show the results in your presentation layer, let's see how.

const User =
    entity('User', {
        name: field(String),
        plan: field(Plan)
    })

const user = new User()
user.name = 42
user.plan.monthlyCost = true
user.validate()
user.errors // { name: [ {wrongType: 'String'} ], plan: { monthlyCost: [ {wrongType: 'Number'}  } }

const suma2text = require('@herbsjs/suma2text')()

const englishUserErrors = suma2text.errorsToText(user.errors)
/*
    {
        name: ['Wrong type, the correct type is String']
        plan: {
            monthlyCost: ['Wrong type, the correct type is Plan']
        }
    }
*/
const portugueseUserErrors = suma2text.errorsToText(user.errors, 'pt-BR')
/*
    {
        name: ['Tipo incorreto, o valor esperado era Texto']
        plan: {
            monthlyCost: ['Tipo incorreto, o valor esperado era Plan']
        }
    }
*/

TODO

Language localisation:

  • [ ] Arabic
  • [ ] Bangla
  • [ ] Chinese
  • [ ] Dutch
  • [x] English ('en-US')
  • [ ] French
  • [ ] German
  • [ ] Italian
  • [ ] Korean
  • [X] Portuguese ('pt-BR')
  • [X] Spanish
  • [ ] Swedish
  • [ ] Tamil

Text Formatting:

  • [X] Primitive types
  • [X] Strings types
  • [X] Number types
  • [ ] Date Type and formating style
  • [ ] User Class instances types

Contribute

Come with us to make an awesome suma2text.

Now, if you do not have the technical knowledge and also have intended to help us, do not feel shy, click here to open an issue and collaborate their ideas, the contribution may be a criticism or a compliment (why not?)

If you would like to help contribute to this repository, please see CONTRIBUTING

The Herb

suma2text suma2text has been used historically to relieve congestion from upper respiratory infections and colds and for wound healing. It is very popular for treating varicose veins and memory loss.

https://www.herbslist.net/

https://en.wikipedia.org/wiki/Centella_asiatica

License

suma2text is released under the MIT license