Ssg
Allows you to hook in to function calls of objects. A pre and post method can be provided. These functions wil get run once.
Installation
npm i ssg-core
Example
import {hook} from 'ssg-core'
import {lowerCase} from 'lodash'
namespace Api {
const endpoints = [
'home',
'about',
'faq',
'cookies',
'contact',
'sitemap'
]
export function get(q: string) {
if (endpoints.indexOf(q) !== -1) return q + ' 200'
return q + ' 404'
}
}
function appendMessage(result) {
if (result.indexOf('200') !== -1) return result + ' ok'
else return result + ' not found'
}
hook(Api, 'get', lowerCase, appendMessage)
console.log(Api.get('HOME')) // 'home 200 ok'