open-index/open-npm huggingface dataset:
npm package: @loadingio/cubic
Description: Cubic Function and Cubic Bezier calculator
Author: zbryikt
Latest version: 0.0.4

# cubic

Calculator for cubic function and cubic bezier. Provided with an inverse function from given X to t, which could be used to calculate Y then.

Equation roots calculation use Sheng Jin Formula which might be inaccurate according to Kahan; there is an alternative solution here: https://www.npmjs.com/package/cubic-roots , which could be integrated in the future.


## Usage

    require! <[cubic]>
    bezier = new cubic.bezier [0.2, 0.3, 0.4, 0.5]
    t = Math.random!
    x = bezier.x t
    y = bezier.y t
    t-from-x = bezier.t x
    
    assert t == t-from-x

    coff = [0 to 3].map -> Math.random!
    func = new cubic.func coff.0, coff.1, coff.2, coff.3
    x = Math.random!
    func.calc x             # f(x)
    root = func.root 0      # root for solving f(x) = 0


For a simply `x -> y` bezier calculation:

    b = new cubic.bezier([....])
    [0 to 1 by 0.1].map (x) -> y = b.y(bezier.t(x))


## Compatibility

cubic use `Math.cbrt` which is not available in IE < 11. You can simply use a polyfill or following code:

```
    Math.cbrt = -> Math.pow(it, 1/3)
```


## LICENSE

MIT
npm package: @loadingio/datahub
Description: access scoped data via piped operational transformation
Author: zbryikt
Latest version: 0.0.1

# Data Hub

Access *scoped* data via *piped* *operational transformation*.


## Usage

    # this is our data source.
    src = new srchub do
      ops-out: (ops) -> # update data src by incoming ops
      get: -> # return complete data. always return cloned data to prevent user from touching original data

    # this is our view controller
    des = new deshub do
      ops-in (ops): -> # update ui / widget

    # data through pipe are scoped under "my-view"
    view-hub = new hub {scope: ["my-view"]}
    # ... from srchub / through view-hub / to deshub
    src.pipe view-hub .pipe des

    # notify all users (deshub) about data changed
    src.ops-in [... /* ops */ ...]

    # update data source (srchub)
    des.ops-out [... /* ops */ ...]


## Memhub, Userhub

Datahub also provides auxiliary hubs for quickly trying and testing.

 - `memhub` - data source hub. store data in memory.
 - `usrhub` - simple destination hub. constructor options:
   - render(ops): called when there are updates from data source.

A sample usage of `memhub` and `usrhub` as follows:

    mhub = new memhub!
    uhub = new usrhub {render: -> console.log('ok'); }
    mhub.pipe uhub
    document.querySelector('textarea').addEventListener \input, ->
      uhub.ops-out [
        { p: ['str',0], si: @value[@value.length - 1] }
      ]


## Sharehub

Sharehub provides a simple interface and implementation reference for adopting ShareDB with data hub to keep edited data in database:

    uhub = new usrhub!
    shub = new sharehub do
      render: -> # .. update ui ..
    shub.init({
      id: 'my-sharedb-doc-id'
    })
      .then ->
        shub.pipe uhub

Sharehub is in a standalone JS file. include `sharehub.js` if you want to use it.


## Scoping

Passing `scope` option ( an array of strings / numbers ) into datahub constructor to filter incoming op and data based on the specified scope. For example, assume our data source keeps data in `datasrc` variable, then following hub:

    new hub({scope: ["users", "deleted"]})

will only pass ops that affect object in `datasrc.users.deleted`. Furthermore, data get from this hub will only be the subtree in `datasrc.users.deleted`.

You can pipe data source to a hub that is scoped, and pipe this scoped hub to the destination hubs that use the same subtree.


## License

MIT
npm package: @loadingio/debounce.js
Description: Debouncing Function
Author: zbryikt
Latest version: 1.0.1

# Debounce.js

Debounce.js helps you to debounce your function.

## Features

 * Simply by wrapping function in debounce().
 * Preserve scope for object methods.
 * Support Promise

