open-index/open-npm huggingface dataset:
npm package: @superhero/acl
Description: Access Control List
Author: Erik Landvall
Latest version: 0.3.0

# Acl

Licence: [MIT](https://opensource.org/licenses/MIT)

---

[![npm version](https://badge.fury.io/js/%40superhero%2Facl.svg)](https://badge.fury.io/js/%40superhero%2Facl)

ACL - Access Control List

## Install

`npm install @superhero/acl`

...or just set the dependency in your `package.json` file:

```json
{
  "dependencies":
  {
    "@superhero/acl": "*"
  }
}
```

## Example | Role

```js
const
Acl         = require('@superhero/acl'),
acl         = new Acl,
role        = 'foo',
domain      = 'bar',
resource    = 'baz',
permission  = 'qux'

acl.addRoleResourcePermission(role, domain, resource, permission)
const authorized = acl.isRoleAuthorized(role, domain, resource, permission)
// authorized == true
```

## Example | User

```js
const
Acl         = require('@superhero/acl'),
acl         = new Acl,
user        = 'foobar',
role        = 'bazbar',
domain      = 'barbaz',
resource    = 'bazqux',
permission  = 'quxfoo'

acl.addRoleUser(role, user)
acl.addRoleResourcePermission(role, domain, resource, permission)
const authorized = acl.isUserAuthorized(user, domain, resource, permission)
// authorized == true
```

## Example | Dump and re-create an ACL

```js
const
AclFactory  = require('@superhero/acl/factory'),
aclFactory  = new AclFactory,
acl_genesis = aclFactory.create(),
role        = 'foo',
domain      = 'bar',
resource    = 'baz',
permission  = 'qux'

acl_genesis.addRoleResourcePermission(role, domain, resource, permission)

const
dump        = acl_genesis.dump(),
acl         = aclFactory.create(dump),
authorized  = acl.isRoleAuthorized(role, domain, resource, permission)
// authorized == true
```
npm package: @superhero/core.eventsource
Description: A solution for an eventsource implementation
Latest version: 3.12.3

# Core › Eventsource

Licence: [MIT](https://opensource.org/licenses/MIT)

----

[![npm version](https://badge.fury.io/js/%40superhero%2Fcore.eventsource.svg)](https://badge.fury.io/js/%40superhero%2Fcore.eventsource)

----
npm package: @superhero/core.message-queue
Description: A reactive programming model utilizing Redis as a message queue with integrated scheduling capabilities
Latest version: 1.0.10

# Message Queue

Licence: [MIT](https://opensource.org/licenses/MIT)

----

[![npm version](https://badge.fury.io/js/%40superhero%2Fmessage-queue.svg)](https://badge.fury.io/js/%40superhero%2Fmessage-queue)

----
npm package: @superhero/core.redis
Description: A redis wrapper for the core library
Latest version: 2.7.1

# Core - Redis

Redis wrapper for the core library

---

[![npm version](https://badge.fury.io/js/%40superhero%2Fcore.redis.svg)](https://badge.fury.io/js/%40superhero%2Fcore.redis)

## Install

`npm install @superhero/core.redis`

...or just set the dependency in your `package.json` file:

```json
{
  "dependencies":
  {
    "@superhero/core.redis": "*"
  }
}
```
npm package: @superhero/core.resource
Description: Addon module to serve resources from a public folder to the @superhero/core module
Author: Erik Landvall
Latest version: 2.1.0

# Core › Resource

Licence: [MIT](https://opensource.org/licenses/MIT)

---

[![npm version](https://badge.fury.io/js/%40superhero%2Fcore.resource.svg)](https://badge.fury.io/js/%40superhero%2Fcore.resource)

This is an addon module to the [superhero/core](https://github.com/superhero/js.core) module. This addon is a simple dispatcher that can be used to serve public resources.

## Install

`npm install @superhero/core.resource`

...or just set the dependency in your `package.json` file:

```json
{
  "dependencies":
  {
    "@superhero/core.resource": "*"
  }
}
```

## Example Application

### Example Application › File structure

```
App
├── view
│   ├── resource
│   │   └── js
│   │       └── foo.js
|   └── config.js
├── index.js
└── package.json
```

#### `package.js`

```js
{
  "name": "Super Duper App",
  "version": "0.0.1",
  "description": "An example meant to describe the libraries fundamentals",
  "license": "MIT",
  "dependencies": {
    "superhero": "*",
    "@superhero/core.resource": "*"
  }
}

```

#### `config.js`

```js
module.exports =
{
  core:
  {
    resource:
    {
      directory: 'view'
    },
    http:
    {
      server:
      {
        routes:
        {
          resource:
          {
            url       : '/resource/.+',
            endpoint  : '@superhero/core.resource',
            input     : false
          }
        }
      }
    }
  }
}
```

#### `index.js`

```js
const
CoreFactory = require('superhero/core/factory'),
coreFactory = new CoreFactory,
core        = coreFactory.create()

core.add('view')
core.add('@superhero/core.resource')

core.load()

core.locate('bootstrap').bootstrap().then(() =>
core.locate('http/server').listen(process.env.HTTP_PORT))
```
npm package: @superhero/db
Description: Db interaction, designed to separate queries from the source code
Author: Erik Landvall
Latest version: 1.0.1

# DB

Licence: [MIT](https://opensource.org/licenses/MIT)

---

[![npm version](https://badge.fury.io/js/%40superhero%2Fdb.svg)](https://badge.fury.io/js/%40superhero%2Fdb)

A simple DB interface implementation that reads queries from a file, segregating your code from your queries.

## Install

`npm install @superhero/db`

...or just set the dependency in your `package.json` file:

```json
{
  "dependencies":
  {
    "@superhero/db": "*"
  }
}
```

## Example | MySql

```js
const
connections     = 5,
host            = 'mysql.example.com',
user            = 'root',
password        = 'b4real',
filePath        = '/sql',
fileSuffix      = '.sql',
mysql           = require('mysql'),
Db              = require('@superhero/db'),
AdapterFactory  = require('@superhero/db/adapter/mysql/factory'),
adapterFactory  = new AdapterFactory(),
adapter         = adapterFactory.create(mysql, { connections, host, user, password }),
db              = new Db(adapter, filePath, fileSuffix),
result          = await db.query('file', ['context'])
```

The example above will create a pool with 5 idle connections and query the database with the content from the `/sql/file.sql` file composed with the specified context.


## Example | Postgres

```js
const
host            = 'postgres.example.com',
user            = 'root',
database        = 'stuff',
password        = 'b4real',
filePath        = '/sql',
fileSuffix      = '.sql',
pg              = require('pg'),
Db              = require('@superhero/db'),
AdapterFactory  = require('@superhero/db/adapter/postgres/factory'),
adapterFactory  = new AdapterFactory(),
adapter         = adapterFactory.create(pg, { host, user, password, database }),
db              = new Db(adapter, filePath, fileSuffix),
result          = await db.query('file', ['context'])
```

The example above will create a pool and query the database with the content from the `/sql/file.sql` file composed with the specified context.
npm package: @superhero/debug
Description: Debug utility
Author: Erik Landvall
Latest version: 1.1.14

# Debug

Licence: [MIT](https://opensource.org/licenses/MIT)

---

[![npm version](https://badge.fury.io/js/%40superhero%2Fdebug.svg)](https://badge.fury.io/js/%40superhero%2Fdebug)

A debug utility for pretty log output..

## Install

`npm install @superhero/debug`

...or just set the dependency in your `package.json` file:

```json
{
  "dependencies":
  {
    "@superhero/debug": "*"
  }
}
```

## Example

```javascript
const
Debug = require('@superhero/debug'),
debug = new Debug(/* options */);

debug.log('what is this?', {foo:'bar', baz:'qux'});

// outputs something like the following in the console log (color coded):
/*
  2017-11-17 13:20:40:	what is this?	{ foo: 'bar',
    baz: 'qux' }
*/
```

Or the shorter version if you don't need to define any options:

```javascript
require('@superhero/debug').log('what is this?', {foo:'bar', baz:'qux'});
```

## Options

All options are optional.

```javascript
{
  // cap array output
  maxArrayLength: 10,

  // cap object depth
  maxObjectDepth: 10,

  // cap string length
  maxStringLength: 100,

  // define a desired color of the output:
  // ['black', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow', 'white', false]
  color: undefined,

  // if false, output wont be colored.
  colors: true,

  // show timestamp in prefix.
  date: true,

  // available date formats @see: https://www.npmjs.com/package/dateformat
  dateFormat: 'yyyy-mm-dd HH:MM:ss',

  // if false, no output is made.
  debug: true,

  // if an auto increment index should be printed.
  index: false,

  // a static string that will prefix all output of this instance.
  prefix: false,

  // the separator to use between content.
  separator: '\t',

  // error output, writable stream
  stderr: process.stderr,

  // log output, writable stream
  stdout: process.stdout
}
```
npm package: @superhero/elastic
Description: object modeling tool for elasticsearch
Author: Erik Landvall
Latest version: 0.0.1

# An object modeling tool for elasticsearch.

## Example
```
const
elastic = require('@superhero/elastic'),
type    = elastic.type,
schema  =
{
  created   : type.date,
  updated   : type.date,
  title     : type.text,
  body      : type.text,
  viewed    : type.integer,
  comments  :
  {
    ip      : type.ip,
    email   : type.keyword,
    avatar  : type.binary,
    location: type.geo_point,
    title   : type.text,
    body    : type.text,
    rating  : type.float,
    approved: type.boolean
  }
},
host  = 'localhost',
port  = 9200,
db    = elastic.db(host, port[, user, password, ssl=false]);

// Will reindex the index to reflect the defined schema, if the schema defined
// is different from what's already mapped.
// To prevent reindexing; use the last argument. If set to false, will throw an
// error if the mapping does not match what's already defined. Only creates the
// index if the index doesn't already exist.
// The "index-name" is optional an optional argument, if no index name is
// defined then the type name will be used.
db.index(['index-name',] 'blog', schema [, update=true], (error, index) =>
{
  // basic interface of the index, the interface can be extended
  // index.search(terms, cb);
  // index.remove(id, cb);
  // index.add(item, cb);
  // index.save(id, item, cb);
  // index.rest(method, uri, params, body, cb);
  // index.filter(map);
  // index.validate(map);

  // find by ...
  index.findByTitle         = (title, cb) => this.find({title}, cb);
  index.findByCommentTitle  = (title, cb) => this.find({comments:{title}}, cb);
  index.findCommentsByTitle = (title, cb) => this.find({title}, (error, result) => cb(error, result && [].concat(...result.map(item => item.comments))));

  // input filter
  index.filter =
  {
    title   : (value, action, cb) => cb(value.trim()),
    created : (value, action, cb) => cb(action == 'add'   ? Date.now()  : undefined),
    updated : (value, action, cb) => cb(action == 'save'  ? Date.now()  : undefined),
    comments: (value, action, cb) => cb([].isArray(value) ? value       : (item === undefined ? undefined : [value])),
  });

  // input validator
  index.validate =
  {
    comments:
    {
      email : (value, cb) => cb(value.test(/\S+@\S+\.\S+/))
    }
  });
});
```
npm package: @superhero/flow
Description: control asynchronous flow tools
Author: Erik Landvall
Latest version: 1.0.0

# Flow

Licence: [MIT](https://opensource.org/licenses/MIT)

---

[![npm version](https://badge.fury.io/js/%40superhero%2Fflow.svg)](https://badge.fury.io/js/%40superhero%2Fflow)

Tools to control asynchronous flow

## Install

`npm install @superhero/flow`

...or just set the dependency in your `package.json` file:

```json
{
  "dependencies":
  {
    "@superhero/flow": "*"
  }
}
```

## Example

Not ready for production...
npm package: @superhero/request
Description: Wrapper for the http and https modules request function
Author: Erik Landvall
Latest version: 2.3.8

# Request

Licence: [MIT](https://opensource.org/licenses/MIT)

---

[![npm version](https://badge.fury.io/js/%40superhero%2Frequest.svg)](https://badge.fury.io/js/%40superhero%2Frequest)

A wrapper for the http and https modules request function. I put this together to be able to simplify my api requests..

## Install

`npm install @superhero/request`

...or just set the dependency in your `package.json` file:

```json
{
  "dependencies":
  {
    "@superhero/request": "*"
  }
}
```

## Example

```javascript
const
Request = require('@superhero/request'),
request = new Request();

request.post('example.com/foobar').then((result) => console.log(result.status, result.headers, result.data));
request.post({url:'https://example.com/foobar', data: {foo:'bar',baz:'qux'}}).then(console.log);
```

## Options

Options for the constructor.

```javascript
{
  // if true, some output for debugging is logged to the console
  debug: false,

  // debug console color
  debug_color: 'cyan',

  // if the debug console should be prefixed with the date time
  debug_date: true',

  // the debug prefix message
  debug_prefix: 'debug request:',

  // a seperator between debug message
  debug_separator: ' ',

  // this url will be used to resolve any provided url in the fetch call
  url: '',

  // optional proxy url (example: http://user:password@www.example.com:666)
  proxy: '',

  // headers that will be used in every request
  headers: {},

  // retries amount of specified times if a none 2XX response is returned
  retry: 0,

  // timeout
  timeout: 30e3,

  // specifies if you want the ssl unauthorization to be rejected or not
  rejectUnauthorized: true
}
```

Options for each request

```javascript
{
  // the url to make the request to, relative paths will be resolved against
  // the provided url in the constructor
  url: '',

  // an object map of the data to send with the request
  data: undefined,

  // an object map of headers to send with the request
  headers: {},

  // amount of retries on the request level
  retry: 0,

  // timeout, inherit from setting in the constructor
  timeout: ?,

  // https://nodejs.org/api/stream.html#stream_writable_streams
  pipe: Writable,

  // alias for pipe
  stream: Writable
}
```
npm package: @superhero/socket
Description: TCP socket connection, client and server
Author: Erik Landvall
Latest version: 0.5.2

# Socket

Licence: [MIT](https://opensource.org/licenses/MIT)

---

[![npm version](https://badge.fury.io/js/%40superhero%2Fsocket.svg)](https://badge.fury.io/js/%40superhero%2Fsocket)

A socket connection for "server to server" communication.

## Install

`npm install @superhero/socket`

...or just set the dependency in your `package.json` file:

```json
{
  "dependencies":
  {
    "@superhero/socket": "*"
  }
}
```

## Example Application

A simple example to get started follows.

```js
const
SocketFactory = require('@superhero/socket'),
socketFactory = new SocketFactory,
// Debug      = require('@superhero/debug'),
// log        = new Debug({ debug:true }),
log           = console,
server        = socket.createServer(log),
client        = socket.createClient(log),
port          = 18200,
event         = 'foobar',
body          = { foo:'bar' }

server.listen(port)
client.connect(port)

client.emit(event, body)
server.on(event, (context, data) => context.emit(event, body))
client.on(event, (context, data) =>
{
  // if you need to close the connection, then...
  client.client.end()
  server.server.close()
})
```
npm package: @superhero/syntax-check
Description: Test for syntax errors
Author: Erik Landvall
Latest version: 0.0.2

# Syntax check

Licence: [MIT](https://opensource.org/licenses/MIT)

---

[![npm version](https://badge.fury.io/js/%40superhero%2Fsyntax-check.svg)](https://badge.fury.io/js/%40superhero%2Fsyntax-check)

A "syntax check test" module that utilizes the `node -c` command through a bash script.

## Install

`npm install @superhero/syntax-check`

...or just set the dependency in your `package.json` file:

```json
{
  "dependencies":
  {
    "@superhero/syntax-check": "*"
  }
}
```

## Example

```js
{
  "name": "Super Duper App",
  "scripts": {
    "test": "syntax-check"
  },
  "devDependencies": {
    "@superhero/syntax-check": "0.0.1"
  }
}
```

## Example | with mocha, or any other test script

```js
{
  "name": "Super Duper App",
  "scripts": {
    "test": "syntax-check && mocha"
  },
  "devDependencies": {
    "@superhero/syntax-check": "0.0.1",
    "mocha": "5.1.0",
  }
}
```

## Output

```
  Syntax check of files:

  ✔ ./index.js
  ✔ ./model/auth/aggregate.js
  ✔ ./model/auth/index.js
  ✔ ./model/auth/error/invalid-token.js
  ✔ ./model/auth/error/unauthorized.js
  ✔ ./model/log/index.js
  ✔ ./model/redis/gateway.js
  ✔ ./model/redis/index.js
  ✔ ./model/redis/error/key-conflict.js
  ✔ ./model/redis/gateway-fallback.js
  ✔ ./model/mysql/gateway.js
  ✔ ./model/mysql/gateway/transaction.js
  ✔ ./config.js
  ✔ ./controller/endpoint/index.js
  ✔ ./controller/endpoint/v1.leads.js
  ✔ ./controller/middleware/authenticate.js
  ✔ ./controller/middleware/authorize.js

  Successful syntax check of 30 files
```
npm package: @superhero/telnet
Description: Telnet client
Author: Erik Landvall
Latest version: 1.3.3

# Telnet

Licence: [MIT](https://opensource.org/licenses/MIT)

---

[![npm version](https://badge.fury.io/js/%40superhero%2Ftelnet.svg)](https://badge.fury.io/js/%40superhero%2Ftelnet)

A simple telnet client

## Install

`npm install @superhero/telnet`

...or just set the dependency in your `package.json` file:

```json
{
  "dependencies":
  {
    "@superhero/telnet": "*"
  }
}
```

## Example

```javascript
const
Telnet  = require('@superhero/telnet'),
telnet  = new Telnet(),
host    = '127.0.0.1',
port    = 23;

// optional host and port, but you probably like to specify the host at least :)
telnet.connect(host, port)

// all commands are stacked and performed in a series after each other.
.exec(/login: $/i, 'superhero')
.exec(/password: $/i, 'b-real')

/**
 * Argument specification:
 * 1. regex, when found in returned string, then write the command
 * 2. the telnet command to write
 * 3. [optional] how long to sleep, expressed in milliseconds
 * 4. [optional] callback with the returned data after the command has been performed
 */
.exec(/# $/, '<your command>', 0, (error, data) => {});
```

## options

All options are optional.

```javascript
{
  // timeout in milliseconds, if 0 then never timeout
  timeout     : 60e3,

  // debug options, see "superhero/js.debug" for options
  debug       : {},

  // control the amount of debugging data logged, the smaller the number the less is logged
  debug_level : 3,

  // array of regex, output will be compared to all the regex, if match, exit -> emit error..
  error       : [],

  // array of regex, when the commands queue stack is depleted use this regex to find the end  
  end         : [/# ?$/],

  // list of callbacks when end is found
  onEnd       : [],

  // list of callbacks when the socket connection has closed
  onClose     : [],

  // list of callbacks when an error took place
  onError     : [],

  // list of callbacks when a timeout occurred
  onTimeout   : [],
}
```
npm package: @superhero/translation
Description: Translation module
Author: Erik Landvall
Latest version: 0.0.3

# Translation

Licence: [MIT](https://opensource.org/licenses/MIT)

---

[![npm version](https://badge.fury.io/js/%40superhero%2Ftranslation.svg)](https://badge.fury.io/js/%40superhero%2Ftranslation)

A translation module | pre-beta

## Install

`npm install @superhero/translation`

...or just set the dependency in your `package.json` file:

```json
{
  "dependencies":
  {
    "@superhero/translation": "*"
  }
}
```
npm package: @superhero/websocket
Description: Websocket implementation
Author: Erik Landvall
Latest version: 1.1.1

# Websocket

Licence: [MIT](https://opensource.org/licenses/MIT)

---

[![npm version](https://badge.fury.io/js/%40superhero%2Fwebsocket.svg)](https://badge.fury.io/js/%40superhero%2Fwebsocket)

A server/client bundle setup to solve some personal issues I have with other solutions out there.

## Install

`npm install @superhero/websocket`

...or just set the dependency in your `package.json` file:

```json
{
  "dependencies":
  {
    "@superhero/websocket": "*"
  }
}
```

## Browser › Example

#### `server.js`

```javascript
const Websocket = require('@superhero/websocket')
const options   = { debug:true }
const websocket = new Websocket(options)

// listen on port 80
websocket.server.listen({ port:80 })

websocket.events.on('HelloWorld', (ctx, dto) =>
{
  // dto == { 'I':'am','now':'connected' }
  ctx.emit('sup m8', { 'this':'is','the':'response' })
})

websocket.events.on('¯|_(ツ)_/¯', (ctx, dto) =>
{
  // dto == { 'also':'works' }

  // headers is an object of the request headers sent when connection was
  // established
  console.log(ctx.headers)

  // client ip
  console.log(ctx.socket.remoteAddress)

  // ip family (IPv4 or IPv6)
  console.log(ctx.socket.remoteFamily)

  // numeric representation of the remote port..
  console.log(ctx.socket.remotePort)
})
```

#### `index.html`

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Websocket by a Superhero</title>
  </head>

  <body>
    <script data-main="/main" src="//requirejs.org/docs/release/2.2.0/minified/require.js"></script>
  </body>
</html>
```

#### `main.js`

```javascript
define(
[
  // this "cient" -module is included in this repo. see `client.browser.js` file
  'client'
],
function(client)
{
  var socket = client(
  {
    host  : 'localhost',
    debug : true
  })
  .on('sup m8', function(dto)
  {
    // dto == { 'this':'is','the':'response' }
    socket.emit('¯|_(ツ)_/¯', { 'also':'works' })
  })
  .connected(function(socket2)
  {
    // `socket` === `socket2`
    // socket2 is however returned through a promise that the socket is
    // connected. attaching listeners does not need this promise, emitting
    // messages however needs a connection to send to.

    // example
    socket2.emit('HelloWorld', { 'I':'am','now':'connected' })
  })
})
```

## Server › Example

The module has both a server and a client. So you can use the module for a
server to server connection, *for what ever reason you now want to do that...*

```js
const WebsocketServer = require('@superhero/websocket')
const WebsocketClient = require('@superhero/websocket/client')

const server = new WebsocketServer()
const client = new WebsocketClient()

const evt1 = 'foo'
const evt2 = 'bar'
const dto1 = 'baz'
const dto2 = 'qux'

const port = 9001

server.server.listen({ port })
server.server.on('listening', async () =>
{
  await client.connect(port)
  client.emit(evt1, dto1)
})

server.events.on(evt1, (ctx, dto) =>
{
  // dto === 'baz'
  ctx.emit(evt2, dto2)
})

client.events.on(evt2, (dto) =>
{
  // dto === 'qux'
})
```