iso-datestring-validator
Advanced tools
Comparing version 2.0.5 to 2.1.0
@@ -0,0 +0,0 @@ export * from './is-valid-date/is-valid-date.function'; |
@@ -1,1 +0,1 @@ | ||
module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var u=t[r]={i:r,l:!1,exports:{}};return e[r].call(u.exports,u,u.exports,n),u.l=!0,u.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var u in e)n.d(r,u,function(t){return e[t]}.bind(null,u));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(e,t){return void 0===t&&(t="-"),new RegExp("^(?!0{4}"+t+"0{2}"+t+"0{2})((?=[0-9]{4}"+t+"(((0[^2])|1[0-2])|02(?="+t+"(([0-1][0-9])|2[0-8])))"+t+"[0-9]{2})|(?=((([13579][26])|([2468][048])|(0[48]))0{2})|([0-9]{2}((((0|[2468])[48])|[2468][048])|([13579][26])))"+t+"02"+t+"29))([0-9]{4})"+t+"(?!((0[469])|11)"+t+"31)((0[1,3-9]|1[0-2])|(02(?!"+t+"3)))"+t+"([0-2][0-9]|3[0-1])$").test(e)}function u(e,t){return void 0===t&&(t=":"),new RegExp("^([0-1]|2(?=([0-3])|4"+t+"00))[0-9]"+t+"[0-5][0-9]("+t+"([0-5]|6(?=0))[0-9])?(.[0-9]{1,9})?$").test(e)}function i(e){var t=function(e){var t=/\D/.exec(e);return t?t[0]:""},n=e.split("T"),i=n[0],o=n[1],c=r(i,t(i));if(o.includes("Z")){var f=o.replace("Z","");return c&&u(f,t(f))}var l=!!o.includes("+"),a=o.split(/[+-]/),d=a[0],s=a[1];return c&&u(d,t(d))&&function(e,t,n){return void 0===n&&(n=":"),new RegExp(t?"^(0(?!(2"+n+"4)|0"+n+"3)|1(?=([0-1]|2(?="+n+"[04])|[34](?="+n+"0))))([03469](?="+n+"[03])|[17](?="+n+"0)|2(?="+n+"[04])|5(?="+n+"[034])|8(?="+n+"[04]))"+n+"([03](?=0)|4(?=5))[05]$":"^(0(?=[^0])|1(?=[0-2]))([39](?="+n+"[03])|[0-24-8](?="+n+"00))"+n+"[03]0$").test(e)}(s,l,t(s))}function o(e,t){return void 0===t&&(t="-"),new RegExp("^[0-9]{4}"+t+"(0(?=[^0])|1(?=[0-2]))[0-9]$").test(e)}n.r(t),n.d(t,"isValidDate",(function(){return r})),n.d(t,"isValidISODateString",(function(){return i})),n.d(t,"isValidTime",(function(){return u})),n.d(t,"isValidYearMonth",(function(){return o}))}]); | ||
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var u=t[n]={i:n,l:!1,exports:{}};return e[n].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var u in e)r.d(n,u,function(t){return e[t]}.bind(null,u));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";function n(e,t){return void 0===t&&(t="-"),new RegExp("^(?!0{4}"+t+"0{2}"+t+"0{2})((?=[0-9]{4}"+t+"(((0[^2])|1[0-2])|02(?="+t+"(([0-1][0-9])|2[0-8])))"+t+"[0-9]{2})|(?=((([13579][26])|([2468][048])|(0[48]))0{2})|([0-9]{2}((((0|[2468])[48])|[2468][048])|([13579][26])))"+t+"02"+t+"29))([0-9]{4})"+t+"(?!((0[469])|11)"+t+"31)((0[1,3-9]|1[0-2])|(02(?!"+t+"3)))"+t+"([0-2][0-9]|3[0-1])$").test(e)}function u(e){var t=/\D/.exec(e);return t?t[0]:""}function i(e,t,r){void 0===t&&(t=":"),void 0===r&&(r=!1);var n=new RegExp("^([0-1]|2(?=([0-3])|4"+t+"00))[0-9]"+t+"[0-5][0-9]("+t+"([0-5]|6(?=0))[0-9])?(.[0-9]{1,9})?$");if(!r||!/[Z+\-]/.test(e))return n.test(e);if(/Z$/.test(e))return n.test(e.replace("Z",""));var i=e.includes("+"),o=e.split(/[+-]/),f=o[0],c=o[1];return n.test(f)&&function(e,t,r){return void 0===r&&(r=":"),new RegExp(t?"^(0(?!(2"+r+"4)|0"+r+"3)|1(?=([0-1]|2(?="+r+"[04])|[34](?="+r+"0))))([03469](?="+r+"[03])|[17](?="+r+"0)|2(?="+r+"[04])|5(?="+r+"[034])|8(?="+r+"[04]))"+r+"([03](?=0)|4(?=5))[05]$":"^(0(?=[^0])|1(?=[0-2]))([39](?="+r+"[03])|[0-24-8](?="+r+"00))"+r+"[03]0$").test(e)}(c,i,u(c))}function o(e){var t,r=e.split("T"),o=r[0],f=r[1];return n(o,u(o))&&i(f,(t=f.match(/[^Z+\-\d]/),Array.isArray(t)?t[0]:""),!0)}function f(e,t){return void 0===t&&(t="-"),new RegExp("^[0-9]{4}"+t+"(0(?=[^0])|1(?=[0-2]))[0-9]$").test(e)}r.r(t),r.d(t,"isValidDate",(function(){return n})),r.d(t,"isValidISODateString",(function(){return o})),r.d(t,"isValidTime",(function(){return i})),r.d(t,"isValidYearMonth",(function(){return f}))}]); |
@@ -0,0 +0,0 @@ /** |
export declare function isValidISODateString(dateString: string): boolean; |
/** | ||
* | ||
* @param time hh:mm:ss (optional) | ||
* @param timeWithOffset hh:mm:ss(optional)±hh:mm(optional) | ||
* @param s separator between hours, minutes and optional seconds | ||
* @param isTimezoneCheckOn boolean flag, pass true not to check for valid timezone | ||
*/ | ||
export declare function isValidTime(time: string, s?: string): boolean; | ||
export declare function isValidTime(timeWithOffset: string, s?: string, isTimezoneCheckOn?: boolean): boolean; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -32,3 +32,3 @@ { | ||
"license": "MIT", | ||
"version": "2.0.5", | ||
"version": "2.1.0", | ||
"keywords": [ | ||
@@ -35,0 +35,0 @@ "date", |
@@ -9,4 +9,11 @@ # iso-datestring-validator | ||
2. **Time validation**. HH:mm:ss.fff format, seconds and fractions of seconds being optional. Custom digit separators supported for HHmmss as well (no custom separator for fractions, it is dot). | ||
2. **Time validation**. HH:mm:ss.fff±hh:mm format, seconds, fractions of seconds and timezone offset being optional. Custom digit separators supported for HHmmss as well (no custom separator for fractions, it is dot). | ||
**Caveat**: do not use '-' and '+' as separators when validating time with timezone. I am reluctant to fix this unless it is an issue. | ||
``` | ||
isValidTime('14-45-15.000+00-00', '-', true) | ||
// will yield wrong result | ||
``` | ||
3. **Year-month validation**. | ||
@@ -79,3 +86,3 @@ | ||
Time string in HH:mm:ss.fff format can be validated with the **isValidTime** function. Seconds and fractions are optional. However, if using fractions min number of numbers is 1 and max is 9. | ||
Time string in HH:mm:ss.fff±hh:mm format can be validated with the **isValidTime** function. Seconds and fractions are optional. However, if using fractions min number of numbers is 1 and max is 9. Zone offset is optional as well, its check is switched off by default. | ||
@@ -94,2 +101,13 @@ ``` | ||
// pass time, separator and boolean flag to enable zone offset check | ||
isValidTime('14:45:15.000+00:00', ':', true) | ||
// true | ||
// you can take advantage of default separator if you pass undefined as second param | ||
isValidTime('14:45:15.000+00:00', undefined, true) | ||
// true | ||
isValidTime('144515.000Z', '', true) | ||
// true | ||
``` | ||
@@ -96,0 +114,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9785
11
33
142