Our Data Handling functions. These support type checking and type coercion and conversion of Objects--ints, string, number, JSON, any--to commonize data handling and type checking.
npm install mcode-data
> node examples
`
Dependencies
- Production
1. None
- Development
1. Node.JS - standard runtime environment
2. JSDocs - our preferred JavaScript documentation system
3. Jest.JS - our preferred JavaScript testing framework
Development
When building a large application its important that the entire team agreed to common data handling practices.
$3
- Get to a terminal session in the local repo folder of your project.
- Use 'npm install' to load the package. It can be used 'stand-alone'...
`
npm install mcode-data
`
$3
This package includes a simple demo module: examples.js.
Running it directly will show you a set of examples for using all the data library functions.
- From your project directory after installation...
`
node .\node_modules\mcode-data\examples
`
...this will deomnstrate thru console logging various uses of the mcode-data functions.
- To test with JEST:
- From the mcode-data package directory...
`
npm install --save-dev jest
npm test
`
Included Functions
These are the functions we want at the ready in any module for development and debug.
| Function | Description | Usage |
| -------------------- | ---------------------------------------------------------------- | -------------------------------------------------------- |
| _Properties_ | | |
| property | Creates a property .set, .get, .validate, and .onchange. | mcode.property(options) |
| contextProperty | Defines a getter/setter proxy to sync instance to context. | mcode.contextProperty(instance, property, contextPath) |
| getProperty | Safely resolves a nested property using an array of keys. | mcode.getProperty(source, pathArray) |
| setProperty | Assigns a nested property on the target object. | mcode.setProperty(target, pathArray, value) |
| _Universal Export_ | | |
| classExport | Exports a class to the global or specified namespace. | mcode.classExport('Namespace', 'ClassName', factory) |
| _Type Checking_ | | |
| isString | Checks the type of an Object for String. | mcode.isString('stringToTest') |
| isObject | Checks the type of an Object for Object. | mcode.isObject(objectName) |
| isArray | Checks the type of an Object for Array. | mcode.isArray(arrayName) |
| isFunction | Checks the type of an Object for Function. | mcode.isFunction(objectName) |
| isNumber | Checks the type of an Object for Number. | mcode.isNumber(102022 or numberName) |
| ifNumber | Checks the type of an Object for Number, returns default. | mcode.ifNumber(102022 or numberName, defaultValue) |
| isNaN | Checks the type of an Object for NaN. | mcode.isNaN(numberName) |
| isJson | Checks the type of an Object for JSON. | mcode.isJson('{'JSON text'}' or objectName) |
| isHtml | Checks the type of an Object for HTML. | mcode.isHtml('<'HTML text'>' or objectName) |
| isDate | Checks the type of an Object for DATE. | mcode.isDate(timestamp) |
| isTimeStamp | Checks the type of an Object for TIME STAMP. | mcode.isTimeStamp(timestamp) |
| default | Returns a default value if an 'item' is 'blank'. | mcode.default(value, default) |
| _Utilities_ | | |
| sleep | Pauses execution for a specified duration in ms. | await mcode.sleep(500); |
| generateRandomId | Generates a random alpha-numeric ID of specified length. | mcode.generateRandomId('myobject') |
| encodeJson | Encodes a JSON object into a Base64 string. | mcode.encodeJson(jsonObject) |
| encodeAttr | Encodes a string for safe inclusion in HTML attributes. | mcode.encodeAttr('stringToEncode') |
| _Type Conversions_ | | |
| octify | Converts a string into octal bytes for log. | mcode.octify(stringToExamine) |
| hexify | Converts a string into hexadecimal bytes for log. | mcode.hexify(stringToExamine) |
| extractId | Extracts the first alpha-numeric ID Field from a string. | mcode.extractId("EP\_GPT13TZ1\_20231115_0800.L5K") |
| fromSnakeCase | Creates a 'Title Case String' from a 'snake-case-string'. | mcode.fromSnakeCase("snake-case-string") |
| toSnakeCase | Creates a 'snake-case-string' from a 'Title Case String'. | mcode.toSnakeCase("Title Case String") |
| _HTTP Support_ | | |
| HTTP_CODES | A STATIC list of common HTTP status codes and messages. | mcode.HTTP_CODES |
| isDomAvailable | Checks if the DOM APIs are available in the current environment. | mcode.isDomAvailable() |
| httpStatus | Converts a http status code into a message. | mcode.httpStatus(code) |
| httpSeverity | Converts a http status code into a log severity. | mcode.httpSeverity(code) |
| _UUID Support_ | | |
| uuidDecode | Decodes a UUID string into a JSON object. | mcode.uuidDecode('LLLLLLLL-MMMM-vHHH-VSSS-CNNNNNNNNNNN') |
$3
We believe in explicit code documentation, for other users, and for our 'future selves'.
JSDocs is a standardized system for documenting functions and data structures that produces three (3) primary outputs:
1. Inline documentation for the coder.
2. Intellisense popup documentation for the coder for every function.
3. External 'reference manual' documentation for your entire code base, if used consistently.
- This entire project--like all our projects--is documented with JSDocs.
- To install JSDocs use, get to a terminal session in the project folder...
`
npm install --save-dev jsdoc
`
- Configure JSDoc processing in...
`
jsdoc.json
`
- To regenerate the JSDocs from all source code, use the following command (from the project root directory)...
`
jsdoc -c .jsdoc.json
``

