@videsk/humanize-date
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -5,2 +5,6 @@ # Changelog | ||
## v1.1.0 | ||
- [NEW] Units `auto`, automatically returns with the best unit | ||
## v1.0.0 | ||
@@ -7,0 +11,0 @@ |
@@ -1,2 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.HumanizeDate=e():t.HumanizeDate=e()}(window,(function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var o,r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}();var a=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.from=new Date,this.to=new Date,this.units={seconds:this.seconds,minutes:this.minutes,hours:this.hours,days:this.days,weeks:this.weeks,months:this.months,years:this.years,quarters:this.quarters}}return i(t,[{key:"toLocale",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Date,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{year:"numeric",month:"long",day:"numeric"};return new Date(t).toLocaleDateString(navigator.language,e)}},{key:"dates",value:function(t,e){var n=this.constructor.getDates(t,e),o=n.from,r=n.to;return this.from=new Date(o),this.to=new Date(r),this}},{key:"within",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"seconds";if(!(t in this.units))throw new Error("The available units are "+Object.keys(this.units));return new Intl.RelativeTimeFormat(navigator.language,{numeric:"auto"}).format(this.units[t](this.from,this.to),t)}},{key:"ago",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"seconds";if(!(t in this.units))throw new Error("The available units are "+Object.keys(this.units));return new Intl.RelativeTimeFormat(navigator.language,{numeric:"auto"}).format(-1*this.units[t](this.from,this.to),t)}},{key:"seconds",value:function(t,e){return Math.abs(new Date(e||this.to)-new Date(t||this.from))/1e3}},{key:"minutes",value:function(t,e){return Math.abs(new Date(e||this.to)-new Date(t||this.from))/6e4}},{key:"hours",value:function(t,e){return Math.abs(new Date(e||this.to)-new Date(t||this.from))/36e5}},{key:"days",value:function(t,e){return Math.abs(new Date(e||this.to)-new Date(t||this.from))/864e5}},{key:"weeks",value:function(t,e){return Math.abs(new Date(e||this.to)-new Date(t||this.from))/24192e5}},{key:"months",value:function(t,e){return Math.abs(12*this.years(t,e)+(new Date(e||this.to).getMonth()-new Date(t||this.from).getMonth()))}},{key:"years",value:function(t,e){return Math.abs(new Date(e||this.to).getFullYear()-new Date(t||this.from).getFullYear())}},{key:"quarters",value:function(t,e){return Math.abs(this.months(t,e)/4)}}],[{key:"getDates",value:function(t,e){return!Array.isArray(t)&&"object"!==(void 0===t?"undefined":r(t))||"object"===(void 0===t?"undefined":r(t))&&"getTime"in t?{from:t,to:e}:Array.isArray(t)?{from:t[0],to:t[1]}:"object"===(void 0===t?"undefined":r(t))?{from:t[Object.keys(t)[0]],to:t[Object.keys(t)[1]]}:void 0}}]),t}();void 0===(o=function(){return a}.apply(e,[]))||(t.exports=o),t.exports=a}])})); | ||
//# sourceMappingURL=humanize-date.min.js.map | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).HumanizeDate=e()}(this,(function(){return class{constructor(){this.from=new Date,this.to=new Date,this.units={seconds:this.seconds,minutes:this.minutes,hours:this.hours,days:this.days,weeks:this.weeks,months:this.months,years:this.years,quarters:this.quarters,auto:this.auto}}toLocale(t=new Date,e={year:"numeric",month:"long",day:"numeric"}){return new Date(t).toLocaleDateString(navigator.language,e)}dates(t=new Date,e=new Date){const{from:s,to:i}=this.constructor.getDates(t,e);return this.from=new Date(s),this.to=new Date(i),this}within(t="seconds",e={numeric:"auto"}){if(!(t in this.units))throw new Error(`The available units are ${Object.keys(this.units)}`);return new Intl.RelativeTimeFormat(navigator.language,e).format(this.units[t](this.from,this.to),"auto"!==t?t:this.autoToUnitText(this.from,this.to))}ago(t="seconds",e={numeric:"auto"}){if(!(t in this.units))throw new Error(`The available units are ${Object.keys(this.units)}`);return new Intl.RelativeTimeFormat(navigator.language,e).format(-1*this.units[t](this.from,this.to),"auto"!==t?t:this.autoToUnitText(this.from,this.to))}seconds(t,e){return Math.abs(new Date(e||this.to)-new Date(t||this.from))/1e3}minutes(t,e){return Math.abs(new Date(e||this.to)-new Date(t||this.from))/6e4}hours(t,e){return Math.abs(new Date(e||this.to)-new Date(t||this.from))/36e5}days(t,e){return Math.abs(new Date(e||this.to)-new Date(t||this.from))/864e5}weeks(t,e){return Math.abs(new Date(e||this.to)-new Date(t||this.from))/24192e5}months(t,e){return Math.abs(12*this.years(t,e)+(new Date(e||this.to).getMonth()-new Date(t||this.from).getMonth()))}years(t,e){return Math.abs(new Date(e||this.to).getFullYear()-new Date(t||this.from).getFullYear())}quarters(t,e){return Math.abs(this.months(t,e)/4)}auto(t,e){return this.seconds(t,e)<=60?this.seconds(t,e):this.minutes(t,e)<=60?this.minutes(t,e):this.hours(t,e)<=24?this.hours(t,e):this.days(t,e)<=31?this.days(t,e):this.months(t,e)<=12?this.months(t,e):this.years(t,e)}autoToUnitText(t,e){return this.seconds(t,e)<=60?"seconds":this.minutes(t,e)<=60?"minutes":this.hours(t,e)<=24?"hours":this.days(t,e)<=31?"days":this.months(t,e)<=12?"months":"years"}static getDates(t,e){return!Array.isArray(t)&&"object"!=typeof t||"object"==typeof t&&"getTime"in t?{from:t,to:e}:Array.isArray(t)?{from:t[0],to:t[1]}:"object"==typeof t?{from:t[Object.keys(t)[0]],to:t[Object.keys(t)[1]]}:void 0}}})); |
{ | ||
"name": "@videsk/humanize-date", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Humanize dates making readable in locale and ultra lightweight", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "webpack", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"build": "rollup -c", | ||
"dev": "rollup -c -w" | ||
}, | ||
"browser": "dist/humanize-date.min.js", | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.esm.js", | ||
"repository": { | ||
@@ -26,8 +28,9 @@ "type": "git", | ||
"devDependencies": { | ||
"babel-core": "^6.26.3", | ||
"babel-loader": "^7.1.5", | ||
"babel-preset-es2015": "^6.24.1", | ||
"webpack": "^4.39.1", | ||
"webpack-cli": "^3.3.6" | ||
"@rollup/plugin-commonjs": "^18.0.0", | ||
"@rollup/plugin-node-resolve": "^11.2.1", | ||
"rollup": "^2.42.4", | ||
"rollup-plugin-livereload": "^2.0.0", | ||
"rollup-plugin-replace": "^2.2.0", | ||
"rollup-plugin-terser": "^7.0.2" | ||
} | ||
} |
@@ -19,2 +19,8 @@ # Humanize Date | ||
### Install | ||
```shell | ||
npm i @videsk/humanize-date | ||
``` | ||
It's simple: | ||
@@ -21,0 +27,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
18
260
1
74
47055
6
1
2