open-index/open-npm huggingface dataset:
npm package: @superjs/awaitor
Description: awaitable callback
Author: mr_jin
Latest version: 1.1.4
Deprecated: deprecated, use @superjs/cb instead

# [@superjs](https://www.npmjs.com/org/superjs)/awaitor
awaitable callback. 

async/await way to call callback style functions

## thought
If you want to convert callback style to async/await style, you can either:
1. wrap the operation to return a promise
2. just call the operation, using @superjs/awaitor as callback, like the example below  

## usage
awaitor()

return an awaitable callback, the promiseValue of which is the args array it's called with 

awaitor.norm()

same as above, but it only accept two args: `(err,value)`. If err exists, promiseValue will be `err` and rejected. 
Otherwise, promiseValue will be `value`. 
## example

```javascript
const awaitor = require('@superjs/awaitor')
// await can't be used without being wrapped by async function
;(async ()=>{
  let cb = awaitor()
  foo(1,2,cb) // whenever a callback is needed, just use cb
  let result = await cb //result is an array, containing the args cb received
  console.log(result) // [3]
})()

function foo(a,b,cb){
  setTimeout(()=>cb(a+b),1000)
}
```

## use together with [@superjs/wait](https://www.npmjs.com/package/@superjs/wait)

wait can await something synchronously. 

```javascript
const awaitor = require('@superjs/awaitor')
const wait = require('@superjs/wait')

let cb = awaitor()
foo(1,2,cb) // whenever a callback is needed, just use cb
let result = wait(cb) //result is an array, containing the args cb received
console.log(result) // [3]

function foo(a,b,cb){
  setTimeout(()=>cb(a+b),1000)
}
```

## compatibility
You can use @superjs/awaitor in both nodejs and browser environment.
npm package: @superjs/cb
Description: awaitable callback
Author: mr_jin
Latest version: 1.0.2

# [@superjs](https://www.npmjs.com/org/superjs)/cb
awaitable callback. 

async/await way to call callback style functions

## Thought
If you want to convert callback style to async/await style, you can either:
1. wrap the operation to return a new Promise, which is ugly
2. or, just call the operation, using @superjs/cb as callback, then await the cb  

## Example

```javascript
const Cb = require('@superjs/cb')
// await can't be used without being wrapped by async function
;(async ()=>{
  // Cb() create a plain Promise
  // with some extra fields/magics
  setTimeout(Cb().ok,2000)

  await Cb.pop()
})()
```

You can also use it as event handlers:
```javascript
const Cb = require('@superjs/cb')
const {spawn} = require('child_process')
// await can't be used without being wrapped by async function
;(async ()=>{
  let proc = spawn('ls')
  // Cb().ok resolve 1st arg
  proc.stdout.on('data', Cb().ok) 
  // use Cb instead of Cb() to reference the last created one
  proc.on('error', Cb.err) //Cb.err reject 1st arg
  try {
    let out = await Cb.pop()
    console.log(`out: `+ out)
  }
  catch (err) {
    console.log(`err: `, err)
  }
})()
```

## API
### `Cb()`

* `returns`: `Cb`, return itself 

calling `Cb` will create a `Promise`: `cb`, then push `cb` to `cbStack`. 
From now on, `Cb` will *ref* to the `cb` created

**__*ref* means you can use `Cb.ok/err/arr/pair` to get `cb.ok/err/arr/pair`__**

### `Cb.pop()`
 
 * `returns`: `cb`, a `Promise` 
 
Pop the top `cb` in `cbStack` and return it

### `Cb.new()`
 
 * `returns`: `cb`, a `Promise` 
 
return a standalone cb not included by `cbStack`

comparing to `Cb()/Cb.pop()`, you would have to add a local variable to reference to `Cb.new()`

### `cb.then/catch/finally`

since cb is a `Promise`, use them just like `new Promise(...).then/catch/finally`



### `cb.ok(value)`

