UNPKG

@w.dental/date-mask

Version:

Lib for using as maks for date input

13 lines (12 loc) 818 B
/*! * @w.dental/date-mask v0.0.2 * (c) W-Dental * Released under the MIT License. */ /*! * @w.dental/date-mask v0.0.2 * (c) W-Dental * Released under the MIT License. */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).dateMask=t()}(this,(function(){"use strict";var e=/[a-z]/gi,t=/\D/gi;return function(n){if(void 0===n&&(n=""),"string"!=typeof n||e.test(n))throw new Error("You must to pass a digits as string with pattern DD/MM/YYYY or MM/DD/YYYY");var r=n.replace(t,"");return 3===r.length?r.replace(/(\d{2})/,"$1/"):r.length>3&&r.length<5?r.replace(/(\d{2})(\d+)/,"$1/$2"):r.length>=5&&r.length<=8?r.replace(/(\d{2})(\d{2})(\d+)/,"$1/$2/$3"):r.substring(0,10)}})); //# sourceMappingURL=index.umd.min.js.map