JSDoc all the things!
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user