Giter Site home page Giter Site logo

astrohelm / astropack Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 108 KB

Astropack ๐Ÿ› ๏ธ - repository for all general purpose scripts. Time handler, Async, Wrappers, Structures, Strategies and many more repeated from project to project utilities. Main purpose - Tools for Astrohelm project.

Home Page: https://astrohelm.ru

License: MIT License

Makefile 4.97% JavaScript 95.03%
astrohelm javascript kit utilities utils utils-library useful-scripts

astropack's Introduction

Astropack - utilities kit

Utilities without any domain logic witch often in use at astrohelm repositories. This library can be used in frontend and backend with both commonjs and esm syntaxes.

Installation ๐Ÿš€

npm i astropack --save

Usage

  • 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.

Modules

Time utilities | astropack.time
  • 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.

Copyright & contributors

Copyright ยฉ 2023 Astrohelm contributors. This library is MIT licensed.
And it is part of Astrohelm ecosystem.

astropack's People

Contributors

sashapop10 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.