value-breakpoints
Run specific stuff when value reaches a specific range.
☁️ Installation
# Using npm npm install --save value-breakpoints # Using yarn yarn add value-breakpoints
📋 Example
const ValueBreakpoints = ; let value = 0; ; let brks = min: 10 max: 30 { console; } { console; } { console; } min: 5 max: 10 { console; } ; brks;// 0// 2// 4// 6// 7// 9// 11// Start// Inside// Second End// 13// Inside// 15// Inside// 17// Inside// 19// Inside// 21// Inside// 23// Inside// 25// Inside// 27// Inside// 29// Inside// 31// End// 33// 35// 37// ...
❓ Get Help
There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. 🐛
- For direct and quick help, you can use Codementor. 🚀
📝 Documentation
BreakpointObj(input)
Creates a breakpoint object instance.
Params
- Object
input
: An object containing the following fields:min
(Number): The min value to be caught (default:-Infinity
).max
(Number): The max value to be caught (default:+Infinity
).start
(Function): The start handler (optional).inside
(Function): The inside handler (optional).end
(Function): The end handler (optional).event
(String): The event to be emitted when the value is in the specific range.
Return
- BreakpointObj The
BreakpointObj
instance containing the following fields:-
min
(Number): The min value to be caught (default:-Infinity
). -
max
(Number): The max value to be caught (default:+Infinity
). -
handlers
(Object):start
(Function): The start handler (optional).inside
(Function): The inside handler (optional).end
(Function): The end handler (optional).
-
started
(Boolean):true
, if the value reached the min number,false
otherwise. -
ended
(Boolean):true
, if the value reached the max number,false
otherwise. -
event
(String): The event to be emitted when the value is in the specific range. -
_
(Object): The original input object.
-
check(val)
Params
- Number
val
: The value to be checked.
Return
- Object An object containing the following fields:
handlers
(Array): The array of functions to call.isInside
(Boolean):true
, if the value is in the specified range.wasInside
(Boolean):true
, if the value was in the specified range one step before.
ValueBreakpoints(brks)
Run specific stuff when value reaches a specific range.
Params
- Array
brks
: An array of breakpoint objects.
Return
- ValueBreakpoints The
ValueBreakpoints
extended fromEventEmitter
.
stop()
Stops all the intervals.
Return
- ValueBreakpoints The current
ValueBreakpoints
instance.
add(brk)
Adds one or more breakpoints.
Params
- Object
brk
: The breakpoint object or an array of breakpoints.
Return
- ValueBreakpoints The current
ValueBreakpoints
instance.
check(fn, interval)
Params
- Function|Number
fn
: The function to be called when checking the value automatically. Manual checking is possible by passing a number. - Number
interval
: The interval duration.
Return
- ValueBreakpoints The current
ValueBreakpoints
instance (if a number was passed), or an object: stop
(Function): If called, it will stop the checking.fn
(Function): The function checking the value.
😋 How to contribute
Have an idea? Found a bug? See how to contribute.
💖 Support my projects
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
-
Starring and sharing the projects you like 🚀
-
—I love books! I will remember you after years if you buy me one. 😁 📖
-
—You can make one-time donations via PayPal. I'll probably buy a
coffeetea. 🍵 -
—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
-
Bitcoin—You can send me bitcoins at this address (or scanning the code below):
1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6
Thanks! ❤️