* `value`: value to be resolved with
 
resolve the Promise `cb` with `value`

### `cb.err(err)`

* `err`: error to be rejected with
 
reject the Promise `cb` with `err`

### `cb.arr(...args)`

* `...args`: arg list to be resolved with

collect args received as an array and resolve with `args`

### `cb.pair(err, value)`

* `err`: error to be rejected with, `err==null` to resolve `value`

* `value`: value to be resolved with, if `err==null`
 
## Use together with [@superjs/wait](https://www.npmjs.com/package/@superjs/wait)

@superjs/wait can await something synchronously. 

```javascript
const Cb = require('@superjs/cb')
const wait = require('@superjs/wait')

foo(1,2,Cb().arr) 
// wait instead of await
let result = wait(Cb.pop()) 
// print [3,-1] one second later
console.log(result) 

function foo(a,b,cb){
  setTimeout(()=>cb(a+b,a-b),1000)
}
```

## Compatibility
You can use @superjs/cb in both nodejs and browser environment.
npm package: @superjs/future
Description: wrap an async result
Author: mr_jin
Latest version: 1.0.2

# [@superjs](https://www.npmjs.com/org/superjs)/future
wrap an async result. 

## Example

```javascript
/// client.js
const MongoClient = require('mongodb').MongoClient
module.exports = future(()=>require('mongodb').MongoClient.connect('mongodb://localhost:27017'))
```

```javascript
/// collection.js
const client = require('./client')
module.exports = client.db().collection('test')
```

```javascript
/// app.js
const collection=require('./collection')
module.exports = async (params)=>{
  let result = await collection.insert(params)
  return result
}
```

## Thought
如果想在同步环境中返回需要 async 初始化的对象(如 export 一个 axios client 或 db client), 你可以选择:
1. 返回两个元素: async init函数, obj, 这样消费者需要提防init是否漏掉执行
2. 返回一个元素: async init函数, 该函数返回 obj, 这样消费者必须在 async 函数中才可消费, 对 reexport 或仅透传参数的场景很不友好
3. 返回一个元素: obj=future(init), 其返回为同步的, 该 obj 及该 obj 所有同步执行的过程和结果, 在被 await/then/catch/finally 时, 正确的结果将会被返回, 如同 obj=await init()之后执行这些过程一样

解释: 假如 await init() 返回 realObj, 那么 obj 是一个被称为 realObj 的配料的 Proxy, 除了实际 inspect 值时拿不到有用信息, 它能进行 realObj 的所有操作, 且get属性及当做函数调用时返回结果为新配料 obj2, 最终某个配料被 realObjN=await objN, 那么结果已经去配料化了, realObjN是实际对象

## Limitation
1. 仅对配料的get set apply作了 trap, 也就是不要进行get set apply之外的操作

## Options
future 支持一个有用的选项: lazy(默认 true)

当 lazy 为 false 时, 会在 future 函数进入时就执行 init 函数

否则会在首次 await 某个配料时执行 init 函数, 有可能永不被执行, 起到优化作用

若想指定 lazy 为 false, 使用示例如下:
```javascript
/// client.js
module.exports = future(()=>require('mongodb').MongoClient.connect('mongodb://localhost:27017'),{lazy:false})
```
npm package: @superjs/koa-router-dir
Description: composite a dir to a router
Author: jinCN
Latest version: 1.1.0

# koa-router-dir
composite a dir to a router

## Example
```javascript
const Koa = require('koa')
const koaRouterDir = require('koa-router-dir');
const app = new Koa()
app.use(koaRouterDir(__dirname+'/routers'))
```
npm package: @superjs/lazy
Description: lazy object
Author: mr_jin
Latest version: 1.0.1

# [@superjs](https://www.npmjs.com/org/superjs)/lazy
lazy object.

## Thought
If you want to define some lazy variable, you can either:
1. define a function instead, which is ugly
2. use a function to define a variable, such as `let local= lazy({a:()=>new Date()})`, then use it as `local.a`

