@totemorg/enums
v3.26.0
Published
Provide basic enumerators
Downloads
32
Readme
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
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.
Requires: module:os, module:cluster, module:fs, module:http, module:https, module:vm, module:cp, module:crypto, module:stream, module:mysql, module:neo4j-driver, module:nodemailer, module:nodemailer-smtp-transport
Author: ACMESDS
ENUMS.mysql
Stash for MySQL configuation options.
Kind: static constant of ENUMS
ENUMS.neo4j
Stash for Neo4J configuation options.
Kind: static constant of ENUMS
ENUMS.txmail
Stash for Send-Mail configuation options.
Kind: static constant of ENUMS
ENUMS.rxmail
Stash for Receive-Mail configuation options.
Kind: static constant of ENUMS
ENUMS.Log
Dump message to the console.
Kind: static constant of ENUMS
| Param | Type | Description | | --- | --- | --- | | ...args | Object | Data to dump |
ENUMS.neoThread(cb)
Provide a Neo4J connector to the callback.
Kind: static method of ENUMS
| Param | Type | Description | | --- | --- | --- | | cb | function | Callback cb(connector) |
ENUMS.sqlThread(cb)
Provide a MySQL connector to the callback.
Kind: static method of ENUMS
| Param | Type | Description | | --- | --- | --- | | cb | function | Callback cb(connector) |
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 ENUMS
| Param | Type | Description | | --- | --- | --- | | host | String | Name of hosting module | | ctx | Object | comamnd context hash |
ENUMS.isFunction()
Kind: static method of ENUMS
ENUMS.isString()
Kind: static method of ENUMS
ENUMS.isObject()
Kind: static method of ENUMS
ENUMS.isNumber()
Kind: static method of ENUMS
ENUMS.Copy(src, tar, deep) ⇒ Object
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 ENUMS
Returns: Object - target hash
| Param | Type | Description | | --- | --- | --- | | src | Object | source hash | | tar | Object | target hash | | deep | String | copy key |
ENUMS.Each(A, cb)
Enumerate Object A over its keys with callback cb(key,val).
Kind: static method of ENUMS
| Param | Type | Description | | --- | --- | --- | | A | Object | source object | | cb | function | callback (key,val) |
ENUMS.Notify()
Kind: static method of ENUMS
ENUMS~_Trace(msg, ...args)
Trace log message and args.
Kind: inner method of ENUMS
| Param | Type | Description | | --- | --- | --- | | msg | String | Tracing message | | ...args | Object | Tracing arguments |
Array
Array~extend()
extend protototypes of a constructor.
Kind: inner method of Array
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 Array
| Param | Type | Description | | --- | --- | --- | | fetch | function | Callback to fetch the data sent to the cb | | cb | function | Callback to process the fetched data. |
Example
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
### 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
});
Array~get(index, ctx) ⇒ Object
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 Array
Returns: Object - Indexed data
| Param | Type | Description | | --- | --- | --- | | index | String | Object | function | Indexer | | ctx | Object | Context of functions etc |
Example
[{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
[{x:1,y:2},{x:10,y:20}].get("x")
{ x: [ 1, 10 ] }
Example
[{x:1,y:2},{x:10,y:20}].get("x&mydata=y")
{ mydata: [ 2, 20 ], x: [ 1, 10 ] }
Example
[{x:1,y:2},{x:10,y:20}].get("mydata=[x,y]")
{ mydata: [ [ 1, 2 ], [ 10, 20 ] ] }
Example
[{x:1,y:2},{x:10,y:20}].get("mydata=x+1")
{ mydata: [ 2, 11 ] }
Example
[{x:1,y:2},{x:10,y:20}].get("",{"!all":1})
{ x: [ 1, 10 ], y: [ 2, 20 ] }
Example
[{x:1,y:2},{x:10,y:20}].get("")
[ { x: 1, y: 2 }, { x: 10, y: 20 } ]
Example
[{x:1,y:2},{x:10,y:20}].get("u")
{ u: [ undefined, undefined ] }
Example
[[1,2,3],[10,20,30]].get("1&0")
{ '0': [ 1, 10 ], '1': [ 2, 20 ] }
String
String~stream()
Kind: inner method of String
String~replaceSync()
Kind: inner method of String
String~tag(el, at) ⇒ String
Tag url with specified attributes.
Kind: inner method of String
Returns: String - tagged results
| Param | Type | Description | | --- | --- | --- | | el | String | tag html element or one of "?&/:=" | | at | String | tag attributes = {key: val, ...} |
String~evalJS(ctx)
Run JS against string in specified context.
Kind: inner method of String
| Param | Type | Description | | --- | --- | --- | | ctx | Object | context hash |
String~parseJSON(def)
Parse string into json or set to default value/callback if invalid json.
Kind: inner method of String
| Param | Type | Description | | --- | --- | --- | | def | function | Object | default object or callback that returns default |
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 String
| Param | Type | Description | | --- | --- | --- | | path | String | source file | | opts | Object | {newline,limit} options | | {Function) | | cb Callback(record) |
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 String
| Param | Type | Description | | --- | --- | --- | | path | String | source file | | opts | Object | {keys,comma,newline,limit} options | | cb | function | Callback(record || null) |
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 String
| Param | Type | Description | | --- | --- | --- | | path | String | source file | | opts | Object | {keys,comma,newline,limit,batch} options | | cb | function | Callback( [record,...] || null ) |
String~trace(msg, req, res)
Trace message to console with optional request to place into syslogs
Kind: inner method of String
| Param | Type | Description | | --- | --- | --- | | msg | String | message to trace | | req | Object | request { sql, query, client, action, table } | | res | function | response callback(msg) |
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 String
Example
"junkabc;junkdef;"
.serial( (rec,cb) => cb("$"), /junk([^;]*);/g, "@tag", msg => console.log(msg) )
produces:
"$$"
Contacting, Contributing, Following
Feel free to
- submit and status TOTEM issues
- contribute to TOTEM notebooks
- revise TOTEM requirements
- browse TOTEM holdings
- or follow TOTEM milestones
License
© 2012 ACMESDS