@kenote/common
TypeScript icon, indicating that this package has built-in type declarations

1.0.50 • Public • Published

@kenote/common

Based on @kenote common methods and types.

NPM Version NPM Downloads Gratipay

CommonEngine

import { CommonEngine } from '@kenote/common'
import express, { Express } from 'express'
import { RequestListener } from 'http'

export class ServiceEngine extends CommonEngine<Express> {

  constructor (options?: any) {
    super()
    this.__application = express()
  }

  get name (): string {
    return 'express'
  }

  get server (): RequestListener {
    return this.__application
  }
}

HttpClient

import { HttpClient, xhrClient } from '@kenote/common'

// Axios
const client: ClientInstance = axios
// XMLHttpRequest
const client: ClientInstance = xhrClient(new XMLHttpRequest())

const httpClient = (options?: HeaderOptions) => new HttpClient(client, options)

async function start () {
  // Send Get
  await httpClient().get(url, params)
  // Send Post
  await httpClient().post(url, body)
  // Download
  await httpClient().download(url)
  // Upload
  await httpClient().upload(url)
}

DataNodeProxy

import { dataNodeProxy, CommonDataNode } from '@kenote/common'

const data: CommonDataNode[] = [
  {
    key: '1',
    name: 'home'
  }
]

const dataProxy = dataNodeProxy(data)
// Find Single Node
let node = dataProxy.find({ name: 'home' })
console.log( node )
// Add Single Node
dataProxy.add(null, { key: '2', name: 'aaa' })
dataProxy.add('1', { key: '3', name: 'bbb' })
// Update Single Node
dataProxy.update('1', { name: 'ccc' })
// Remove Single Node
dataProxy.remove('1')
// Get Changed Data
console.log( dataProxy.data )

MIT License.

Readme

Keywords

Package Sidebar

Install

npm i @kenote/common

Weekly Downloads

32

Version

1.0.50

License

MIT

Unpacked Size

92.6 kB

Total Files

34

Last publish

Collaborators

  • thondery