## Example

```javascript
const lazy = require('@superjs/lazy')
const lazyLocal = lazy({
  noLazy: new Date(),
  lazy: ()=>{
    console.log('lazy')
    return new Date()
  },
  lazyNeverHappen: ()=>{
    console.log('lazyNeverHappen')
    return new Date()
  },
})

console.log(lazyLocal.noLazy) //
console.log(lazyLocal.lazy) // a little later than noLazy

console.log(lazyLocal.lazy) // never change again

lazyLocal.lazyNeverHappen = 1 // never invoke function
console.log(lazyLocal.lazyNeverHappen)
```

### recommend example for refactor
You have some variables that cost a lot, and want to make them lazy without changing any logic.

As an example, `require('typescript')` call may cost a lot, as used here:
```javascript
const ts=require('typescript') // expensive!!!
module.exports=()=>{
  console.log(ts)
  // a lot of ts here
}
```
Use `lazy()` to delay the `require`:
```javascript
const lazy = require('@superjs/lazy')
const lazyLocal = lazy({
  ts:()=>require('typescript') // expensive!!!
})
```

You cannot make a local variable to be lazy, so it's a must: every `ts` be refactor to `something.ts` like `lazyLocal.ts`.

It's recommended to use [Refactor]/[Inline...] in IDE to automate this for you:
```javascript
const lazy = require('@superjs/lazy')
const lazyLocal = lazy({
  ts:()=>require('typescript') // expensive!!!
})
const ts = lazyLocal.ts // [Refactor]/[Inline...] this

module.exports=()=>{
  console.log(ts)
  // a lot of ts here
}
```

You get perfectly what you want:
```javascript
const lazy = require('@superjs/lazy')
const lazyLocal = lazy({
  ts:()=>require('typescript') // expensive!!!
})

module.exports=()=>{
  console.log(lazyLocal.ts)
  // a lot of lazyLocal.ts here
}
```

## API
### `lazy(definitions)`

* `returns`: `Object`, return new object from `definitions`

convert function fields in `definitions` to lazy props, non-function stay the same. `lazy({a:1, b:()=>1})` returns `{a:1, b:lazyProp}` with lazyProp being basically 1


### `lazy.define(obj, definitions)`

 * `returns`: `Object`, return result object, return value is same as `obj`

same as `lazy()` but put props into existing `obj`.

## Compatibility
You can use @superjs/lazy in both nodejs and browser environment.
npm package: @superjs/observe
Description: use Proxy to observe changes for nested object
Author: jinCN
Latest version: 1.1.8

# @superjs/observe
use Proxy to observe changes for nested object
## Example
```javascript
const observe = require('@superjs/observe')
let x=observe({a:{b:1}},(change)=>{
  console.log(change)
})
x.a.b=2
```
The argument `change` will be output as below:
```
{
  key: 'a',
  type: 'object',
  data: {
    a: { b: 2 }
  },
  change: {
    key: 'b',
    type: 'object',
    data: { b: 2 },
    change: { data: 2 }
  }
}
```
For array type, only changes for NormalInteger keys will be tracked:
```javascript
const observe = require('@superjs/observe')
let x=observe({a:{b:[]}},(change)=>{
  console.log(change)
})
x.a.b.c=2
```
Nothing will be output.
npm package: @superjs/require-auto
Description: start node script without node_modules, install on require
Author: mr_jin
Latest version: 1.0.2

# [@superjs](https://www.npmjs.com/org/superjs)/require-auto
start node script without node_modules, install on require.

## Thought
No package.json, no node_modules, simply write the script, require dependencies, and run with `require-auto`

## Example

Install `@superjs/require-auto` globally:
```bash
npm i -g @superjs/require-auto
```
Then you can start a node script like this:
```bash
require-auto app.js
```
The dependencies will be installed in the dir of app.js.

