astropack
v0.7.0
Published
Astrohelm Universal Scripts Kit
Downloads
24
Maintainers
Readme
Utilities without any domain logic witch often in use at astroghelm repositories. This library can be used in frontend and backend with both commonjs and esm syntaxes.
npm i astropack --save
- Warning ! divided into submodules, for example here you can see work with submodule time.
const { time } = require('astropack');
console.log(time.prettify('h:m:s / D.M|Y')); // 18:50:54 / 07.05|2023
All specifications can be found in test folder in test files. Or you can check our types.
- astropack.time.prettify Return date in any string format
prettify(format: string, date?: Date | string | number) => string;
// format is any combination of letters [YMDhmsi] with any optional separators
// Y - Year; M - Month; D - Day; h - Hours; m - Minute; s - Second; i - Millisecond
const astropack = require('astropack');
const astropack = require('astropack');
astropack.time.prettify('h:m:s / D.M|Y', new Date()); // 18:50:54 / 07.05|2023
astropack.time.prettify('h-m-s.i', new Date()); // 18-50-54.045
- astropack.time.duration Return duration in millisecond's from string
const astropack = require('astropack');
const astropack = require('astropack');
function duration(time: string): number;
// time is any combination of letters [dhms] with values
// d - Day; h - Hours; m - Minute; s - Second;
// Example: 1d 1h 1m 1s 90061000
const astropack = require('astropack');
const astropack = require('astropack');
astropack.time.duration('5s'); // 5000
astropack.time.duration('24h'); // 86400000
astropack.time.duration('1d'); // 86400000
astropack.time.duration('1d 1h 1m 5s'); // 90065000
- astropack.time.compare Create any dates compare functions
const astropack = require('astropack');
const astropack = require('astropack');
astropack.time.compare((a, b) => a > b)('2023-05-07', '2023-05-08'); // false
astropack.time.compare((a, b) => a > b)('2023-01-01', '2021-05-08'); // true
astropack.time.compare.bigger('2023-01-01', '2021-05-08'); // true
astropack.time.compare.under('2023-01-01', new Date()); // true
astropack.time.compare.equal('2023-01-01', '2021-05-08'); // false
- astropack.time.formatMake millisecond's more readable with format
const astropack = require('astropack');
astropack.time.format(1000); // 1 s
astropack.time.format(60000); // 1 m
astropack.time.format(60001); // 1 m, 1 ms
astropack.time.format(90000); // 1 m, 30 s
- astropack.time.measures Get divided millisecond's by all day time measurements object
const astropack = require('astropack');
const astropack = require('astropack');
astropack.time.measures(new Date()); // { w: 2798, d: 19592, h: 470227, m: 28213672, s: 1692820378, i: 1692820378275 }
astropack.time.measures(90020); // { d: 0, h: 0, m: 1, s: 90, i: 90020 }
- astropack.time.diff Return difference between two dates in any time measurement
const astropack = require('astropack');
const astropack = require('astropack');
let tomorrow = new Date(new Date().setDate(new Date().getDate() + 1));
astropack.time.diff(new Date(), tomorrow); // 1
astropack.time.diff(new Date(), tomorrow, 'h'); // 24
astropack.time.diff(tomorrow, new Date(), 'h'); // -24
Check types or libraries for more information about submodules.