# Shared API
# createProxy()
Create a Proxy
instance.
# Type
function createProxy<T extends object = object, R = T>(target: T, handler: ProxyHandler<T>): R;
# Parameters
target: T
The target object to be brokered.
handler: ProxyHandler<T>
Same as handler for
Proxy
👉🏻 Handler Functions (opens new window)
# Return Value
Proxy-wrapped object.
# Example
type Greeter = {
hello(): void;
};
const proxy = createProxy<object, Greeter>(
{},
{
get(_, property) {
if (property === 'hello') {
return () => void console.log('hello');
}
return undefined;
},
}
);
proxy.hello(); // Output: hello
# restorePrefixedString()
Restore a prefixed string.
# Type
function restorePrefixedString(target: string, prefix: string, uncapitalize?: boolean): string;
# Parameters
target: string
Prefixed string.
prefix: string
Prefix string.
uncapitalize?: boolean = true
Whether to automatically change the first letter of the restored string to lower case.
# Return Value
Restored string.
# Example
const prefixed = 'setToken';
const key = restorePrefixedString(prefixed, 'set'); // key = 'token'
# restoreSuffixedString()
Restore a suffixed string.
# Type
function restoreSuffixedString(target: string, suffix: string, autoCapitalizeSuffix?: boolean): string;
# Parameters
target: string
Suffixed string.
suffix: string
Suffix string.
autoCapitalizeSuffix?: boolean = true
Whether to automatically capitalize the first letter of the
suffix
.
# Return Value
Restored string.
# Example
const suffixed = 'tokenState';
const key = restoreSuffixedString(suffixed, 'state'); // key = 'token'