nickpalenchar / goodtimer Goto Github PK
View Code? Open in Web Editor NEWA setTimeout/setInterval for Humans (and so much more)
Home Page: https://nickpalenchar.github.io/goodtimer
License: MIT License
A setTimeout/setInterval for Humans (and so much more)
Home Page: https://nickpalenchar.github.io/goodtimer
License: MIT License
d
,h
,m
,s
,ms
will automatically parse that unit of time, even if not in the right order.
"3h"
= 3:00:00
"40m3h
= 3:40:00
If more numbers without units are added, they take the next unit of measurment
"3h30"
= 3:30:00
"3h30:4
= 3:30:04
Something like
const { useSetGoodInterval } = require('goodtimer/timeutil');
useSetGoodInterval();
setInterval(..., ...) // now is setGoodInterval
Ability to add words (usually a human name for the unit), that will automatically be pluralized if the value is anything but 1.
timer.fmtTime('%S {%s:second} left') // => "10 seconds left", "1 second left"
signature proposed
{%unit:WORD}
timeStr
s are the abbreviations for full names (i.e., 'M'
or 'minutes'
)
{
round | floor | ceil: 'timeStr',
exclude: 'timeStr', // remove all values up to and including timeStr, from end
}
"Time" is currently represented by an array of numbers (such as [10,0]
for 10 mins). Comparing them is cumbersome.
Make a Time class that allows some additional functions such as:
math - add and subtract
compasinons - compare if time is greater, less than, or equal to another time.
UI - format string
where possible, methods should be similar in name to Dates
instead of using this.mins, this.secs
, just use [mm, ss]
english-like parsing:
two years and seven days
10 minutes
1 second
3 second
Main qualities:
and
can be added without interfearingfunctions fire on onTimeout
and onInterval
, but OnTime
should be added to allow users to add arbitrary events whenever they please.
new Timer("5:00", {
onTime: {
"2:00": showRunningLowOnTime,
"0:30": showVeryRunningLowOnTime
}
});
const timer = new Timer("5:00");
timer.onTime("2:00", showRunningLowOnTime);
timer.onTime("0:30", showVeryRunningLowOnTime);
```js
## clearing `onTime` events.
```js
timer.clearOnTime("2:00");
// returns: true if a function existed and was removed, false otherwise
This effectively makes onTimeout
a function for { onTime: "0:00" }
, and should be refactored as such.
Is your feature request related to a problem? Please describe.
Can be a good thing add also a client version.
Describe the solution you'd like
Add the javascript client side version.
Describe alternatives you've considered
Now I can only use goodtimer with node js and not within a browser...
Additional context
/
divider , defalut ":" character used to seperate units in showUI methods
minute/hr/dayFunction: to invoke the function on each interval unit passed
immediateInterval( default false : immediately calls the interval function when the timer is instantiated. (sholdu this be default true??????)
UIPadding <second|minute|hour|day> : - zero padding (and zeros when no value remaning) defult true for seconds only.
protect default: false
- prevents the new timer object from being destroyed via .destroy()
can also call these of the same name on Timer.options
for the 0.1.x release
only function declarations can be used for access to timer via, this
. Arrow functions's lexical scoping breaks the relationship. But instead, timer can pass its self (this
) to the callbacks first argument, which can allow arrow functions.
new Timer('1m', { onTimeout: function() {
this.reset();
}});
can be
new Timer('1m', { onTimeout: (timer) => timer.reset() });
Enchance .toString()
to be .toString(startingUnit?, endUnit?)
.
startingUnit takes the floor of that unit.
time.toString(); // -> "03:15.325"
time.toString('s'); // -> "03:15"
Passing a falsey value results in no starting unit.
endUnit
adds any larger units to the end unit.
time.toString(); // "03:15.325"
time.toString(null, 's'); // "95.325"
we might want to display 30 hours as 30 hours rather than 1 day and 6 hours. Allow the ability to cap.
new Timer('30:00:00', { maxUnit: 'hours' });
the Time class has the same ability
new Time('30:00:00', { maxUnit: 'hours'});
Timers/Times can be dynamical adjusted with setMaxUnit
Other methods where its useful:
Timer.fmtTime('%h hours', {maxUnit: 'hours'});
so we dont pollute docs with lots of details.
generate an index.html page that lists all objects in the goodtimer/
s3 bucket.
prevent rounding to the next appropriate unit with !
appended.
"70!"
= :70
"100m!"
= 100:00
! works only on largest unit, so all other places should be ignored and rounded.
10:60!
= 11:00
That way a user could verify a hash of a version was not tampered with.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.