JSDoc all the things!

This commit is contained in:
2020-08-17 09:44:23 -05:00
parent c2a7c3f914
commit f67ae37923
121 changed files with 2855 additions and 63 deletions

View File

@@ -2,12 +2,19 @@ import { Service } from '../../../../di/src/decorator/Service.ts'
import { Logging } from '../logging/Logging.ts'
import {uuid} from '../../external/std.ts'
/**
* Base service with some utility helpers.
*/
@Service()
export default class Utility {
constructor(
protected logger: Logging
) {}
/**
* Make a deep copy of an object.
* @param target
*/
deep_copy<T>(target: T): T {
if ( target === null )
return target
@@ -33,6 +40,10 @@ export default class Utility {
// TODO deep_merge
/**
* Given a string of a value, try to infer the JavaScript type.
* @param {string} val
*/
infer(val: string): any {
if ( !val ) return undefined
else if ( val.toLowerCase() === 'true' ) return true
@@ -44,6 +55,10 @@ export default class Utility {
else return val
}
/**
* Returns true if the given value is valid JSON.
* @param {string} val
*/
is_json(val: string): boolean {
try {
JSON.parse(val)
@@ -54,6 +69,10 @@ export default class Utility {
}
}
/**
* Get a universally-unique ID string.
* @return string
*/
uuid(): string {
return uuid()
}