💎 express-gems
Encapsulated express related libraries for external utilities.
It's named "gems", but it has nothing to do with Ruby programming language, believe me. It is just a programmer trying to name things 🤷
Utility "gems" will keep expanding as I discover new needings with the libraries I am using.
⚙️ Setup
Via npm
You can install package by executing following command:
$ npm i express-gems -s
📦 Provided gems/goodies
✉️ MySQL Gem
.createPool(config, callback)
Creates traditional connection pool with given configs.
However, callback
is called with an err
and pool
object
Example:
const gemMySQL = gemMySQL let options = /* ... */ gemMySQL
.buildWhereTemplate(input, rules)
Helps you to build where templates.
const gemMySQL = gemMySQL let _pseudoReqBody = foo:'Lorem ips' bar:'123.45' baz:'somevariable' unwanted:'malicious' let where params = gemMySQL // "where" will be/// "WHERE foo=? AND bar=CAST(? AS UNSIGNED) AND baz=? AND locale IN ('tr_TR', 'en_GB')"// "params" will be// ['%Lorem ips%', '123.45', 'somevariable']
✉️ Express-validator Gem
.errors(req)
Returns a gathered up, response-ready format of errors within req. MUST BE used after express-validator
middlewares are executed.
const express = const gemValidator = gemValidator let app = appall'/some-endpoint' ... { const errors = gemValidator if errors return resstatus400}
errors
is an object with checked fields in it. Error objects within the arrays are determined by the .withMessage(MSG)
chain within the check rules.
.fillWithMessages(chains, errorTable?)
Traverses given chains
array and fills them with appropriate error messages. (Helps you in cases you do not want to repeat same withMessage(MSG)
statements)
const gemValidator = gemValidatorconst check body = // With built-in standard messagesconst validationRules = gemValidator // With custom message builder tableconst validationRules = gemValidator // CAUTION: Please note that while using builder tableconst validationRules = gemValidator
‼️ Found a bug or have a suggestion?
Feel free to open up an issue to let me know if you;
- Found a bug
- Have a suggestion
- Have a question