Skip to content

Commit

Permalink
feat: 删除 compareVersions 并使用具名导出
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Mar 29, 2019
1 parent 2d72b07 commit a896699
Show file tree
Hide file tree
Showing 99 changed files with 275 additions and 289 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"typescript": "^3.3.3333"
},
"dependencies": {
"compare-versions": "^3.4.0",
"is-chinese-phone-number": "^0.1.9"
}
}
4 changes: 2 additions & 2 deletions src/Disposer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable lines-between-class-members */
/* eslint-disable no-dupe-class-members */
import randomString from './randomString'
import { randomString } from './randomString'

export type Dispose = () => void

Expand All @@ -9,7 +9,7 @@ const anonymousKey: string = `__anonymous_${randomString()}__`
/**
* 处置器。
*/
export default class Disposer<N extends string | number = string | number> {
export class Disposer<N extends string | number = string | number> {
/**
* 待处置项目存放容器。
*
Expand Down
2 changes: 1 addition & 1 deletion src/EventBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type EventBusUnsubscribe = () => void
*
* @template T 事件名称及其对应的监听器描述
*/
export default class EventBus<
export class EventBus<
T extends { [key: string]: (...args: any[]) => any } = { [key: string]: (...args: any[]) => any },
K extends Extract<keyof T, string> = Extract<keyof T, string>
> {
Expand Down
4 changes: 2 additions & 2 deletions src/FileData.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import isObject from './isObject'
import { isObject } from './isObject'

const flag = 0x666

export default class FileData<T = any> {
export class FileData<T = any> {
private readonly $$instanceOf = flag

private content: T
Expand Down
30 changes: 15 additions & 15 deletions src/Validator.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import castArray from './castArray'
import isArray from './isArray'
import isChineseIDCardNumber from './isChineseIDCardNumber'
import isChinesePhoneNumber from './isChinesePhoneNumber'
import isEmail from './isEmail'
import isFunction from './isFunction'
import isInteger from './isInteger'
import isNil from './isNil'
import isNumber from './isNumber'
import isNumeric from './isNumeric'
import isPromise from './isPromise'
import isRegExp from './isRegExp'
import isUrl from './isUrl'
import isChineseName from './isChineseName'
import { castArray } from './castArray'
import { isArray } from './isArray'
import { isChineseIDCardNumber } from './isChineseIDCardNumber'
import { isChinesePhoneNumber } from './isChinesePhoneNumber'
import { isEmail } from './isEmail'
import { isFunction } from './isFunction'
import { isInteger } from './isInteger'
import { isNil } from './isNil'
import { isNumber } from './isNumber'
import { isNumeric } from './isNumeric'
import { isPromise } from './isPromise'
import { isRegExp } from './isRegExp'
import { isUrl } from './isUrl'
import { isChineseName } from './isChineseName'

export type ValidatorRuleType = 'number'
| 'integer'
Expand Down Expand Up @@ -112,7 +112,7 @@ function validate<D>(data: D, key: keyof D, rule: ValidatorRule): Promise<boolea
})
}

export default class Validator<R extends ValidatorRules> {
export class Validator<R extends ValidatorRules> {
private rules: R = {} as any

/**
Expand Down
4 changes: 2 additions & 2 deletions src/assign.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import forOwn from './forOwn'
import { forOwn } from './forOwn'

/**
* 分配来源对象的可枚举属性到目标对象上。
Expand All @@ -8,7 +8,7 @@ import forOwn from './forOwn'
* @param sources 来源对象
* @returns 目标对象
*/
export default function assign<T extends Record<string, any>>(target: T, ...sources: any[]): T {
export function assign<T extends Record<string, any>>(target: T, ...sources: any[]): T {
sources.forEach(source => {
forOwn(source, (value, key) => {
target[key as any] = value
Expand Down
2 changes: 1 addition & 1 deletion src/base64Decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { base64Decode as localBase64Decode } from './libs/base64'
* @param str 要解码的字符串
* @returns 解码后的字符串
*/
export default function base64Decode(str: string): string {
export function base64Decode(str: string): string {
return localBase64Decode(str)
}
2 changes: 1 addition & 1 deletion src/base64Encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { base64Encode as localBase64Encode } from './libs/base64'
* @param str 要编码的字符串
* @returns 编码后的字符串
*/
export default function base64Encode(str: string | number): string {
export function base64Encode(str: string | number): string {
return localBase64Encode(String(str))
}
4 changes: 2 additions & 2 deletions src/base64UrlDecode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import base64Decode from './base64Decode'
import { base64Decode } from './base64Decode'

/**
* 返回 base64url 解码后的字符串。
Expand All @@ -7,6 +7,6 @@ import base64Decode from './base64Decode'
* @returns 解码后的字符串
* @see http://www.ietf.org/rfc/rfc4648.txt
*/
export default function base64UrlDecode(str: string): string {
export function base64UrlDecode(str: string): string {
return base64Decode(str.replace(/-/g, '+').replace(/_/g, '/'))
}
4 changes: 2 additions & 2 deletions src/base64UrlEncode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import base64Encode from './base64Encode'
import { base64Encode } from './base64Encode'

/**
* 返回 base64url 编码后的字符串。
Expand All @@ -7,7 +7,7 @@ import base64Encode from './base64Encode'
* @returns 编码后的字符串
* @see http://www.ietf.org/rfc/rfc4648.txt
*/
export default function base64UrlEncode(str: string | number): string {
export function base64UrlEncode(str: string | number): string {
return base64Encode(str)
.replace(/\+/g, '-')
.replace(/\//g, '_')
Expand Down
2 changes: 1 addition & 1 deletion src/bindEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type UnbindEventListener = () => void
* @param listener 事件监听器
* @param [options] 事件选项
*/
export default function bindEvent(
export function bindEvent(
target: EventTarget,
types: BindEventTypes,
listener: EventListenerOrEventListenerObject,
Expand Down
2 changes: 1 addition & 1 deletion src/castArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
* @param value 要处理的值
* @returns 转换后的数组
*/
export default function castArray<T>(value: T | T[]): T[] {
export function castArray<T>(value: T | T[]): T[] {
return Array.isArray(value) ? value : [value]
}
2 changes: 1 addition & 1 deletion src/chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @param [filler] 填充物
* @returns 拆分后的新数组
*/
export default function chunk<T, F = never>(array: T[], size: number, filler?: F): (T | F)[][] {
export function chunk<T, F = never>(array: T[], size: number, filler?: F): (T | F)[][] {
size = Math.max(size, 1)
const result: (T | F)[][] = []
const rows = Math.ceil(array.length / size)
Expand Down
2 changes: 1 addition & 1 deletion src/clamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @param max 最大值
* @returns 结果值
*/
export default function clamp(value: number, min: number, max: number): number {
export function clamp(value: number, min: number, max: number): number {
return (
value <= min
? min
Expand Down
2 changes: 1 addition & 1 deletion src/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @param [indexKey] 作为返回对象的键的列,若不设置,则返回数组
* @returns 列对象或数组
*/
export default function column<
export function column<
O extends Record<string, any>,
CK extends keyof O,
IK extends keyof O,
Expand Down
3 changes: 0 additions & 3 deletions src/compareVersion.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/defaultValue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import forOwn from './forOwn'
import { forOwn } from './forOwn'

export default function defaultValue<
export function defaultValue<
T extends { [key: string]: any },
X extends Partial<T>,
>(getDefaultValue: (obj: X) => T, obj: X): T {
Expand Down
2 changes: 1 addition & 1 deletion src/endsWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
* @param needle 要检索的字符串
* @returns 是(true)或否(false)
*/
export default function endsWith(str: string, needle: string): boolean {
export function endsWith(str: string, needle: string): boolean {
return str.slice(-needle.length) === needle
}
2 changes: 1 addition & 1 deletion src/fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ function fill(
return newArr
}

export default fill
export { fill }
6 changes: 3 additions & 3 deletions src/flexible.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import inBrowser from './inBrowser'
import onResize from './onResize'
import { inBrowser } from './inBrowser'
import { onResize } from './onResize'

/**
* 移动端屏幕适配。
*
* @param [options] 选项
*/
export default function flexible(options: { getViewWidth?: () => number } = {}): void {
export function flexible(options: { getViewWidth?: () => number } = {}): void {
inBrowser(() => {
const docEl = document.documentElement
const dpr = window.devicePixelRatio || 1
Expand Down
4 changes: 2 additions & 2 deletions src/forOwn.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import isObject from './isObject'
import { isObject } from './isObject'

/**
* 遍历对象的可枚举属性。若回调函数返回 false,遍历会提前退出。
*
* @param obj 要遍历的对象
* @param callback 回调函数
*/
export default function forOwn<
export function forOwn<
T extends { [key: string]: any },
K extends keyof T,
>(obj: T, callback: (value: T[K], key: K, obj: T) => any): void {
Expand Down
2 changes: 1 addition & 1 deletion src/formatCurrency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const defaultOptions: FormatCurrencyOptions = {
* @param options 选项
* @returns 格式化后的值
*/
export default function formatCurrency(value: FormatCurrencyValue, options?: FormatCurrencyOptions): string {
export function formatCurrency(value: FormatCurrencyValue, options?: FormatCurrencyOptions): string {
value = Number(value)
options = {
...defaultOptions,
Expand Down
8 changes: 4 additions & 4 deletions src/formatDate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import reduce from './reduce'
import repeat from './repeat'
import toDate from './toDate'
import { reduce } from './reduce'
import { repeat } from './repeat'
import { toDate } from './toDate'

export type FormatDateValue = string | number | Date

Expand All @@ -11,7 +11,7 @@ export type FormatDateValue = string | number | Date
* @param template 格式化模板
* @returns 格式化后的值
*/
export default function formatDate(value: FormatDateValue, template: string): string {
export function formatDate(value: FormatDateValue, template: string): string {
const date = toDate(value)
const patterns: { [key: string]: number } = {
y: date.getFullYear(), // 年
Expand Down
4 changes: 2 additions & 2 deletions src/formatDateDiff.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FormatDateValue } from './formatDate'
import toDate from './toDate'
import { toDate } from './toDate'

const MINUTE = 60
const HOUR = MINUTE * 60
Expand All @@ -19,7 +19,7 @@ const YEAR = DAY * 365
* @param template 格式化模板
* @returns 格式化后的字符串
*/
export default function formatDateDiff(
export function formatDateDiff(
startDate: FormatDateValue,
endDate: FormatDateValue,
template: string,
Expand Down
6 changes: 3 additions & 3 deletions src/get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import has from './has'
import toPath, { ToPathValue } from './toPath'
import { has } from './has'
import { toPath, ToPathValue } from './toPath'

/**
* 根据 `obj` 对象的路径 `path` 获取值。
Expand All @@ -9,7 +9,7 @@ import toPath, { ToPathValue } from './toPath'
* @param [defaultValue] 默认值
* @returns 检索结果
*/
export default function get(obj: object, path: ToPathValue, defaultValue?: any): any {
export function get(obj: object, path: ToPathValue, defaultValue?: any): any {
const normalizedPath = toPath(path)
let last: any = obj
for (let i = 0, len = normalizedPath.length; i < len; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/getType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export type ValueType = (
* @see https://www.ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring
* @see https://www.ecma-international.org/ecma-262/5.1/#sec-8.6.2
*/
export default function getType(value: any): ValueType {
export function getType(value: any): ValueType {
return Object.prototype.toString.call(value).slice(8, -1) as any
}
4 changes: 2 additions & 2 deletions src/groupBy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import get from './get'
import { get } from './get'
import { ToPathValue } from './toPath'

/**
Expand All @@ -8,7 +8,7 @@ import { ToPathValue } from './toPath'
* @param iteratee 迭代值,字符串或数字表示键路径,函数表示以该函数生成 `key`
* @returns 分组结果
*/
export default function groupBy<T>(
export function groupBy<T>(
arr: T[],
iteratee: ToPathValue | ((item: T, index: number) => any),
): { [key: string]: T[] } {
Expand Down
2 changes: 1 addition & 1 deletion src/has.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
* @param key 要检查的键
* @returns 是(true)或否(false)
*/
export default function has(obj: object, key: string): boolean {
export function has(obj: object, key: string): boolean {
return obj != null && Object.prototype.hasOwnProperty.call(obj, key)
}
4 changes: 2 additions & 2 deletions src/inBrowser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isFunction from './isFunction'
import { isFunction } from './isFunction'

let isInBrowser: boolean | undefined

Expand All @@ -8,7 +8,7 @@ let isInBrowser: boolean | undefined
* @param [callback] 在浏览器环境中执行的回调
* @returns 是(true)或否(false)
*/
export default function inBrowser(callback?: () => void): boolean {
export function inBrowser(callback?: () => void): boolean {
if (isInBrowser === undefined) {
isInBrowser = typeof window === 'object'
&& typeof document === 'object'
Expand Down
4 changes: 2 additions & 2 deletions src/inNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isFunction from './isFunction'
import { isFunction } from './isFunction'

let isInNode: boolean | undefined

Expand All @@ -8,7 +8,7 @@ let isInNode: boolean | undefined
* @param [callback] 在 Node 环境中执行的回调
* @returns 是(true)或否(false)
*/
export default function inNode(callback?: () => void): boolean {
export function inNode(callback?: () => void): boolean {
if (isInNode === undefined) {
isInNode = typeof process !== 'undefined'
&& process.versions != null
Expand Down
2 changes: 1 addition & 1 deletion src/inRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type InRangeInterval = '()' | '(]' | '[)' | '[]'
* @param [interval='()'] 区间符号
* @returns `value` 在区间内,返回 `true`;`value` 在区间外,返回 `false`。
*/
export default function inRange(
export function inRange(
value: number,
start: number,
end: number,
Expand Down
8 changes: 4 additions & 4 deletions src/inWechatMiniProgram.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inBrowser from './inBrowser'
import isFunction from './isFunction'
import isObject from './isObject'
import { inBrowser } from './inBrowser'
import { isFunction } from './isFunction'
import { isObject } from './isObject'

let isInWechatMiniProgram: boolean | undefined

Expand All @@ -10,7 +10,7 @@ let isInWechatMiniProgram: boolean | undefined
* @param [callback] 在微信小程序环境中执行的回调
* @returns 是(true)或否(false)
*/
export default function inWechatMiniProgram(callback?: () => void): boolean {
export function inWechatMiniProgram(callback?: () => void): boolean {
if (isInWechatMiniProgram === undefined) {
isInWechatMiniProgram = !inBrowser() && typeof wx !== 'undefined' && isObject(wx) && isFunction(wx.getSystemInfo)
}
Expand Down
Loading

0 comments on commit a896699

Please sign in to comment.