0.3.1 • Published 5 months ago

kuu-tools v0.3.1

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
5 months ago

kuu-tools

NPM version Build Status NPM downloads Dependencies

Kuu front-end tools

Install

npm i kuu-tools

Request utils

GET

import { get } from 'kuu-tools'

const data = await get('/member/get?foo=1&bar=2')

POST

import { post } from 'kuu-tools'

const data = await post('/member/signup', { user: 'foo', name: 'bar' })

PUT

import { put } from 'kuu-tools'

const data = await put('/member/signup?foo=1&bar=2', { user: 'foo', name: 'bar' })

DELETE

import { del } from 'kuu-tools'

const data = await del('/member/signup?foo=1&bar=2', { user: 'foo', name: 'bar' })

Model SDK

Create

https://github.com/kuuland/kuu#create-record

import { create } from 'kuu-tools'

// create a role
const data = await create('Role', { Code: 'foo', Name: 'bar' })

// batch create roles
const data = await create('Role', [{ Code: 'foo1', Name: 'bar1' }, { Code: 'foo2', Name: 'bar2' }])

Update

https://github.com/kuuland/kuu#update-fields

import { update } from 'kuu-tools'

// update a param
const data = await update('param', { ID: 5 }, { Value: 'new value', Name: 'foobar' })

// batch updates
const data = await update('param', { ID: { $in: [5, 10, 11] } }, { Value: 'new value' }, true)

Delete

https://github.com/kuuland/kuu#delete-record

import { remove } from 'kuu-tools'

// delete a param
const data = await remove('param', { ID: 5 })

// batch delete
const data = await remove('param', { ID: { $in: [5, 10, 11] } }, true)

// batch and unsoft delete
const data = await remove('param', { ID: { $in: [5, 10, 11] } }, true, true)

Query

https://github.com/kuuland/kuu#query

import { list, one, id } from 'kuu-tools'

// list query
const data = await list('param', { cond: { ID: { $in: [5, 10, 11] } }, page: 3, sort: '-CreatedAt' })

// query only one record
const data = await one('param', { cond: { Name: 'foo' } })

// query by id
const data = await id('param', 11)

i18n

{
     "hello": "你好",
     "welcome": "欢迎 {{name}}"
}
import { withLocale } from 'kuu-tools'

class Param extends React.Component {
  render () {
    return (
      <div>
        <div>{this.props.L('hello', 'Hello')}</div>                         /* => 你好 */
        <div>{this.props.L('not_found', 'Not found')}</div>                 /* => Not found */
        <div>{this.props.L('welcome', 'Welcome Kuu', { name: 'Kuu' }}</div> /* => 欢迎 Kuu */
      </div>
    )
  }
}

export default withLocale(Param)

Notes:

  1. this.props.L can only be used in render, otherwise it will not respond to language updates in real time.
  2. withLocale(Param)
  3. withLocale(withRouter(Param))
  4. withLocale(connect(mapStateToProps)(withRouter(Param)))

Message supports the mustache syntax.

0.3.1

5 months ago

0.3.0

5 months ago

0.2.17

2 years ago

0.2.16

3 years ago

0.2.15

3 years ago

0.2.14

3 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.25

4 years ago

0.1.23

4 years ago

0.1.24

4 years ago

0.1.22

4 years ago

0.1.21

5 years ago

0.1.20

5 years ago

0.1.19

5 years ago

0.1.18

5 years ago

0.1.17

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago