ha-script

npm install --save ha-script

Usage no npm install needed!

<script type="module">
  import haScript from 'https://cdn.skypack.dev/ha-script';
</script>

README

常用模块包

npm install --save ha-script

  // typescript
  import __ = require('ha-script')
  // javascript
  const __ = require('ha-script')

「 float 」

如何使用

  let count = __.float.to(0.1 + 0.2) // get 0.3

参数和说明

方法 参数 参数类型
to arg number

「 assert 」

如何使用

  let count1 = __.assert.on("0.2", "Float") // false
  let count2 = __.assert.on(0.2, "Float") // true
  let count2 = __.assert.format("0.2", "Float") // 0.2

参数

方法 参数:基准数值 参数:判断/格式化的类型
on value type
format value type

type 参数必须遵循以下规则,且 type 必须为string 类型!

方法 type 含义
on "String" 是否是字符串
on "Float" 是否是浮点数
on "Int" 是否是整数
on "Datetime" 是否是时间格式的对象
on "Array" 是否是array对象
on "Object" 是否是对象
on "Null" 是否是null
on "Undefined" 是否是undefined

方法 type 含义
format "String" 转换为字符串
format "Float" 转换为浮点数
format "Int" 转换为整数

「 array 」

如何使用

  let list = __.array.range(4) // get [0, 1, 2, 3]
  let newList = __.array.sortBy(
    [{k: 'a', v: 10},{k: 'b', v: 11}], 'v', 'desc') // get {k: 'b', v: 11},{k: 'a', v: 10}

range

参数 含义
len 数组长度

sortBy 对object数组进行排序

参数 含义
list 需要排序的原始数组
key 需要排序的键
type 排序类型:desc 倒序,asc 正序