3.26.0 • Published 1 year ago

@totemorg/enums v3.26.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

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

ParamTypeDescription
...argsObjectData to dump

ENUMS.neoThread(cb)

Provide a Neo4J connector to the callback.

Kind: static method of ENUMS

ParamTypeDescription
cbfunctionCallback cb(connector)

ENUMS.sqlThread(cb)

Provide a MySQL connector to the callback.

Kind: static method of ENUMS

ParamTypeDescription
cbfunctionCallback 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

ParamTypeDescription
hostStringName of hosting module
ctxObjectcomamnd 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

ParamTypeDescription
srcObjectsource hash
tarObjecttarget hash
deepStringcopy key

ENUMS.Each(A, cb)

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

Kind: static method of ENUMS

ParamTypeDescription
AObjectsource object
cbfunctioncallback (key,val)

ENUMS.Notify()

Kind: static method of ENUMS

ENUMS~_Trace(msg, ...args)

Trace log message and args.

Kind: inner method of ENUMS

ParamTypeDescription
msgStringTracing message
...argsObjectTracing 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

ParamTypeDescription
fetchfunctionCallback to fetch the data sent to the cb
cbfunctionCallback 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

ParamTypeDescription
indexString | Object | functionIndexer
ctxObjectContext 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

ParamTypeDescription
elStringtag html element or one of "?&/:="
atStringtag attributes = {key: val, ...}

String~evalJS(ctx)

Run JS against string in specified context.

Kind: inner method of String

ParamTypeDescription
ctxObjectcontext hash

String~parseJSON(def)

Parse string into json or set to default value/callback if invalid json.

Kind: inner method of String

ParamTypeDescription
deffunction | Objectdefault 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

ParamTypeDescription
pathStringsource file
optsObject{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

ParamTypeDescription
pathStringsource file
optsObject{keys,comma,newline,limit} options
cbfunctionCallback(recordnull)

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

ParamTypeDescription
pathStringsource file
optsObject{keys,comma,newline,limit,batch} options
cbfunctionCallback( record,...null )

String~trace(msg, req, res)

Trace message to console with optional request to place into syslogs

Kind: inner method of String

ParamTypeDescription
msgStringmessage to trace
reqObjectrequest { sql, query, client, action, table }
resfunctionresponse 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

License

MIT


© 2012 ACMESDS

3.20.0

1 year ago

3.22.0

1 year ago

3.21.0

1 year ago

3.23.0

1 year ago

3.15.0

1 year ago

3.14.0

1 year ago

3.19.0

1 year ago

3.18.0

1 year ago

3.13.0

1 year ago

3.26.0

1 year ago

3.25.0

1 year ago

3.9.0

2 years ago

3.11.0

2 years ago

3.8.0

2 years ago

3.10.0

2 years ago

3.7.0

2 years ago

3.6.0

2 years ago

3.12.0

2 years ago

3.5.0

2 years ago

3.4.0

2 years ago

3.3.0

2 years ago

3.2.0

2 years ago

3.1.0

2 years ago

1.36.0

3 years ago

1.37.0

3 years ago

1.34.0

3 years ago

1.35.0

3 years ago

1.29.0

3 years ago

1.38.0

3 years ago

1.39.0

3 years ago

1.32.0

3 years ago

1.33.0

3 years ago

1.30.0

3 years ago

1.31.0

3 years ago

1.28.0

3 years ago

1.27.0

3 years ago

1.26.0

3 years ago

1.25.0

3 years ago

1.24.0

3 years ago

1.23.0

3 years ago

1.21.0

3 years ago