Awesome-js
该库提供了业务中常用到工具函数或者正则表达式,欢迎增加更多的函数
ChangeLog
- v1.0.0: 初始化项目
- v2.0.0: 新增websocket封装的类以及GIS相关的有用函数
TodoList
Feature
- Typescript, so beatiful types definition
- Mocha, so the quality of code is can be guaranteed
All methods
export interface Deferred {
resolve: (value?: any) => any
reject: (reason?: any) => void
promise: Promise<any>
}
type wordMap = Map<string, recursiveMap | boolean>
interface recursiveMap extends wordMap {}
export namespace AwesomeRegx {
export const phoneNumber: RegExp;
export const isEmoji: RegExp;
export const privacyMobile: (mobile: string) => string;
export const privacyName: (name: string) => string;
export const chineseAndfullWidthChar: RegExp;
export const https: (url: string) => string;
export const simpleIdentityNo: RegExp;
export const chineseName: RegExp;
export const positiveInteger: RegExp;
export const integer: RegExp;
export const negativeInteger: RegExp;
export const nonnegativeInteger: RegExp;
export const nonPostiveInterger: RegExp;
export const postiveFloat: RegExp;
export const negativeFloat: RegExp;
export const float: RegExp;
export const nonNegativeFloat: RegExp;
export const nonPositiveFloat: RegExp;
export const alphabat: RegExp;
export const upperAlpha: RegExp;
export const lowerAlpha: RegExp;
export const alphaNumWithUnderline: RegExp;
export const DBC: RegExp;
export const emptyLine: RegExp;
export const emptyCharInStartAndEnd: RegExp;
export const chinese: RegExp;
export const email: RegExp;
export const url: RegExp;
export const ip: RegExp;
export const telPhone: RegExp;
export const postalCode: RegExp;
}
export namespace AwesomeHelp {
export function groupBySomeFields<T>(list: T[], fields: (item: T) => any[]): T[][]
export function convertDate(date: Date, format: string): string
export function addFloat(arg1: number, arg2: number): number
export function minusFloat(arg1: number, arg2: number): number
export function divFloat(arg1: number, arg2: number): number
export function timesFloat(arg1: number, arg2: number): number
export function makeDeferred(): Deferred
export function isGenerator(obj: any): boolean
export function isGeneratorFunction(obj: any): boolean
export function isPromise(obj: any): boolean
export function toThousands(num: number): string
export function hiddenNumberExpectSpecified(num: number, expected: number, hiddenStr: string): string
export function makeSensitiveMap(sensitiveWordList: string[]): wordMap
export function checkSensitiveWord(
txt: string,
isQuickSearch?: null,
sensitiveWordsMap?: wordMap): Map<string, { location: number}[] >
export function checkSensitiveWord(
txt: string,
isQuickSearch: boolean,
sensitiveWordsMap?: wordMap): boolean
export function prefixPadding(val: string, length: number, paddingStr?: string): string
export function chunkArray<T>(array: T[], size: number): T[][]
export function shuffleArray<T>(array: Array<T>): T[]
}
export namespace AwesomeGis {
export class Region {
constructor(points: number[][])
public centroid: () => { x: number, y: number}
private area: () => number
}
getAngleByLngLat: (lng_a: number, lat_a: number, lng_b: number, lat_b: number) => number;
getDistance: (lat1: number, lng1: number, lat2: number, lng2: number) => number;
gcj02towgs84: (pos: number[]) => { utm_x: number; utm_y: number };
wgs84togcj02: (utm_x: number, utm_y: number) => number[];
toLatLon: (
easting: number,
northing: number,
zoneNum: number,
zoneLetter: string,
northern?: boolean,
) => number[];
fromLatLon: (
latitude: number,
longitude: number,
forceZoneNum?: number,
) => { easting: number; northing: number; zoneNum: number; zoneLetter: string };
judgePointIsInSpecificArea: (point: DotProps, points: DotProps[]) => boolean;
getTargetLngLatByAngleDistanceFromSourceLngLat: (
lng: number,
lat: number,
brng: number,
dist: number,
) => { lng: number; lat: number };
toRadians: (deg: number) => number;
toDegrees: (rad: number) => number;
export function decodeLatLng(origin: number): number
export function encodeLatLng(origin : number): number
export function getSunRhythm (
date: Date,
lat: number,
lng: number,
height = 0
): {
solarNoon: Date,
nadir: Date,
sunrise: Date,
sunset: Date,
sunriseEnd: Date,
sunsetStart: Date,
dawn: Date,
dusk: Date,
nauticalDawn: Date,
nauticalDusk: Date,
nightEnd: Date,
night: Date,
goldenHourEnd: Date,
goldenHour: Date
}
}
export namespace AwesomeHttp {
export function updateQueryStringParam(baseUrl: string, key: string, value: any): string
export function queryObject2String(path: string, queryObject: object): string
}
export namespace AwesomeWs {
export interface ConfigProps {
url: string;
onMessage?: (data: MessageEvent) => void;
onOpen?: (data: Event) => void;
onClose?: (data: CloseEvent) => void;
onError?: (data: Event) => void;
onReconnect?: (data: any) => void;
onOffline?: (data: any) => void;
sendPing?: (() => void) | null;
interval?: number;
reconnect?: number;
reconnectOnVisibility?: boolean;
}
export default class BaseSocket {
constructor(configs: ConfigProps){}
}
}
How to Use
Can be referenced by the types or the unit testing