@sincerecloud/sc-utils
TypeScript icon, indicating that this package has built-in type declarations

0.0.29 • Public • Published

@sincerecloud/sc-utils

  • 包含HighAxios 类,对axios 二次封装,处理预定状态码
  • 常用object处理方法
  • 中英翻译查询方法
  • 常用正则表达式

安装

npm install axios
npm install @sincerecloud/sc-utils

具体文档请使用 yarn dev 查看

初始化

初始化baseHttp工厂函数

import { HighAxios, getAxios } from '@sincerecloud/sc-utils'

// getAxios 初始化 工厂函数
const baseHttp = getAxios(config)
// or 通过HigAxios 初始化 工厂函数
// const getAxios = HighAxios(config)
// const baseHttp = getAxios(config)

object

查找方法

/**
 * @param {Object} obj 对象
 * @param {String} prototype 属性名
 * @returns Boolean
 */
export const hasOwn = (obj: Object, prototype: string) => {
  return Object.hasOwnProperty.call(obj, prototype);
};

/**
 * 深度获取对象的值
 * @param collection Data source
 * @param keyPath Key path array
 * @param notSetValue Default value for not found
 */
export const getObjectIn = (collection: Object, keyPath: string[], notSetValue:unknown = null) => {
  return keyPath.reduce((rlt: any, keyIndex: string) => {
    return (rlt && rlt[keyIndex] ? rlt[keyIndex] : null)
  }, collection) || notSetValue
}

Package Sidebar

Install

npm i @sincerecloud/sc-utils

Weekly Downloads

1

Version

0.0.29

License

MIT

Unpacked Size

350 kB

Total Files

31

Last publish

Collaborators

  • peter---sss
  • sc-cli1
  • blackdou
  • samson94