You can also write `app.js` with first line as `#!/usr/bin/env require-auto`, just like below: 
```javascript
#!/usr/bin/env require-auto

const superagent = require('superagent')
const wait = require('@superjs/wait')
let { body } = wait(superagent.get('https://api.npms.io/v2/search?q=scope:superjs'))
console.log(`body:`, body)
```

Run it with
```bash
./app.js
```

## Programmatic Usage
```javascript
//after this, hook created for require, for every file
require('@superjs/require-auto') 

//if 'something' can't be resolved, I will `npm i something` then require it
require('something')
```

## API
### require('@superjs/require-auto') 
* `returns`: `requireAuto`, return singleton for the lib 

hook is created when the lib is required


### `requireAuto.option(opt)`
 * `opt`: option to specify
 
change the specific option of `requireAuto`.

available options are listed below:
 * `cwd`: where installation take place, default to the dir of `module.parent`(who first call`require
 ('@superjs/require-auto')`)
 * `silent`: don't log output, default to `false`
 * `excludeNodeModules`: don't hook require in node_modules, default to `false`.
npm package: @superjs/wait
Description: await anything synchronously
Author: mr_jin
Latest version: 1.1.6

# [@superjs](https://www.npmjs.com/org/superjs)/wait
await anything synchronously. 

## Thought
Useful when you want to get the result of async operation inside a synchronous function,
 
 while rewriting the 