## Usage

 * simply debounce:

    ````
    var myFunc = debounce(function( ... ) {
      /* do whatever you want */
    }); 
    myFunc(...);
    ````


 * custom delay: 

    ````
    var myFunc = debounce(function(p1, p2, ...) { ... }, 123); /* default delay is 500 */
    myFunc(...);
    ````

 * sometimes it's convenient to have delay come first:
    ````
    var myFunc = debounce(123, function(p1, p2, ...) { ... });
    myFunc(...);
    ````

 * simply delay for a few milliseconds (e.g., 300 ms) is also userful when working with promise:
   ```
   debounce(300).then(function() { ... });
   ```

 * use promise after function is executed:

    ````
    var myFunc = debounce(function( ... ) { ... }); 
    myFunc(...).then(function(ret) {
      if(ret) { ... } /* ret is thre return value of the function inside debounce */
    });
    ````

 * used with object members:

    ````
    var obj = {
      member: debounce(function( ... ) { this.value = 2; },
      value: 1
    };
    ````

 * clear previously scheduled function call:

   ````
   myFunc();
   myFunc.clear();
   ````

 * bypassing debounce and call immediately:
   ```
   myFunc( ... ).now();
   ```

 * overwrite previous set delay value:
   ```
   myFunc.delay(300)();
   ```


## Reference

 - usage: 
   - constructor
     - deb = debounce(f, delay)
     - deb = debounce(delay, f) 
     - debounce(delay).then ...
   - methods
     - deb.clear - clear all pending calls.
     - deb() - call `f` ( pending for delay milliseconds ).
     - deb().cancel - cancel pending call.
     - deb().now - call `f` immediately, discard previous call.
     - deb().then - like promise pattern, execute function in then after `f` finished.


## Compatibility

 * debounce.js uses Promise, which is not supported in some browsers like IE. Remember to install polyfill before using debounce.js.


## LICENSE

MIT
npm package: @loadingio/ldc
Description: js components/action framework
Author: zbryikt
Latest version: 0.0.6

# ldc

loading js component/action framework.


## API

 - `ldc.register(name, dep-list, (({dep-list}) ->))`: register a component
   - while name ignored the module will be an anonymous module and be treated as an app directly.
   - return the registered ldc object.
 - `ldc.app(name, ...)`: set main entry point of component
 - `ldc.init(opt, ...)`: force init components
   - `opt` is either:
     - a string: name for specific ldc component.
     - an object: a ldc object ( returned by `ldc.register` )
     - an array of either string or objects as above
 - `ldc.on(name, ((...opts)->)`: listen to a ldc event
 - `ldc.fire(name, ...opts)`: fire a ldc event
 - `ldc.action(opt1, opt2)`: register an action handler.
   there are three different cases of usage
   1. opt1 = name, opt2 = object
      register an set of action handler under the namespace with opt1 as its name.

   2. opt1 = object, opt2 is omitted
      similar to 1. while use module name as the action name.
     
   3. opt1 = name, opt2 = function (deprecated)
      register ldc action. deprecated since we can use on/fire to replace this.


## Module

ldc helps us to maintain the dependency of modules. Define a module as follow:

    ldc.regsiter "module1", <[]>, -> return {foo: -> \bar}


A newly created this context can be used in this module:

    ldc.regsiter "module1", <[]>, -> return @ <<< {foo: -> \bar}


Declare dependency and load another module:

    ldc.regsiter "module2", <[module1]>, ({module1}) ->


the `module1` object sent to module2 handler will be the returned value in the module1 handler:

    ldc.regsiter "module2", <[module1]>, ({module1}) ->
      assert module1.foo! == \bar

Each module function will be called at most once. The returned object in the first call will be used then.

    ldc.regsiter "module1", <[]>, ->
      console.log "this line runs only once."
      @foo = (@foo or 0) + 1
      return @
    ldc.regsiter "module2", <[module1]>, ({module1}) ->
      assert module.foo == 1
    ldc.regsiter "module3", <[module1]>, ({module1}) ->
      assert module.foo == 1


main entry module can be defined by `ldc.app` or by omitting the module name:

    ldc.regsiter <[module1 module2]>, ({module1, module2}) -> ...


## Action

One can use `lda` to access the actions registered via `ldc.action`. For example, following code registers a set of actions:

    ldc.register "mymodule", [], ->
      ldc.action do
        open: ->
        close: ->


Once registered, we can use `ldc.mymodule` to access them:

    ldc.mymodule.open!


## License

MIT