TritonDataCenter / node-assert-plus

Extra assertions on top of node's assert module
MIT License
122 stars 25 forks source link

Allow the configuration of error messages #27

Open bruno-brant opened 8 years ago

bruno-brant commented 8 years ago

Assertion messages are composed automatically from the name of the field. They aren't localized, for instance. Allowing users to configure the message would be nice to support other languages and/or custom messages.

bruno-brant commented 8 years ago

I have a few ideas concerning how to do it:

Directly on the API

let assert = require("assert-plus");
assert.object(foo, "foo", "%s can't be null");
// or
assert.object(foo, "foo", "%s deve ser preenchido"); // in pt-BR

Globally

let assert = require("assert-plus");
assert.messageTemplate = "%s can't be null";

Locale sensitive

let assert = require("assert-plus");
assert.locale = "pt-BR";
assert.messageTemplate = { "pt-BR": "%s é requerido" };

If someone can provide me with some feedback on the methods, maybe I can slap together a PR during this week.