# @totemorg/enums

> Provide basic enumerators

Latest version **3.26.0** (published 2024-07-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install @totemorg/enums
pnpm add @totemorg/enums
yarn add @totemorg/enums
bun add @totemorg/enums
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.26.0 |
| Published | 2024-07-02 |
| First published | 2022-10-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 344.5 KB |
| Known vulnerabilities | 0 (+12 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ACME Software Disposal Service |
| Maintainers | totem4, totem3, totem2, totem1 |

## Links

- npm: https://www.npmjs.com/package/@totemorg/enums
- Repository: https://github.com/totemorg/enums
- Homepage: https://github.com/totemorg/enums#readme
- Issues: https://github.com/totemorg/enums/issues
- npm.io page: https://npm.io/package/@totemorg/enums

## Dependencies (5)

- [imap](https://npm.io/package/imap.md) ^0.8.19
- [mysql2](https://npm.io/package/mysql2.md) ^3.9.7
- [nodemailer](https://npm.io/package/nodemailer.md) ^6.9.13
- [neo4j-driver](https://npm.io/package/neo4j-driver.md) ^4.4.11
- [nodemailer-smtp-transport](https://npm.io/package/nodemailer-smtp-transport.md) ^2.7.4

## Recent versions

- 3.26.0 (latest) — 2024-07-02
- 3.25.0 — 2024-05-27
- 3.23.0 — 2024-05-27
- 3.22.0 — 2024-05-27
- 3.21.0 — 2024-05-27
- 3.20.0 — 2024-05-27
- 3.19.0 — 2024-05-25
- 3.18.0 — 2024-05-25
- 3.15.0 — 2024-05-25
- 3.14.0 — 2024-05-25
- 3.13.0 — 2024-05-24
- 3.12.0 — 2023-10-31
- 3.11.0 — 2023-10-31
- 3.10.0 — 2023-10-31
- 3.9.0 — 2023-10-31
- … 26 more at https://npm.io/package/@totemorg/enums/versions

## README

# [ENUMS](https://www.npmjs.com/package/@totemorg/enums)

Provides methods to fetch, enumerate, stream, and index data.  Also provides connections
to the mysql, neo4j, txmail, rxmail services per env variables.
 
## Install

	npm install @totemorg/enums	
	npm update

## Start

	npm run	startdbs				# Start database servers
	npm run start 					# Start/unit test

## Manage

	npm run verminor				# Roll minor version
	npm run vermajor				# Roll major version
	npm run redoc					# Regen documentation
	npm run pubminor				# republish as minor version
	npm run pubmajor				# republish as major version

## Usage

	import { Copy, Each, Extend, Stream, ... } from "@totemorg/enums";

See program reference for more information.


## Program Reference
<details>
<summary>
<i>Open / Close</i>
</summary>
## Modules

<dl>
<dt><a href="#module_ENUMS">ENUMS</a></dt>
<dd><p>Provides various enumeration methods, stream and serialization methods, data indexing methods as well as 
MySQL and Neo4J database connectors.  This module documented IAW <a href="https://jsdoc.app/">jsdoc</a>.</p>
</dd>
<dt><a href="#ENUMS.module_Array">Array</a></dt>
<dd></dd>
<dt><a href="#ENUMS.module_String">String</a></dt>
<dd></dd>
</dl>

<a name="module_ENUMS"></a>

## ENUMS
Provides various enumeration methods, stream and serialization methods, data indexing methods as well as 
MySQL and Neo4J database connectors.  This module documented IAW [jsdoc](https://jsdoc.app/).

**Requires**: <code>module:[os](https://nodejs.org/docs/latest/api/)</code>, <code>module:[cluster](https://nodejs.org/docs/latest/api/)</code>, <code>module:[fs](https://nodejs.org/docs/latest/api/)</code>, <code>module:[http](https://nodejs.org/docs/latest/api/)</code>, <code>module:[https](https://nodejs.org/docs/latest/api/)</code>, <code>module:[vm](https://nodejs.org/docs/latest/api/)</code>, <code>module:[cp](https://nodejs.org/docs/latest/api/)</code>, <code>module:[crypto](https://nodejs.org/docs/latest/api/)</code>, <code>module:[stream](https://nodejs.org/docs/latest/api/)</code>, <code>module:[mysql](https://www.npmjs.com/package/mysql)</code>, <code>module:[neo4j-driver](https://www.npmjs.com/package/neo4j-driver)</code>, <code>module:[nodemailer](https://www.npmjs.com/package/nodemailer)</code>, <code>module:[nodemailer-smtp-transport](https://www.npmjs.com/package/nodemailer-smtp-transport)</code>  
**Author**: [ACMESDS](https://totemorg.github.io)  

* [ENUMS](#module_ENUMS)
    * _static_
        * [.mysql](#module_ENUMS.mysql)
        * [.neo4j](#module_ENUMS.neo4j)
        * [.txmail](#module_ENUMS.txmail)
        * [.rxmail](#module_ENUMS.rxmail)
        * [.Log](#module_ENUMS.Log)
        * [.neoThread(cb)](#module_ENUMS.neoThread)
        * [.sqlThread(cb)](#module_ENUMS.sqlThread)
        * [.Start(host, ctx)](#module_ENUMS.Start)
        * [.isFunction()](#module_ENUMS.isFunction)
        * [.isString()](#module_ENUMS.isString)
        * [.isObject()](#module_ENUMS.isObject)
        * [.isNumber()](#module_ENUMS.isNumber)
        * [.Copy(src, tar, deep)](#module_ENUMS.Copy) ⇒ <code>Object</code>
        * [.Each(A, cb)](#module_ENUMS.Each)
        * [.Notify()](#module_ENUMS.Notify)
    * _inner_
        * [~_Trace(msg, ...args)](#module_ENUMS.._Trace)

<a name="module_ENUMS.mysql"></a>

### ENUMS.mysql
Stash for MySQL configuation options.

**Kind**: static constant of [<code>ENUMS</code>](#module_ENUMS)  
<a name="module_ENUMS.neo4j"></a>

### ENUMS.neo4j
Stash for Neo4J configuation options.

**Kind**: static constant of [<code>ENUMS</code>](#module_ENUMS)  
<a name="module_ENUMS.txmail"></a>

### ENUMS.txmail
Stash for Send-Mail configuation options.

**Kind**: static constant of [<code>ENUMS</code>](#module_ENUMS)  
<a name="module_ENUMS.rxmail"></a>

### ENUMS.rxmail
Stash for Receive-Mail configuation options.

**Kind**: static constant of [<code>ENUMS</code>](#module_ENUMS)  
<a name="module_ENUMS.Log"></a>

### ENUMS.Log
Dump message to the console.

**Kind**: static constant of [<code>ENUMS</code>](#module_ENUMS)  

| Param | Type | Description |
| --- | --- | --- |
| ...args | <code>Object</code> | Data to dump |

<a name="module_ENUMS.neoThread"></a>

### ENUMS.neoThread(cb)
Provide a Neo4J connector to the callback.

**Kind**: static method of [<code>ENUMS</code>](#module_ENUMS)  

| Param | Type | Description |
| --- | --- | --- |
| cb | <code>function</code> | Callback cb(connector) |

<a name="module_ENUMS.sqlThread"></a>

### ENUMS.sqlThread(cb)
Provide a MySQL connector to the callback.

**Kind**: static method of [<code>ENUMS</code>](#module_ENUMS)  

| Param | Type | Description |
| --- | --- | --- |
| cb | <code>function</code> | Callback cb(connector) |

<a name="module_ENUMS.Start"></a>

### ENUMS.Start(host, ctx)
Start a unit test using an optional `$(cmd,ctx)` command processor or a `CB()` callback provided in the `ctx` context.  
Inspect a KEY variable, file, or notebook or function with `?KEY`.

**Kind**: static method of [<code>ENUMS</code>](#module_ENUMS)  

| Param | Type | Description |
| --- | --- | --- |
| host | <code>String</code> | Name of hosting module |
| ctx | <code>Object</code> | comamnd context hash |

<a name="module_ENUMS.isFunction"></a>

### ENUMS.isFunction()
**Kind**: static method of [<code>ENUMS</code>](#module_ENUMS)  
<a name="module_ENUMS.isString"></a>

### ENUMS.isString()
**Kind**: static method of [<code>ENUMS</code>](#module_ENUMS)  
<a name="module_ENUMS.isObject"></a>

### ENUMS.isObject()
**Kind**: static method of [<code>ENUMS</code>](#module_ENUMS)  
<a name="module_ENUMS.isNumber"></a>

### ENUMS.isNumber()
**Kind**: static method of [<code>ENUMS</code>](#module_ENUMS)  
<a name="module_ENUMS.Copy"></a>

### ENUMS.Copy(src, tar, deep) ⇒ <code>Object</code>
Copy source hash src to target hash tar.  If the copy is shallow (deep = false), a 
Copy({...}, {}) is equivalent to new Object({...}).  In a deep copy,
(e.g. deep = "."), src keys are treated as keys into the target thusly:

	{	
		A: value,			// sets target[A] = value

		"A.B.C": value, 	// sets target[A][B][C] = value

		"A.B.C.": {			// appends X,Y to target[A][B][C]
			X:value, Y:value, ...
		},	
	}

**Kind**: static method of [<code>ENUMS</code>](#module_ENUMS)  
**Returns**: <code>Object</code> - target hash  

| Param | Type | Description |
| --- | --- | --- |
| src | <code>Object</code> | source hash |
| tar | <code>Object</code> | target hash |
| deep | <code>String</code> | copy key |

<a name="module_ENUMS.Each"></a>

### ENUMS.Each(A, cb)
Enumerate Object A over its keys with callback cb(key,val).

**Kind**: static method of [<code>ENUMS</code>](#module_ENUMS)  

| Param | Type | Description |
| --- | --- | --- |
| A | <code>Object</code> | source object |
| cb | <code>function</code> | callback (key,val) |

<a name="module_ENUMS.Notify"></a>

### ENUMS.Notify()
**Kind**: static method of [<code>ENUMS</code>](#module_ENUMS)  
<a name="module_ENUMS.._Trace"></a>

### ENUMS~\_Trace(msg, ...args)
Trace log message and args.

**Kind**: inner method of [<code>ENUMS</code>](#module_ENUMS)  

| Param | Type | Description |
| --- | --- | --- |
| msg | <code>String</code> | Tracing message |
| ...args | <code>Object</code> | Tracing arguments |

<a name="ENUMS.module_Array"></a>

## Array

* [Array](#ENUMS.module_Array)
    * [~extend()](#ENUMS.module_Array..extend)
    * [~stream(fetch, cb)](#ENUMS.module_Array..stream)
    * [~get(index, ctx)](#ENUMS.module_Array..get) ⇒ <code>Object</code>

<a name="ENUMS.module_Array..extend"></a>

### Array~extend()
extend protototypes of a constructor.

**Kind**: inner method of [<code>Array</code>](#ENUMS.module_Array)  
<a name="ENUMS.module_Array..stream"></a>

### Array~stream(fetch, cb)
Serialize an Array to the callback cb(rec,info) or cb(null,stack) at end given 
	a sync/async fetcher( rec, res ).

**Kind**: inner method of [<code>Array</code>](#ENUMS.module_Array)  

| Param | Type | Description |
| --- | --- | --- |
| fetch | <code>function</code> | Callback to fetch the data sent to the cb |
| cb | <code>function</code> | Callback to process the fetched data. |

**Example**  
```js
Serialize a list:

		function fetcher( rec, info => { 
		});

		[ rec, ...].serial( fetcher, (rec, fails) => {
			if ( rec ) 
				// rec = record being serialized
			else
				// done. fails = number of failed fetches
		}

	
```
**Example**  
```js
### Serialize a string:

		function fetcher( rec, ex => {
			// regexp arguments rec.arg0, rec.arg1, rec.arg2, ...
			// rec.ID = record number being processed
			return "replaced string";
		});

		"string to search".serial( fetcher, regex, "placeholder key", str => { 
			// str = final string with all replacements made
		});

	
```
<a name="ENUMS.module_Array..get"></a>

### Array~get(index, ctx) ⇒ <code>Object</code>
Index an array using a indexor:

		string of the form "to=from & to=eval & to & ... & !where=eval"
		hash of the form {to: from, ...}
		callback of the form (idx,array) => { ... }

	The "!where" clause returns only records having a nonzero eval.

**Kind**: inner method of [<code>Array</code>](#ENUMS.module_Array)  
**Returns**: <code>Object</code> - Indexed data  

| Param | Type | Description |
| --- | --- | --- |
| index | <code>String</code> \| <code>Object</code> \| <code>function</code> | Indexer |
| ctx | <code>Object</code> | Context of functions etc |

**Example**  
```js
[{x:1,y:2},{x:10,y:20}].get("u=x+1&v=sin(y)&!where=x>5",Math)
	{ u: [ 11 ], v: [ 0.9129452507276277 ] }

	
```
**Example**  
```js
[{x:1,y:2},{x:10,y:20}].get("x")
	{ x: [ 1, 10 ] }

	
```
**Example**  
```js
[{x:1,y:2},{x:10,y:20}].get("x&mydata=y")
	{ mydata: [ 2, 20 ], x: [ 1, 10 ] }

	
```
**Example**  
```js
[{x:1,y:2},{x:10,y:20}].get("mydata=[x,y]")
	{ mydata: [ [ 1, 2 ], [ 10, 20 ] ] }

	
```
**Example**  
```js
[{x:1,y:2},{x:10,y:20}].get("mydata=x+1")
	{ mydata: [ 2, 11 ] }

	
```
**Example**  
```js
[{x:1,y:2},{x:10,y:20}].get("",{"!all":1})
	{ x: [ 1, 10 ], y: [ 2, 20 ] }

	
```
**Example**  
```js
[{x:1,y:2},{x:10,y:20}].get("")
	[ { x: 1, y: 2 }, { x: 10, y: 20 } ]

	
```
**Example**  
```js
[{x:1,y:2},{x:10,y:20}].get("u")
	{ u: [ undefined, undefined ] }

	
```
**Example**  
```js
[[1,2,3],[10,20,30]].get("1&0")
	{ '0': [ 1, 10 ], '1': [ 2, 20 ] }	
```
<a name="ENUMS.module_String"></a>

## String

* [String](#ENUMS.module_String)
    * [~stream()](#ENUMS.module_String..stream)
    * [~replaceSync()](#ENUMS.module_String..replaceSync)
    * [~tag(el, at)](#ENUMS.module_String..tag) ⇒ <code>String</code>
    * [~evalJS(ctx)](#ENUMS.module_String..evalJS)
    * [~parseJSON(def)](#ENUMS.module_String..parseJSON)
    * [~chunkFile(path, opts, {Function))](#ENUMS.module_String..chunkFile)
    * [~parseFile(path, opts, cb)](#ENUMS.module_String..parseFile)
    * [~streamFile(path, opts, cb)](#ENUMS.module_String..streamFile)
    * [~trace(msg, req, res)](#ENUMS.module_String..trace)
    * [~serial()](#ENUMS.module_String..serial)

<a name="ENUMS.module_String..stream"></a>

### String~stream()
**Kind**: inner method of [<code>String</code>](#ENUMS.module_String)  
<a name="ENUMS.module_String..replaceSync"></a>

### String~replaceSync()
**Kind**: inner method of [<code>String</code>](#ENUMS.module_String)  
<a name="ENUMS.module_String..tag"></a>

### String~tag(el, at) ⇒ <code>String</code>
Tag url with specified attributes.

**Kind**: inner method of [<code>String</code>](#ENUMS.module_String)  
**Returns**: <code>String</code> - tagged results  

| Param | Type | Description |
| --- | --- | --- |
| el | <code>String</code> | tag html element or one of "?&/:=" |
| at | <code>String</code> | tag attributes = {key: val, ...} |

<a name="ENUMS.module_String..evalJS"></a>

### String~evalJS(ctx)
Run JS against string in specified context.

**Kind**: inner method of [<code>String</code>](#ENUMS.module_String)  

| Param | Type | Description |
| --- | --- | --- |
| ctx | <code>Object</code> | context hash |

<a name="ENUMS.module_String..parseJSON"></a>

### String~parseJSON(def)
Parse string into json or set to default value/callback if invalid json.

**Kind**: inner method of [<code>String</code>](#ENUMS.module_String)  

| Param | Type | Description |
| --- | --- | --- |
| def | <code>function</code> \| <code>Object</code> | default object or callback that returns default |

<a name="ENUMS.module_String..chunkFile"></a>

### String~chunkFile(path, opts, {Function))
Chunk stream at path by splitting into newline-terminated records.
	Callback cb(record) until the limit is reached (until eof when !limit)
	with cb(null) at end.

**Kind**: inner method of [<code>String</code>](#ENUMS.module_String)  

| Param | Type | Description |
| --- | --- | --- |
| path | <code>String</code> | source file |
| opts | <code>Object</code> | {newline,limit} options |
| {Function) |  | cb Callback(record) |

<a name="ENUMS.module_String..parseFile"></a>

### String~parseFile(path, opts, cb)
Parse a csv/txt/json stream at the specified path dependings on if the
	keys is

		[] then record keys are determined by the first header record; 
		[ 'key', 'key', ... ] then header keys were preset; 
		null then raw text records are returned; 
		function then use to parse records.  

	The file is chunked using the (newline,limit) chinkFile parameters.  
	Callsback cb(record) for each record with cb(null) at end.

**Kind**: inner method of [<code>String</code>](#ENUMS.module_String)  

| Param | Type | Description |
| --- | --- | --- |
| path | <code>String</code> | source file |
| opts | <code>Object</code> | {keys,comma,newline,limit} options |
| cb | <code>function</code> | Callback(record || null) |

<a name="ENUMS.module_String..streamFile"></a>

### String~streamFile(path, opts, cb)
Stream file at path containing comma delimited values.  The file is split using the (keys,comma) 
	file splitting parameters, and chunked using the (newline,comma) file chunking parameters. Callsback 
	cb( [record,...] ) with the record batch or cb( null ) at end.

**Kind**: inner method of [<code>String</code>](#ENUMS.module_String)  

| Param | Type | Description |
| --- | --- | --- |
| path | <code>String</code> | source file |
| opts | <code>Object</code> | {keys,comma,newline,limit,batch} options |
| cb | <code>function</code> | Callback( [record,...] || null ) |

<a name="ENUMS.module_String..trace"></a>

### String~trace(msg, req, res)
Trace message to console with optional request to place into syslogs

**Kind**: inner method of [<code>String</code>](#ENUMS.module_String)  

| Param | Type | Description |
| --- | --- | --- |
| msg | <code>String</code> | message to trace |
| req | <code>Object</code> | request { sql, query, client, action, table } |
| res | <code>function</code> | response callback(msg) |

<a name="ENUMS.module_String..serial"></a>

### String~serial()
Serialize this String to the callback(results) given a sync/asyn fetcher(rec,res) where
	rec = {ID, arg0, arg1, ...} contains args produced by regex.  Provide a unique placeholder
	key to back-substitute results.

**Kind**: inner method of [<code>String</code>](#ENUMS.module_String)  
**Example**  
```js
"junkabc;junkdef;"
		.serial( (rec,cb) => cb("$"), /junk([^;]*);/g, "@tag", msg => console.log(msg) )

	produces:

		"$$"
```
</details>

## Contacting, Contributing, Following

Feel free to 
* submit and status [TOTEM issues](http://totem.hopto.org/issues.view) 
* contribute to [TOTEM notebooks](http://totem.hopto.org/shares/notebooks/) 
* revise [TOTEM requirements](http://totem.hopto.org/reqts.view) 
* browse [TOTEM holdings](http://totem.hopto.org/) 
* or follow [TOTEM milestones](http://totem.hopto.org/milestones.view) 

## License

[MIT](LICENSE)

* * *

&copy; 2012 ACMESDS

---
_Source: https://npm.io/package/@totemorg/enums · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