synchronous 
function 
to be an async one is not possible. (Maybe it's in 3rd party library, or a predefined callback like event handler, etc)

## API
### `wait(awaitable)`

`awaitable`: a value can be awaited, which meas _everything_

return the resolved value of `awaitable` or throw the rejected error,
 
 just like using `await`, but synchronously. 

## Example

```javascript
const wait = require('@superjs/wait')
const su = require('superagent')
let resp = wait(su('https://api.npms.io/v2/search?q=scope:superjs')) //async http request 
console.log(resp.body) // result is printed synchronously
```

## Use together with [@superjs/cb](https://www.npmjs.com/package/@superjs/cb)

wait can resolve an operation which returns a promise, but not an operation which needs a callback.

you can either:
1. wrap the operation to return a promise
2. just call the operation, using @superjs/cb as callback, like below  

```javascript
const Cb = require('@superjs/cb')
const wait = require('@superjs/wait')

foo(1,2,Cb().arr) 
// wait instead of await
let result = wait(Cb.pop()) 
// print [3,-1] one second later
console.log(result) 

function foo(a,b,cb){
  setTimeout(()=>cb(a+b,a-b),1000)
}
```

## Also useful as debug tool
When being paused on a breakpoint, you can evaluate expressions but no async operations can be evaluated 
immediately.

Using @superjs/wait, you can evaluate an async operation, get the result of it, while still being paused
 on the breakpoint.

Just evaluate `wait(anyAsyncOperation())`, 
you will see the 
async operation gets done and returned.

You don't even have to require @superjs/wait in your code. Just install @superjs/wait as a devDependency. When debugging, 
evaluate `global.wait=process.mainModule.require('@superjs/wait')`. That's all.
npm package: @superjs/whitematrix-toolkit
Description: awaitable callback.
Author: mr_jin
Latest version: 1.0.3

# [@superjs](https://www.npmjs.com/org/superjs)/cb
awaitable callback. 

async/await way to call callback style functions

## Thought
If you want to convert callback style to async/await style, you can either:
1. wrap the operation to return a new Promise, which is ugly
2. or, just call the operation, using @superjs/cb as callback, then await the cb  

## Example

```javascript
const Cb = require('@superjs/cb')
// await can't be used without being wrapped by async function
;(async ()=>{
  // Cb() create a plain Promise
  // with some extra fields/magics
  setTimeout(Cb().ok,2000)

  await Cb.pop()
})()
```

You can also use it as event handlers:
```javascript
const Cb = require('@superjs/cb')
const {spawn} = require('child_process')
// await can't be used without being wrapped by async function
;(async ()=>{
  let proc = spawn('ls')
  // Cb().ok resolve 1st arg
  proc.stdout.on('data', Cb().ok) 
  // use Cb instead of Cb() to reference the last created one
  proc.on('error', Cb.err) //Cb.err reject 1st arg
  try {
    let out = await Cb.pop()
    console.log(`out: `+ out)
  }
  catch (err) {
    console.log(`err: `, err)
  }
})()
```

## API
### `Cb()`

* `returns`: `Cb`, return itself 

calling `Cb` will create a `Promise`: `cb`, then push `cb` to `cbStack`. 
From now on, `Cb` will *ref* to the `cb` created

**__*ref* means you can use `Cb.ok/err/arr/pair` to get `cb.ok/err/arr/pair`__**

### `Cb.pop()`
 
 * `returns`: `cb`, a `Promise` 
 
Pop the top `cb` in `cbStack` and return it

### `Cb.new()`
 
 * `returns`: `cb`, a `Promise` 
 
return a standalone cb not included by `cbStack`

comparing to `Cb()/Cb.pop()`, you would have to add a local variable to reference to `Cb.new()`

### `cb.then/catch/finally`

since cb is a `Promise`, use them just like `new Promise(...).then/catch/finally`



### `cb.ok(value)`

* `value`: value to be resolved with
 
resolve the Promise `cb` with `value`

### `cb.err(err)`

* `err`: error to be rejected with
 
reject the Promise `cb` with `err`

### `cb.arr(...args)`

* `...args`: arg list to be resolved with

collect args received as an array and resolve with `args`

### `cb.pair(err, value)`

* `err`: error to be rejected with, `err==null` to resolve `value`

* `value`: value to be resolved with, if `err==null`
 
## Use together with [@superjs/wait](https://www.npmjs.com/package/@superjs/wait)

@superjs/wait can await something synchronously. 

```javascript
const Cb = require('@superjs/cb')
const wait = require('@superjs/wait')

foo(1,2,Cb().arr) 
// wait instead of await
let result = wait(Cb.pop()) 
// print [3,-1] one second later
console.log(result) 

function foo(a,b,cb){
  setTimeout(()=>cb(a+b,a-b),1000)
}
```

## Compatibility
You can use @superjs/cb in both nodejs and browser environment.
npm package: @superjump/assetpack-core
Description: <p style="text-align:center;" align="center">   <picture align="center">       <source media="(prefers-color-scheme: dark)" srcset="https://github.com/pixijs/assetpack/blob/main/.github/assets/assetpack-logo-light.svg">       <source media="(prefers-color
Latest version: 1.4.1

<p style="text-align:center;" align="center">
  <picture align="center">
      <source media="(prefers-color-scheme: dark)" srcset="https://github.com/pixijs/assetpack/blob/main/.github/assets/assetpack-logo-light.svg">
      <source media="(prefers-color-scheme: light)" srcset="https://github.com/pixijs/assetpack/blob/main/.github/assets/assetpack-logo-dark.svg">
      <img align="center" src="https://github.com/pixijs/assetpack/blob/main/.github/assets/assetpack-logo-dark.svg" alt="Shows a dark AssetPack logo in light mode and a white logo in dark mode" width="60%"/>
  </picture>
  <div align="center" style="margin-top: -20px">
      <h3>A configurable asset pipeline for the web!</h3>
  </div>
</p>
<br>

AssetPack is a tool for optimising assets for the web. It can be used to transform, combine, compress assets.
Any asset that you want to transform or optimise into something else can be done with AssetPack.

AssetPack is framework agnostic, and can be used with any framework you like, such as PixiJS, Threejs, Phaser, etc.
It uses a plugin based system to allow you to create your own plugins to do whatever you want with your assets.

---

Check out the docs on how to get started with AssetPack: https://pixijs.io/assetpack/