0.0.5 • Published 3 years ago

lizhihua__shared-utils v0.0.5

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

lizhihua__shared-utils

包含模块

  • is

is

// 整体入口引用,通过 tree-shaking 消除无用模块
import { isEmpty } from 'lizhihua__shared-utils'

// 单个入口引用
import { isEmpty } from 'lizhihua__shared-utils/is'

用法

import { isEmpty } from 'lizhihua__shared-utils/test'
isEmpty(null) // true
isEmpty(undefined) // true
isEmpty(false) // true
isEmpty([]) // true
isEmpty({}) // true
isEmpty('') // true
isEmpty(0) // false

humanreadable

用法

import { preciseToZeroDecimals, preciseToTwoDecimals } from 'lizhihua__shared-utils/humanreadable'

utils

用法

import { download, cloneJSON, makeMap, arrayValueToJoinedString, arrayValueToArrayString, stringify } from 'lizhihua__shared-utils/utils'
import { traverseTree } from 'lizhihua__shared-utils/tree'
import { snake2camel, camel2snake } from 'lizhihua__shared-utils/case'

arrayValueToJoinedString([{value:'1'}, {value:'2'}]) // '1,2'
arrayValueToArrayString([{value:'1'}, {value:'2'}]) // ['1','2']

stringify({a:1,b:{c:2}})
/*
{
  "a": 1,
  "b": {
    "c": 2
  }
}
*/

dictCodeToAntdOptions

import { dictCodeToAntdOptions } from 'lizhihua__shared-utils/utils'
dictCodeToAntdOptions([{text: "HTTP", code: "http"}, {text: "HTTPS", code: "https"}])
// [{ value: 'http', label: 'HTTP' }, { value: 'https', label: 'HTTPS' }]

idArrayToAntdOptions

import { idArrayToAntdOptions } from 'lizhihua__shared-utils/utils'
idArrayToAntdOptions([{id: "1", value: "lizhihua1"}, {id: "2", value: "lizhihua2"}])
// [{ value: '1', label: 'lizhihua1' }, { value: '2', label: 'lizhihua2' }]

textArrayToAntdTreeNode

import { textArrayToAntdTreeNode } from 'lizhihua__shared-utils/utils'
textArrayToAntdTreeNode([{text: "Compute Engine", value: "compute_engine"}, {text: "Cloud Run", value: "cloud_run"}])
// [
//   { key: 'compute_engine', value: 'compute_engine', label: 'Compute Engine' },
//   { key: 'cloud_run', value: 'cloud_run', label: 'Cloud Run' },
// ]

textArrayToAntdOptions

import { textArrayToAntdOptions } from 'lizhihua__shared-utils/utils'
textArrayToAntdOptions([{text: "lizhihua1", value: "1"}, {text: "lizhihua2", value: "2"}])
// [
//   { value: '1', label: 'lizhihua1' },
//   { value: '2', label: 'lizhihua2' },
// ]

tester

用于测试的 setTimeout 函数,可以从外部控制

import { setTimeout } from 'lizhihua__shared-utils'
;(async function() {
  const res1 = await setTimeout(1000, true, 'success', null) // 1000 毫秒后,成功并返回 'success'
  console.log(res1) // 'success'
  const res2 = await setTimeout(1000, false, null, 'failure') // 1000 毫秒后,失败并返回 'failure'
  // Uncaught (in promise) failure
})();
0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago