@homer0/jimple
Version:
An extended version of the Jimple lib, with extra features
29 lines (26 loc) • 892 B
text/typescript
import { Jimple as JimpleMod } from '../jimplemod/index.js';
export class Jimple extends JimpleMod {
/**
* This is a version of the `get` method that doesn't throw if the key doesn't exist. It
* will return `undefined` instead.
*
* @param key The key of the parameter or service to return.
* @returns The object related to the service or the value of the parameter
* associated with the given key.
* @template T The type of the returned object.
*/
try<T = unknown>(key: string): T | undefined {
if (!this.has(key)) {
return undefined;
}
return this.get<T>(key);
}
}
/**
* Shorthand for `new Jimple()`.
*
* @param args The same parameters as the {@link Jimple} constructor.
* @returns A new instance of {@link Jimple}.
*/
export const jimple = (...args: ConstructorParameters<typeof Jimple>): Jimple =>
new Jimple(...args);