open-index/open-npm huggingface dataset:
npm package: @sapphire-sh/utils
Description: @sapphire-sh/utils
Author: sapphire
Latest version: 1.71.0

# @sapphire-sh/utils

[![npm-publish](https://github.com/sapphire-sh/sapphire-utils/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/sapphire-sh/sapphire-utils/actions/workflows/npm-publish.yml)
[![license](https://img.shields.io/github/license/sapphire-sh/sapphire-utils)](https://github.com/sapphire-sh/sapphire-utils/blob/main/LICENSE)
[![npm package version](https://img.shields.io/npm/v/@sapphire-sh/utils)](https://www.npmjs.com/package/@sapphire-sh/utils)
[![github package version](https://img.shields.io/github/package-json/v/sapphire-sh/sapphire-utils?label=github)](https://github.com/sapphire-sh/sapphire-utils/packages/1601820)
[![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/@sapphire-sh/utils)](https://bundlephobia.com/package/@sapphire-sh/utils)

## Installation

```sh
npm install -S @sapphire-sh/utils
```
npm package: @sapphirecode/auth-client-helper
Description: client helper to authenticate on servers using the auth-server-helper
Author: Timo Hocker
Latest version: 1.1.3
Deprecated: not compatible with current auth-server-helper, not necessary since you design those auth endpoints yourself

# @sapphirecode/auth-client-helper

version: 1.1.x

client helper to authenticate on servers using the auth-server-helper

## Installation

npm:

> npm i --save @sapphirecode/auth-client-helper

yarn:

> yarn add  @sapphirecode/auth-client-helper

## Usage

```js
const client = require('@sapphirecode/auth-client-helper');

// if using in the browser, will send a request to the current host
const session_id = client.login('user','passw');

// specify a host manually
const session_id = client.login('user','passw','https://example.com');
```

## License

MIT © Timo Hocker <timo@scode.ovh>
npm package: @sapphirecode/console-app
Description: read parameters from env, config files, console args or interactively
Author: Timo Hocker
Latest version: 2.1.7

# @sapphirecode/console-app

version: 2.1.x

read parameters from env, config files, console args or interactively

## Installation

npm:

> npm i --save @sapphirecode/console-app

yarn:

> yarn add @sapphirecode/console-app

## Usage

```js
const {
  ArrayOption, // arrays made out of numbers, strings and booleans
  BooleanOption,
  FileOption, // paths that exist and are a file
  FolderOption, // paths that exist and are a folder
  NumberOption, // integer and float values
  IntegerOption, // only integer values
  PathOption, // paths that exist in the file system
  StringOption,
} = require('@sapphirecode/console-app');

const input = await new BooleanOption({
  name: 'foo', // option name used in configs and console arguments
  
  // optional settings:
  default: false, // default value
  sources: {
    configs: [], // config files to read from. none by default
    interactive: true, // use interactive prompts
    console: true // read from console arguments
    // environment is always on if the 'env' option below is specified
  },
  alias: 'f', // shorthand console argument name
  env: 'foo_env', // name of the environment variable to read from
  message: 'input foo', // message to display in interactive prompt
  error: 'failed to read foo', // message to display when input was invalid
  error_callback: (opt, val, err)=>{...}, // function to call when an option value could not be read
  exit_on_interrupt: true,  // exit program when user cancels the interactive prompt
}).parse();
```

config files can import other config files with #include. example:

```json
#include base.json
{
  "foo": "bar"
}
```

config files are parsed using [hjson](https://github.com/hjson/hjson-js)

## License

MIT © Timo Hocker <timo@scode.ovh>
npm package: @sapphirecode/consts
Description: useful constant values that are used in many applications
Author: Timo Hocker
Latest version: 1.2.2

# @sapphirecode/consts

version: 1.2.x

useful constant values that are used in many applications

## Installation

npm:

> npm i --save @sapphirecode/consts

yarn:

> yarn add @sapphirecode/consts

## Usage

there are many constants, too many to document by hand so I suggest you use
autocomplete or look into the source.

Http status codes:

```js
const {http} = require('@sapphirecode/consts');

console.log(http.status_ok); // 200
```

Time

```js
const {time} = require('@sapphirecode/consts');

console.log(time.base_ms.minute); // 60000
```

The time module contains a few precalculated bases like base_s, base_ms, base_us
and base_ns. Those allow you to use timers without calculating everything
first.

> timer(base_ms.week) instead of timer(1000 x 60 x 60 x 24 x 7) or
> timer(base_us.week) if your timer counts in microseconds

time intervals above one week are functions, because they require additional
information to be calculated

```js
console.log(time.base_ms.year(2020));
console.log(time.base_ms.year(12, 2020));
```

## License

MIT © Timo Hocker <timo@scode.ovh>
npm package: @sapphirecode/crypto-helper
Description: simple functions for cryptography
Author: Timo Hocker
Latest version: 2.1.2

# @sapphirecode/crypto-helper

version: 2.1.x

simple functions for cryptography

## Installation

npm:

> npm i --save @sapphirecode/crypto-helper

yarn:

> yarn add @sapphirecode/crypto-helper

## Usage

### Examples

```js
const crypto = require('@sapphirecode/crypto-helper');

const rand_hex = crypto.random_hex(16); // outputs 16 byte random hex
const rand_salt = crypto.create_salt(); // same as random_hex, but with fixed length of 32 bytes
const random_string = crypto.random_string(16); // output 16 character long random string
const hash = crypto.hash_sha512(random_string, random_hex); // returns sha 512 hex
const check = crypto.checksum('foo'); // returns a sha 256 hex
const scrypt_hash = await crypto.pbkdf_scrypt('foo', 'bar'); // returns a scrypt hash

// jwt like object signing
const signed = crypto.sign_object({foo: 'bar'}, 'secret');
const info = await crypto.get_signature_info(signed); // returns an object with iat (issued at), key_info and data
const dec = await crypto.decode_signed(signed); // decode a signed object without verifying the signature
const ver = await crypto.verify_signature(signed, 'secret', 10000); // verifies the signature and returns the contents. the timeout is in milliseconds and optional, timing will be ignored if omitted.
const ver_info = await crypto.verify_signature_get_info(signed, 'secret', 10000); // verify a signature and get signature information like iat and key_info
const ver_func = await crypto.verify_signature(
  signed,
  (signature_info) => 'secret',
  10000
); // verify a signature, retrieve the key using the signature info

// encryption
const enc = crypto.encrypt_aes('foo', 'bar');
const dec = crypto.decrypt_aes(enc, 'bar');

// asymmetric encryption and signatures
const keys = await crypto.generate_keypair(2048); // generate private and public key (length is optional and 2048 by default)

const aenc = crypto.asym_encrypt('foo', keys.public_key); // encrypt
const adec = crypto.asym_decrypt(aenc, key.private_key); // decrypt

const asig = crypto.asym_sign('foo', keys.private_key); // create signature
const aver = crypto.asym_verify('foo', keys.public_key, asig); // verify signature, returns boolean
```

### Asymmetric signatures on object signing

the functions `sign_object`, `verify_signature`, ... will automatically detect
rsa keys and use them to sign objects asymmetrically. Note that keys have to be
provided in the correct order (private key for signing, public key for
verifying). Else the keys will just be interpreted as symmetric and verification
will fail.

## License

MIT © Timo Hocker <timo@scode.ovh>
npm package: @sapphirecode/dcm
Description: Managing docker compose configurations, volumes and networks
Author: Timo Hocker
Latest version: 1.2.20

# Docker-Compose Management

Version: 1.2.0

Open docker-compose management cli

## Setup

Installation: `npm i -g @sapphirecode/dcm`

Each service has its own folder under `services/` all necessary docker-compose
files and configs should be stored there.

> Docker-compose files have to be named `docker-compose.yml` and be at the top
> level of each individual service folder.

In `dependencies.json` all dependencies of a service can be defined. The start
and stop order of services is determined by the dependencies.

The file `passive.json` can be used to deactivate services, those will not be
started automatically, but they can be started manually by running
`docker-compose up -d` in the service's folder or by including the flag
`--include-passive` when using the cli.

Networks can be defined in `networks.json`. Available options are `internal` to
set docker's network internal flag and `subnet` to define a specific subnet for
a network. With `interface_name` you can specify the interface name for the
network.

Volume settings are placed in `volumes.json`. By default all volumes in this
file are added to the backup filter. To prevent them from getting backed up, set
the option `backup` to false. Additionally single folders can be excluded from
the backup using the `backup_exclude` option. Instead of backing up the whole
volume, you can use `backup_include` to include only specific folders.

## Commands

Global Options:

- `--delay=<seconds>`: Delay before executing the command

1. Pulling images: `pull`

This command simply pulls all images and exits.

2. Starting services: `up`

This command starts all services in the correct order and creates the necessary
networks and volumes if they don't already exist. Available options are:
`--pull` to pull images before starting the services and `--include-passive` to
include passive services.

3. Stopping services: `down`

Stops all services including the passive ones.

4. Restarting services: `restart`

Restarts all services, has the same effect as running `down` and `up`
separately.

5. Creating a backup filter: `create_filter`

Creates a filter file for rsync to create a backup of all configured volumes.
npm package: @sapphirecode/encoding-helper
Description: Converting strings between different encodings
Author: Timo Hocker
Latest version: 1.1.0

# @sapphirecode/encoding-helper

version: 1.1.x

Converting strings between different encodings

## Installation

npm:

> npm i --save @sapphirecode/encoding-helper

yarn:

> yarn add @sapphirecode/encoding-helper

## Usage

```js
const encoding = require('@sapphirecode/encoding-helper');

const hex = encoding.to_hex('abc'); // convert any encoding to hex, default is utf-8
const b64 = encoding.to_b64(hex, 'hex'); // convert any encoding to base64, default is utf-8
const b58 = encoding.to_b58(hex, 'hex'); // convert any encoding to base58, default is utf-8
const utf8 = encoding.to_utf8(hex, 'hex'); // convert any encoding to utf-8, no default
const hexn = encoding.num_to_hex(10); // convert a number to hex
const num = encoding.hex_to_num('a'); // convert hex to a number
```

supported input encodings:

- default supported by buffer:
  - ascii
  - base64
  - binary
  - hex
  - latin1
  - ucs-2
  - utf-8
  - utf16le
- additional encodings:
  - base58

## License

MIT © Timo Hocker <timo@scode.ovh>
npm package: @sapphirecode/eslint-config
Description: scode eslint standard configuration
Author: Timo Hocker
Latest version: 2.1.23

# @sapphirecode/eslint-config

version: 2.1.x

scode eslint standard configuration

## Installation

npm:

> npm i --save-dev @sapphirecode/eslint-config

yarn:

> yarn add --dev @sapphirecode/eslint-config

then create a file named .eslintrc.js with the following contents.

it is a basic configuration, it can be customized to your preferences.

```js
module.exports = {
  env: {
    commonjs: true,
    es6: true,
    node: true
  },
  extends: [
    '@sapphirecode'
  ]
}
```

## License

BSD-3-Clause © Timo Hocker <timo@scode.ovh>
npm package: @sapphirecode/eslint-config-es6
Description: scode eslint es6 configuration
Author: Timo Hocker
Latest version: 1.2.2

# @sapphirecode/eslint-config-es6

version: 1.2.x

scode eslint standard configuration for es6

## Installation

npm:

> npm i --save-dev @sapphirecode/eslint-config-es6

yarn:

> yarn add --dev @sapphirecode/eslint-config-es6

then create a file named .eslintrc.js with the following contents.

it is a basic configuration, it can be customized to your preferences.

```js
module.exports = {
  env: {
    commonjs: true,
    es6: true,
    node: true
  },
  extends: [
    '@sapphirecode/eslint-config-es6'
  ]
}
```

## License

BSD-3-Clause © Timo Hocker <timo@scode.ovh>
npm package: @sapphirecode/eslint-config-ts
Description: scode eslint typescript configuration
Author: Timo Hocker
Latest version: 1.2.2

# @sapphirecode/eslint-config-ts

version: 1.2.x

scode eslint configuration for typescript

## Installation

npm:

> npm i --save-dev @sapphirecode/eslint-config-ts

yarn:

> yarn add --dev @sapphirecode/eslint-config-ts

then create a file named .eslintrc.js with the following contents.

it is a basic configuration, it can be customized to your preferences.

```js
module.exports = {
  env: {
    commonjs: true,
    es6: true,
    node: true
  },
  extends: [
    '@sapphirecode/eslint-config-ts'
  ]
}
```

## License

MIT License © Timo Hocker <timo@scode.ovh>
npm package: @sapphirecode/eslint-config-vue
Description: scode eslint vue configuration
Author: Timo Hocker
Latest version: 1.1.21

# @sapphirecode/eslint-config-vue

version: 1.1.x

scode eslint configuration for vue.js

## Installation

npm:

> npm i --save-dev @sapphirecode/eslint-config-vue

yarn:

> yarn add --dev @sapphirecode/eslint-config-vue

then create a file named .eslintrc.js with the following contents.

it is a basic configuration, it can be customized to your preferences.

```js
module.exports = {
  env: {
    commonjs: true,
    es6: true,
    node: true
  },
  extends: [
    '@sapphirecode/eslint-config-vue'
  ]
}
```

## License

BSD-3-Clause © Timo Hocker <timo@scode.ovh>
npm package: @sapphirecode/graphviz-builder
Description: constructing graphviz files using an easy typescript interface
Author: Timo Hocker
Latest version: 1.4.0

# @sapphirecode/graphviz-builder

version: 1.4.x

constructing graphviz files using an easy typescript interface

## Installation

npm:

> npm i --save @sapphirecode/graphviz-builder

yarn:

> yarn add @sapphirecode/graphviz-builder

## Usage

### Object structure

```js
import {Graph,Color} from '@sapphirecode/graphviz-builder';

// create a new graph
const g = new Graph('foo');

// add a node to the graph
// this function returns the full name of the node that's later used for creating edges
const bar = g.add_node('bar');

// if you want to specify attributes
const baz = g.add_node(n => {
  n.name = 'baz';
  n.label = 'node baz';
  n.color = Color.red;
});

// connect nodes
g.add_edge(bar, baz);

// add a subgraph
g.add_graph(sg=>{
  sg.name = 'subgraph';

  sg.add_node('foo');
})

// get info about current stream state
g.node_count // count of nodes written
g.path // get current path (parent graph names separated by underscores)
```

## License

MIT © Timo Hocker <timo@scode.ovh>
npm package: @sapphirecode/modelling
Description: base classes for controlling data
Author: Timo Hocker
Latest version: 1.1.13

# @sapphirecode/modelling

version: 1.1.x

base classes for controlling data

## Installation

npm:

> npm i --save @sapphirecode/modelling

yarn:

> yarn add @sapphirecode/modelling

## Usage

### Classes

#### Persistent

Persistent allows easy data transfer between classes that extend Persistent, as
long as they have overlapping properties.

to create a persistent type, create a class that extends Persistent and in the
constructor, define all properties you want to store.

Property types can be string, boolean, number or array

```js
import { Persistent } from '@sapphirecode/modelling';

class Foo extends Persistent {
  public constructor() {
    super();
    this.properties.foo = 'string';
    this.properties.baz = 'boolean';
  }
}

class Bar extends Persistent {
  public constructor() {
    super();
    this.properties.bar = 'string';
    this.properties.baz = 'boolean';
  }
}

const f = new Foo();
f.set('foo','bar');
f.set('baz', true);

const b = new Bar();
b.assign(f); // f.assign_to(b) will do the same
// now the property 'baz' of b will also be true
console.log(b.serialize()); // Persistent also implements Serializable
```

Methods:

- assign, assign_to, assign_object: (implementation of Assignable)
- to_object: return data as plain object
- serialize: return data as json string (Implementation of Serializable)
- set(key, value): set property to a specific value
- get(key): get a property

#### DatabaseModel

Extends Persistent and has the abstract methods read, write, delete and
define_properties to allow working with databases

in define_properties, set all the properties you need, id is automatically added
and has to be a number.

read, write and delete specify the actions needed to interact with the database
itself

#### ControlModel

The ControlModel is there to verify incoming data and modify it if needed. It
also extends Persistent.

The method define_properties lets you define the data you will store.

before_change allows you to register observers, that are able to cancel changes.
the registered observers are called with the following parameters: (new_value,
old_value, property_name). By returning false they can cancel the change that
was about to happen.

register_observer does the same thing, but those observers are not able to
cancel the change and they are called after the change already happened.

### Interfaces

#### Assignable

Base interface of Persistent

Methods:

- assign(b): assign data of another assingable object (b)
- assign_to(b): assing data to b
- assign_object(obj): assign data of plain object obj

#### Serializable

Interface to allow serialization of different data structures

Methods:

- serialize: serialize into a string

## License

MIT © Timo Hocker <timo@scode.ovh>
npm package: @sapphirecode/password-helper
Description: easy password storage with argon2
Author: Timo Hocker
Latest version: 1.0.51

# @sapphirecode/password-helper

version: 1.0.x

easy password storage with argon2

## Installation

npm:

> npm i --save @sapphirecode/password-helper

yarn:

> yarn add  @sapphirecode/password-helper

## Usage

```js
const password_helper = require('@sapphirecode/password-helper');

// create a hash
const hash = await password_helper.hash('foo');

// verify a password using the hash
await password_helper.verify(hash, 'foo'); // returns true;
await password_helper.verify(hash, 'bar'); // returns false;
```

## License

MIT © Timo Hocker <timo@scode.ovh>