@practicaloptimism/program-utility
v2.0.3
Published
A set of useful algorithms and data structures for computer programs
Downloads
471
Maintainers
Keywords
Readme
Program Utility
A few algorithms and data structures for accessing property values of objects by using a property key name list. Also available, you may create a deep copy of objects and/or track the copies by using the ObjectDuplicator data structure.
Website Resources
Source Code | Demos | Video Introduction | Video Tutorial | Live Programming Development Journal
Project Development Status Updates
This Documentation Page was last Updated on Mon Jan 24 2022 15:19:13 GMT-0600 (Central Standard Time)
Installation
Node Package Manager (NPM) Installation
npm install --save @practicaloptimism/program-utility
Script import from JavaScript (requires NPM installation)
import * as programUtility from '@practicaloptimism/program-utility'
HTML Script Import
<script src="https://unpkg.com/@practicaloptimism/program-utility"></script>
Getting Started: Accessing Object Property Value
// Initialize the javascript library instance and the usecase property value
const programUtilityInstance = programUtility.algorithms.createJavascriptLibraryInstance.function()
const objectUtility = programUtilityInstance.usecase.objectUtility.algorithms.object
// Create your javascript object
const object = { name: 'Hitomi', hobbyTable: { dancing: true, watchingScaryMovies: false } }
// Create your property value key list
const propertyKeyList = ['hobbyTable', 'dancing']
// Get your object property value using a key list
const propertyValue = objectUtility.getObjectValue.function(object, propertyKeyList)
// The value printed should return 'true'
console.log(propertyValue)
Getting Started: Creating Object Duplicators
// Initialize the javascript library instance and the usecase property value
const programUtilityInstance = programUtility.algorithms.createJavascriptLibraryInstance.function()
const objectDuplicatorUtility = programUtilityInstance.usecase.objectUtility.algorithms.objectDuplicator
// Create your javascript object
const object = { name: 'Miranda', hobbyTable: { watchingScaryMovies: true, watchingDanceRecitals: false } }
// Create your ObjectDuplicator data structure
const objectDuplicator = objectDuplicatorUtility.createObjectDuplicator.function(object)
// Add a duplicate of your object
objectDuplicatorUtility.addObjectToObjectDuplicator.function(objectDuplicator, 'item1')
// Get the duplicate of your object by using a sting value (objectDuplicateId)
const objectDuplicate = objectDuplicatorUtility.getObjectFromObjectDuplicator.function('item1')
// Change the 'name' property value of the object duplicate
// to showcase that the object and object duplicate
// will have different names since they are deep copies
// of one another.
objectDuplicate.name = 'Susan'
// The value printed should return 'false'
console.log(object.name === objectDuplicate.name)
Application Programmable Interface (API Reference)
constructor(defaultOption) {
super(defaultOption);
Object.assign(this, defaultOption);
}
}
constructor(defaultOption) {
Object.assign(this, defaultOption);
}
}
constructor(defaultOption) {
Object.assign(this, defaultOption);
}
}GetObjectPropertyKeyNameListByDepthFirstOrderFunctionfunction getObjectPropertyKeyNameListByDepthFirstOrderFunction(object, parentKeyNameList, option) { if (!object) { return []; } if (typeof object !== 'object') { return []; } if (!parentKeyNameList || parentKeyNameList.length < 0) { parentKeyNameList = []; } let propertyKeyNameList = []; if ((parentKeyNameList.length > 0) && (option ? !option.booleanObjectKeyNotAllowed : true)) { propertyKeyNameList.push(parentKeyNameList); } for (let objectKey in object) { if (!object.hasOwnProperty(objectKey)) { continue; } const objectPropertyKeyNameList = [...parentKeyNameList, objectKey]; if (option && (option.objectPropertyTreeHeight !== undefined) && (objectPropertyKeyNameList.length > option.objectPropertyTreeHeight)) { return []; } if (typeof object[objectKey] !== 'object') { propertyKeyNameList.push(objectPropertyKeyNameList); continue; } propertyKeyNameList.push(...getObjectPropertyKeyNameListByDepthFirstOrderFunction(object[objectKey], objectPropertyKeyNameList, option)); } return propertyKeyNameList; }GetObjectPropertyKeyNameListByBreadthFirstOrderFunctionfunction getObjectPropertyKeyNameListByBreadthFirstOrderFunction(object, parentKeyNameList, option) { if (!object) { return []; } if (typeof object !== 'object') { return []; } if (!parentKeyNameList || parentKeyNameList.length < 0) { parentKeyNameList = []; } let propertyKeyNameList = Object.keys(object).map(objectKey => { const propertyKeyName = Array.isArray(object) ? parseInt(objectKey, 10) : objectKey; return parentKeyNameList.concat(propertyKeyName); }); let removeObjectKeyNameListReferenceTable = {}; if (option && (option.objectPropertyTreeHeight !== undefined) && (propertyKeyNameList[0].length > option.objectPropertyTreeHeight)) { return []; } for (let i = 0; i < propertyKeyNameList.length; i++) { const objectPropertyKeyNameList = propertyKeyNameList[i]; const objectChildObjectValue = get_object_value__WEBPACK_IMPORTED_MODULE_0_["getObjectValue"].function(object, objectPropertyKeyNameList); const objectChildPropertyKeyNameList = getObjectPropertyKeyNameListByBreadthFirstOrderFunction(objectChildObjectValue, objectPropertyKeyNameList, option); if (option && option.booleanObjectKeyNotAllowed && typeof objectChildObjectValue === 'object') { removeObjectKeyNameListReferenceTable[i] = true; } propertyKeyNameList.push(...objectChildPropertyKeyNameList); } const propertyKeyNameListWithoutObjectKey = []; if (option && option.booleanObjectKeyNotAllowed) { for (let i = 0; i < propertyKeyNameList.length; i++) { const removeKeyNameListIndex = removeObjectKeyNameListReferenceTable[i]; if (removeKeyNameListIndex) { continue; } propertyKeyNameListWithoutObjectKey.push(propertyKeyNameList[i]); } propertyKeyNameList = propertyKeyNameListWithoutObjectKey; } return propertyKeyNameList; }
constructor(defaultOption) {
Object.assign(this, defaultOption);
}
}
Operating Environment: JavaScript Runtime Environments
| JavaScript Runtime Environment | Node.js | Node.js Worker Thread | Web Worker | Google Chrome | Mozilla Firefox | Apple Safari | Beaker Browser | | -- | -- | -- | -- | -- | -- | -- | -- | | Supported Versions of the Runtime | The latest version(s) | The latest version(s) | The latest version(s) | The latest version(s) | The latest version(s) | The latest version(s) | The latest version(s) |
To Resolve Problems and Submit Feature Requests
To report issues or submit feature requests with this projectConstants, please visit Program Utility Issue Tracker
About This Project
Benefits
Features
Limitations
- 🤓 Work-in-progress: This project is a work-in-progress. The project architecture and documentation are being updated regularly. Please learn more about the development life cycle by visiting our live programming development sessions on youtube: https://www.youtube.com/channel/UCIv-rMXljsbxoTUg1MXBi3g
Related Work
There are many projects relating to the application usecases that Program Utility strives to provide. A "project usecase 1", a "project usecase 2", a "project usecase 3" are the primary goal for Program Utility. This is a non-exhaustive list of other projects in the world that are being used and also relate to Program Utility usecase areas-of-interest (well renowned projects are prioritized in our listing order strategy):
| Object Utility Providers | | -- | | -- |
Acknowledgements
License
MIT