ssg-core
TypeScript icon, indicating that this package has built-in type declarations

1.6.0 • Public • Published

Build Status


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'

Readme

Keywords

none

Package Sidebar

Install

npm i ssg-core

Weekly Downloads

2

Version

1.6.0

License

MIT

Unpacked Size

20.6 kB

Total Files

22

Last publish

Collaborators

  • nicobb