Sha256: d3fc172a8cd00a750aa64e98923ce88579ee033273bb6605d9efc97d1df29e70
Contents?: true
Size: 991 Bytes
Versions: 1
Compression:
Stored size: 991 Bytes
Contents
import { Env, I18n, Validators } from "loco-js"; class Vulgarity extends Validators.Base { static identity = "Vulgarity"; constructor() { super(); } validate() { if (this.val == null) return; switch (typeof this.val) { case "string": { const vulgarWord = this._getVulgarWord(); const match = new RegExp(`${vulgarWord}`, ["i"]).exec(this.val); if (match) this._addErrorMessage(); else return; break; } default: throw new TypeError( `Vulgarity validator is applicable only for strings and ${ this.attr } isn't.` ); } } _addErrorMessage() { const message = I18n[Env.loco.getLocale()].errors.messages.vulgarity; this.obj.addErrorMessage(message, { for: this.attr }); } _getVulgarWord() { switch (Env.loco.getLocale()) { case "pl": return "kurwa"; case "en": return "fuck"; } } } export default Vulgarity;
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
loco-rails-3.0.4 | test/dummy/frontend/js/validators/Vulgarity.js |