第一次提交
This commit is contained in:
20694
node_modules/@dcloudio/types/html5plus/plus.d.ts
generated
vendored
Normal file
20694
node_modules/@dcloudio/types/html5plus/plus.d.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2
node_modules/@dcloudio/types/index.d.ts
generated
vendored
Normal file
2
node_modules/@dcloudio/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/// <reference path="./uni-app/index.d.ts" />
|
||||
/// <reference path="./html5plus/plus.d.ts" />
|
||||
14
node_modules/@dcloudio/types/package.json
generated
vendored
Normal file
14
node_modules/@dcloudio/types/package.json
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "@dcloudio/types",
|
||||
"version": "2.6.12",
|
||||
"description": "uni-app types",
|
||||
"typings": "index.d.ts",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "fxy060608",
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"vue": "^2.6.10"
|
||||
}
|
||||
}
|
||||
201
node_modules/@dcloudio/types/uni-app/app.d.ts
generated
vendored
Normal file
201
node_modules/@dcloudio/types/uni-app/app.d.ts
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
declare namespace App {
|
||||
interface ReferrerInfo {
|
||||
/**
|
||||
* 来源小程序或公众号或App的 appId
|
||||
*
|
||||
* 以下场景支持返回 referrerInfo.appId:
|
||||
* - 1020(公众号 profile 页相关小程序列表): appId
|
||||
* - 1035(公众号自定义菜单):来源公众号 appId
|
||||
* - 1036(App 分享消息卡片):来源应用 appId
|
||||
* - 1037(小程序打开小程序):来源小程序 appId
|
||||
* - 1038(从另一个小程序返回):来源小程序 appId
|
||||
* - 1043(公众号模板消息):来源公众号 appId
|
||||
*/
|
||||
appId: string;
|
||||
/**
|
||||
* 来源小程序传过来的数据,scene=1037或1038时支持
|
||||
*/
|
||||
extraData?: any;
|
||||
}
|
||||
|
||||
interface LaunchShowOption {
|
||||
/**
|
||||
* 打开小程序的路径
|
||||
*/
|
||||
path: string;
|
||||
/**
|
||||
* 打开小程序的query
|
||||
*/
|
||||
query: AnyObject;
|
||||
/**
|
||||
* 打开小程序的场景值
|
||||
* - 1001: 发现栏小程序主入口,「最近使用」列表(基础库2.2.4版本起包含「我的小程序」列表)
|
||||
* - 1005: 顶部搜索框的搜索结果页
|
||||
* - 1006: 发现栏小程序主入口搜索框的搜索结果页
|
||||
* - 1007: 单人聊天会话中的小程序消息卡片
|
||||
* - 1008: 群聊会话中的小程序消息卡片
|
||||
* - 1011: 扫描二维码
|
||||
* - 1012: 长按图片识别二维码
|
||||
* - 1013: 手机相册选取二维码
|
||||
* - 1014: 小程序模板消息
|
||||
* - 1017: 前往体验版的入口页
|
||||
* - 1019: 微信钱包
|
||||
* - 1020: 公众号 profile 页相关小程序列表
|
||||
* - 1022: 聊天顶部置顶小程序入口
|
||||
* - 1023: 安卓系统桌面图标
|
||||
* - 1024: 小程序 profile 页
|
||||
* - 1025: 扫描一维码
|
||||
* - 1026: 附近小程序列表
|
||||
* - 1027: 顶部搜索框搜索结果页「使用过的小程序」列表
|
||||
* - 1028: 我的卡包
|
||||
* - 1029: 卡券详情页
|
||||
* - 1030: 自动化测试下打开小程序
|
||||
* - 1031: 长按图片识别一维码
|
||||
* - 1032: 手机相册选取一维码
|
||||
* - 1034: 微信支付完成页
|
||||
* - 1035: 公众号自定义菜单
|
||||
* - 1036: App 分享消息卡片
|
||||
* - 1037: 小程序打开小程序
|
||||
* - 1038: 从另一个小程序返回
|
||||
* - 1039: 摇电视
|
||||
* - 1042: 添加好友搜索框的搜索结果页
|
||||
* - 1043: 公众号模板消息
|
||||
* - 1044: 带 shareTicket 的小程序消息卡片
|
||||
* - 1045: 朋友圈广告
|
||||
* - 1046: 朋友圈广告详情页
|
||||
* - 1047: 扫描小程序码
|
||||
* - 1048: 长按图片识别小程序码
|
||||
* - 1049: 手机相册选取小程序码
|
||||
* - 1052: 卡券的适用门店列表
|
||||
* - 1053: 搜一搜的结果页
|
||||
* - 1054: 顶部搜索框小程序快捷入口
|
||||
* - 1056: 音乐播放器菜单
|
||||
* - 1057: 钱包中的银行卡详情页
|
||||
* - 1058: 公众号文章
|
||||
* - 1059: 体验版小程序绑定邀请页
|
||||
* - 1064: 微信连Wi-Fi状态栏
|
||||
* - 1067: 公众号文章广告
|
||||
* - 1068: 附近小程序列表广告
|
||||
* - 1069: 移动应用
|
||||
* - 1071: 钱包中的银行卡列表页
|
||||
* - 1072: 二维码收款页面
|
||||
* - 1073: 客服消息列表下发的小程序消息卡片
|
||||
* - 1074: 公众号会话下发的小程序消息卡片
|
||||
* - 1077: 摇周边
|
||||
* - 1078: 连Wi-Fi成功页
|
||||
* - 1079: 微信游戏中心
|
||||
* - 1081: 客服消息下发的文字链
|
||||
* - 1082: 公众号会话下发的文字链
|
||||
* - 1084: 朋友圈广告原生页
|
||||
* - 1089: 微信聊天主界面下拉,「最近使用」栏(基础库2.2.4版本起包含「我的小程序」栏)
|
||||
* - 1090: 长按小程序右上角菜单唤出最近使用历史
|
||||
* - 1091: 公众号文章商品卡片
|
||||
* - 1092: 城市服务入口
|
||||
* - 1095: 小程序广告组件
|
||||
* - 1096: 聊天记录
|
||||
* - 1097: 微信支付签约页
|
||||
* - 1099: 页面内嵌插件
|
||||
* - 1102: 公众号 profile 页服务预览
|
||||
* - 1103: 发现栏小程序主入口,「我的小程序」列表(基础库2.2.4版本起废弃)
|
||||
* - 1104: 微信聊天主界面下拉,「我的小程序」栏(基础库2.2.4版本起废弃)
|
||||
*/
|
||||
scene: number;
|
||||
/**
|
||||
* 打开小程序的场景值
|
||||
*/
|
||||
shareTicket: string;
|
||||
/**
|
||||
* 当场景为由从另一个小程序或公众号或App打开时,返回此字段
|
||||
*/
|
||||
referrerInfo?: ReferrerInfo;
|
||||
}
|
||||
|
||||
interface PageNotFoundOption {
|
||||
/**
|
||||
* 不存在页面的路径
|
||||
*/
|
||||
path: string;
|
||||
/**
|
||||
* 打开不存在页面的 query
|
||||
*/
|
||||
query: AnyObject;
|
||||
/**
|
||||
* 是否本次启动的首个页面(例如从分享等入口进来,首个页面是开发者配置的分享页面)
|
||||
*/
|
||||
isEntryPage: boolean;
|
||||
}
|
||||
|
||||
interface AppInstance<T extends AnyObject = {}> {
|
||||
/**
|
||||
* 全局对象
|
||||
*/
|
||||
globalData?: AnyObject;
|
||||
/**
|
||||
* 生命周期回调 监听应用初始化
|
||||
*
|
||||
* 应用初始化完成时触发,全局只触发一次。
|
||||
*/
|
||||
onLaunch?(options?: LaunchShowOption): void;
|
||||
/**
|
||||
* 生命周期回调 监听应用显示
|
||||
*
|
||||
* 应用启动,或从后台进入前台显示时触发
|
||||
*/
|
||||
onShow?(options?: LaunchShowOption): void;
|
||||
/**
|
||||
* 生命周期回调 监听应用隐藏
|
||||
*
|
||||
* 应用从前台进入后台时触发
|
||||
*/
|
||||
onHide?(): void;
|
||||
/**
|
||||
* 错误监听函数
|
||||
* 小程序发生脚本错误或 API 调用报错时触发
|
||||
* @param error 错误信息,包含堆栈
|
||||
*/
|
||||
onError?(error: string): void;
|
||||
/**
|
||||
* 页面不存在监听函数
|
||||
*
|
||||
* 应用要打开的页面不存在时触发,会带上页面信息回调该函数
|
||||
*
|
||||
* **注意:**
|
||||
* 1. 如果开发者没有添加 `onPageNotFound` 监听,当跳转页面不存在时,将推入微信客户端原生的页面不存在提示页面。
|
||||
* 2. 如果 `onPageNotFound` 回调中又重定向到另一个不存在的页面,将推入微信客户端原生的页面不存在提示页面,并且不再回调 `onPageNotFound`。
|
||||
*/
|
||||
onPageNotFound?(options: PageNotFoundOption): void;
|
||||
/**
|
||||
* 未处理的 Promise 拒绝事件监听函数
|
||||
*/
|
||||
onUnhandledRejection?(options: UniApp.OnUnhandledRejectionCallbackResult): void;
|
||||
/**
|
||||
* 监听系统主题变化
|
||||
*/
|
||||
onThemeChange?(options: UniApp.OnThemeChangeCallbackResult): void;
|
||||
/**
|
||||
* 监听 nvue 页面消息
|
||||
*
|
||||
* nvue 页面使用 `uni.postMessage` 发送消息时触发
|
||||
*/
|
||||
onUniNViewMessage?(options: AnyObject): void;
|
||||
}
|
||||
|
||||
type AppConstructor = <T extends AnyObject & AppInstance>(
|
||||
options: AppInstance<T> & T,
|
||||
) => void;
|
||||
|
||||
interface GetAppOption {
|
||||
/**
|
||||
* 在 `App` 未定义时返回默认实现。当App被调用时,默认实现中定义的属性会被覆盖合并到App中。一般用于独立分包
|
||||
*/
|
||||
allowDefault: boolean;
|
||||
}
|
||||
|
||||
type GetApp = <T extends AnyObject>(opts?: GetAppOption) => AppInstance<T> & T;
|
||||
}
|
||||
|
||||
declare const getApp: App.GetApp;
|
||||
|
||||
declare const createApp: any;
|
||||
declare const createPage: any;
|
||||
declare const createComponent: any;
|
||||
3097
node_modules/@dcloudio/types/uni-app/cloud.d.ts
generated
vendored
Normal file
3097
node_modules/@dcloudio/types/uni-app/cloud.d.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
7
node_modules/@dcloudio/types/uni-app/common.d.ts
generated
vendored
Normal file
7
node_modules/@dcloudio/types/uni-app/common.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
interface AnyObject {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
type KVInfer<T> = { [K in keyof T]: T[K] };
|
||||
|
||||
type Void<T> = T | undefined | null;
|
||||
7
node_modules/@dcloudio/types/uni-app/index.d.ts
generated
vendored
Normal file
7
node_modules/@dcloudio/types/uni-app/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/// <reference path="./app.d.ts" />
|
||||
/// <reference path="./common.d.ts" />
|
||||
/// <reference path="./page.d.ts" />
|
||||
/// <reference path="./uni.d.ts" />
|
||||
/// <reference path="./cloud.d.ts" />
|
||||
/// <reference path="./vue.d.ts" />
|
||||
/// <reference path="../html5plus/plus.d.ts" />
|
||||
244
node_modules/@dcloudio/types/uni-app/page.d.ts
generated
vendored
Normal file
244
node_modules/@dcloudio/types/uni-app/page.d.ts
generated
vendored
Normal file
@@ -0,0 +1,244 @@
|
||||
declare namespace Page {
|
||||
interface CustomShareContent {
|
||||
/**
|
||||
* 转发标题。默认值:当前应用名称
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* 转发路径,必须是以 / 开头的完整路径。默认值:当前页面 path
|
||||
*/
|
||||
path?: string;
|
||||
/**
|
||||
* 自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径。支持PNG及JPG。显示图片长宽比是 5:4,默认值:使用默认截图
|
||||
*/
|
||||
imageUrl?: string;
|
||||
}
|
||||
|
||||
interface ShareTimelineContent {
|
||||
/**
|
||||
* 自定义标题。默认值:当前小程序名称
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* 自定义页面路径中携带的参数
|
||||
*/
|
||||
path?: string;
|
||||
/**
|
||||
* 自定义图片路径,可以是本地文件或者网络图片。支持 PNG 及 JPG,显示图片长宽比是 1:1。
|
||||
*/
|
||||
imageUrl?: string;
|
||||
}
|
||||
|
||||
interface PageScrollOption {
|
||||
/**
|
||||
* 页面在垂直方向已滚动的距离(单位 px)
|
||||
*/
|
||||
scrollTop: number;
|
||||
}
|
||||
|
||||
interface ShareAppMessageOption {
|
||||
/**
|
||||
* 转发事件来源。
|
||||
* 可选值:
|
||||
* - `button`:页面内转发按钮;
|
||||
* - `menu`:右上角转发菜单。
|
||||
*/
|
||||
from: "button" | "menu";
|
||||
/**
|
||||
* 如果 `from` 值是 `button`,则 `target` 是触发这次转发事件的 `button`,否则为 `undefined`
|
||||
*/
|
||||
target: any;
|
||||
/**
|
||||
* 页面中包含 `<web-view>` 组件时,返回当前 `<web-view>` 的 url
|
||||
*/
|
||||
webViewUrl?: string;
|
||||
}
|
||||
|
||||
interface AddToFavoritesOption {
|
||||
/**
|
||||
* 页面中包含 `<web-view>` 组件时,返回当前 `<web-view>` 的 url
|
||||
*/
|
||||
webviewUrl: string
|
||||
}
|
||||
|
||||
interface CustomFavoritesContent {
|
||||
/**
|
||||
* 自定义标题,默认值:页面标题或账号名称
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* 自定义 query 字段
|
||||
*/
|
||||
path?: string;
|
||||
/**
|
||||
* 自定义图片,显示图片长宽比为 1:1
|
||||
*/
|
||||
imageUrl?: string;
|
||||
}
|
||||
|
||||
interface TabItemTapOption {
|
||||
/**
|
||||
* 被点击 tabItem 的序号,从0开始
|
||||
*/
|
||||
index: string;
|
||||
/**
|
||||
* 被点击 tabItem 的页面路径
|
||||
*/
|
||||
pagePath: string;
|
||||
/**
|
||||
* 被点击 tabItem 的按钮文字
|
||||
*/
|
||||
text: string;
|
||||
}
|
||||
|
||||
interface NavigationBarButtonTapOption {
|
||||
/**
|
||||
* 原生标题栏按钮数组的下标
|
||||
*/
|
||||
index: string;
|
||||
}
|
||||
|
||||
interface BackPressOption {
|
||||
/**
|
||||
* - backbutton 顶部导航栏左边的返回按钮或 Android 实体返回键
|
||||
* - navigateBack 返回 API,即 uni.navigateBack()
|
||||
*/
|
||||
from: 'backbutton' | 'navigateBack';
|
||||
}
|
||||
|
||||
interface NavigationBarSearchInputEvent {
|
||||
/**
|
||||
* 搜索输入框输入内容
|
||||
*/
|
||||
text: string;
|
||||
}
|
||||
|
||||
interface PageInstanceBaseProps<D extends AnyObject = any> {
|
||||
/**
|
||||
* 到当前页面的路径,类型为 `String`
|
||||
*/
|
||||
route?: string;
|
||||
}
|
||||
|
||||
interface PageInstance<D extends AnyObject = any, T extends AnyObject = any> extends PageInstanceBaseProps<D> {
|
||||
/**
|
||||
* 生命周期回调 监听页面初始化
|
||||
*
|
||||
* 页面初始化时触发。一个页面只会调用一次,可以在 onInit 的参数中获取打开当前页面路径中的参数。
|
||||
* @param query 打开当前页面路径中的参数
|
||||
*/
|
||||
onInit?(query?: AnyObject): void;
|
||||
/**
|
||||
* 生命周期回调 监听页面加载
|
||||
*
|
||||
* 页面加载时触发。一个页面只会调用一次,可以在 onLoad 的参数中获取打开当前页面路径中的参数。
|
||||
* @param query 打开当前页面路径中的参数
|
||||
*/
|
||||
onLoad?(query?: AnyObject): void;
|
||||
/**
|
||||
* 生命周期回调 监听页面显示
|
||||
*
|
||||
* 页面显示/切入前台时触发。
|
||||
*/
|
||||
onShow?(): void;
|
||||
/**
|
||||
* 生命周期回调 监听页面初次渲染完成
|
||||
*
|
||||
* 页面初次渲染完成时触发。一个页面只会调用一次,代表页面已经准备妥当,可以和视图层进行交互。
|
||||
*/
|
||||
onReady?(): void;
|
||||
/**
|
||||
* 生命周期回调 监听页面隐藏
|
||||
*
|
||||
* 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,应用切入后台等。
|
||||
*/
|
||||
onHide?(): void;
|
||||
/**
|
||||
* 生命周期回调 监听页面卸载
|
||||
*
|
||||
* 页面卸载时触发。如 `redirectTo` 或 `navigateBack` 到其他页面时。
|
||||
*/
|
||||
onUnload?(): void;
|
||||
/**
|
||||
* 监听用户下拉动作
|
||||
* - 需要在 `pages.json` 的页面配置中开启 `enablePullDownRefresh` 。
|
||||
* - 可以通过 `uni.startPullDownRefresh` 触发下拉刷新,调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
|
||||
* - 当处理完数据刷新后,`uni.stopPullDownRefresh` 可以停止当前页面的下拉刷新。
|
||||
*/
|
||||
onPullDownRefresh?(): void;
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
* - 可以在 `pages.json` 的页面配置中设置触发距离 `onReachBottomDistance` 。
|
||||
* - 在触发距离内滑动期间,本事件只会被触发一次。
|
||||
*/
|
||||
onReachBottom?(): void;
|
||||
/**
|
||||
* 用户点击右上角转发
|
||||
*
|
||||
* 监听用户点击页面内转发按钮(`<button>` 组件 `open-type="share"`)或右上角菜单“转发”按钮的行为,并自定义转发内容。
|
||||
* @param options 分享发起来源参数
|
||||
* @return 转发内容
|
||||
*/
|
||||
onShareAppMessage?(options: ShareAppMessageOption): CustomShareContent;
|
||||
/**
|
||||
* 用户点击右上角转发到朋友圈
|
||||
*
|
||||
* 监听右上角菜单“分享到朋友圈”按钮的行为,并自定义发享内容。
|
||||
*/
|
||||
onShareTimeline?(): ShareTimelineContent;
|
||||
/**
|
||||
* 用户点击右上角收藏
|
||||
*
|
||||
* 监听用户点击右上角菜单“收藏”按钮的行为,并自定义收藏内容。
|
||||
*/
|
||||
onAddToFavorites?(options: AddToFavoritesOption): CustomFavoritesContent;
|
||||
/**
|
||||
* 页面滚动触发事件的处理函数
|
||||
*
|
||||
* 监听用户滑动页面事件。
|
||||
* @param options 页面滚动参数
|
||||
*/
|
||||
onPageScroll?(options: PageScrollOption): void;
|
||||
/**
|
||||
* 页面尺寸改变时触发
|
||||
* @param options 页面滚动参数
|
||||
*/
|
||||
onResize?(options: PageScrollOption): void;
|
||||
/**
|
||||
* 当前是 tab 页时,点击 tab 时触发
|
||||
* @param options tab 点击参数
|
||||
*/
|
||||
onTabItemTap?(options: TabItemTapOption): void;
|
||||
/**
|
||||
* 监听原生标题栏按钮点击事件
|
||||
* @param options tab 点击参数
|
||||
*/
|
||||
onNavigationBarButtonTap?(options: NavigationBarButtonTapOption): void;
|
||||
/**
|
||||
* 监听页面返回
|
||||
* @param options tab 点击参数
|
||||
* @return 返回 `true` 时阻止页面返回
|
||||
*/
|
||||
onBackPress?(options: BackPressOption): any;
|
||||
/**
|
||||
* 监听原生标题栏搜索输入框输入内容变化事件
|
||||
*/
|
||||
onNavigationBarSearchInputChanged?(event: NavigationBarSearchInputEvent): void;
|
||||
/**
|
||||
* 监听原生标题栏搜索输入框搜索事件,用户点击软键盘上的“搜索”按钮时触发。
|
||||
*/
|
||||
onNavigationBarSearchInputConfirmed?(event: NavigationBarSearchInputEvent): void;
|
||||
/**
|
||||
* 监听原生标题栏搜索输入框点击事件
|
||||
*/
|
||||
onNavigationBarSearchInputClicked?(): void;
|
||||
}
|
||||
|
||||
type PageConstructor = <T extends AnyObject & PageInstance>(
|
||||
options: PageInstance<AnyObject, T> & T,
|
||||
) => void;
|
||||
|
||||
type GetCurrentPages = <T extends AnyObject = {}>() => Array<PageInstance<AnyObject, T> & T>;
|
||||
}
|
||||
|
||||
declare const getCurrentPages: Page.GetCurrentPages;
|
||||
16452
node_modules/@dcloudio/types/uni-app/uni.d.ts
generated
vendored
Normal file
16452
node_modules/@dcloudio/types/uni-app/uni.d.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11
node_modules/@dcloudio/types/uni-app/vue.d.ts
generated
vendored
Normal file
11
node_modules/@dcloudio/types/uni-app/vue.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import Vue from "vue";
|
||||
|
||||
declare module "vue/types/options" {
|
||||
type Hooks = App.AppInstance & Page.PageInstance;
|
||||
interface ComponentOptions<V extends Vue> extends Hooks {
|
||||
/**
|
||||
* 组件类型
|
||||
*/
|
||||
mpType?: string;
|
||||
}
|
||||
}
|
||||
152
node_modules/commander/History.md
generated
vendored
Normal file
152
node_modules/commander/History.md
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
|
||||
1.1.1 / 2012-11-20
|
||||
==================
|
||||
|
||||
* add more sub-command padding
|
||||
* fix .usage() when args are present. Closes #106
|
||||
|
||||
1.1.0 / 2012-11-16
|
||||
==================
|
||||
|
||||
* add git-style executable subcommand support. Closes #94
|
||||
|
||||
1.0.5 / 2012-10-09
|
||||
==================
|
||||
|
||||
* fix `--name` clobbering. Closes #92
|
||||
* fix examples/help. Closes #89
|
||||
|
||||
1.0.4 / 2012-09-03
|
||||
==================
|
||||
|
||||
* add `outputHelp()` method.
|
||||
|
||||
1.0.3 / 2012-08-30
|
||||
==================
|
||||
|
||||
* remove invalid .version() defaulting
|
||||
|
||||
1.0.2 / 2012-08-24
|
||||
==================
|
||||
|
||||
* add `--foo=bar` support [arv]
|
||||
* fix password on node 0.8.8. Make backward compatible with 0.6 [focusaurus]
|
||||
|
||||
1.0.1 / 2012-08-03
|
||||
==================
|
||||
|
||||
* fix issue #56
|
||||
* fix tty.setRawMode(mode) was moved to tty.ReadStream#setRawMode() (i.e. process.stdin.setRawMode())
|
||||
|
||||
1.0.0 / 2012-07-05
|
||||
==================
|
||||
|
||||
* add support for optional option descriptions
|
||||
* add defaulting of `.version()` to package.json's version
|
||||
|
||||
0.6.1 / 2012-06-01
|
||||
==================
|
||||
|
||||
* Added: append (yes or no) on confirmation
|
||||
* Added: allow node.js v0.7.x
|
||||
|
||||
0.6.0 / 2012-04-10
|
||||
==================
|
||||
|
||||
* Added `.prompt(obj, callback)` support. Closes #49
|
||||
* Added default support to .choose(). Closes #41
|
||||
* Fixed the choice example
|
||||
|
||||
0.5.1 / 2011-12-20
|
||||
==================
|
||||
|
||||
* Fixed `password()` for recent nodes. Closes #36
|
||||
|
||||
0.5.0 / 2011-12-04
|
||||
==================
|
||||
|
||||
* Added sub-command option support [itay]
|
||||
|
||||
0.4.3 / 2011-12-04
|
||||
==================
|
||||
|
||||
* Fixed custom help ordering. Closes #32
|
||||
|
||||
0.4.2 / 2011-11-24
|
||||
==================
|
||||
|
||||
* Added travis support
|
||||
* Fixed: line-buffered input automatically trimmed. Closes #31
|
||||
|
||||
0.4.1 / 2011-11-18
|
||||
==================
|
||||
|
||||
* Removed listening for "close" on --help
|
||||
|
||||
0.4.0 / 2011-11-15
|
||||
==================
|
||||
|
||||
* Added support for `--`. Closes #24
|
||||
|
||||
0.3.3 / 2011-11-14
|
||||
==================
|
||||
|
||||
* Fixed: wait for close event when writing help info [Jerry Hamlet]
|
||||
|
||||
0.3.2 / 2011-11-01
|
||||
==================
|
||||
|
||||
* Fixed long flag definitions with values [felixge]
|
||||
|
||||
0.3.1 / 2011-10-31
|
||||
==================
|
||||
|
||||
* Changed `--version` short flag to `-V` from `-v`
|
||||
* Changed `.version()` so it's configurable [felixge]
|
||||
|
||||
0.3.0 / 2011-10-31
|
||||
==================
|
||||
|
||||
* Added support for long flags only. Closes #18
|
||||
|
||||
0.2.1 / 2011-10-24
|
||||
==================
|
||||
|
||||
* "node": ">= 0.4.x < 0.7.0". Closes #20
|
||||
|
||||
0.2.0 / 2011-09-26
|
||||
==================
|
||||
|
||||
* Allow for defaults that are not just boolean. Default peassignment only occurs for --no-*, optional, and required arguments. [Jim Isaacs]
|
||||
|
||||
0.1.0 / 2011-08-24
|
||||
==================
|
||||
|
||||
* Added support for custom `--help` output
|
||||
|
||||
0.0.5 / 2011-08-18
|
||||
==================
|
||||
|
||||
* Changed: when the user enters nothing prompt for password again
|
||||
* Fixed issue with passwords beginning with numbers [NuckChorris]
|
||||
|
||||
0.0.4 / 2011-08-15
|
||||
==================
|
||||
|
||||
* Fixed `Commander#args`
|
||||
|
||||
0.0.3 / 2011-08-15
|
||||
==================
|
||||
|
||||
* Added default option value support
|
||||
|
||||
0.0.2 / 2011-08-15
|
||||
==================
|
||||
|
||||
* Added mask support to `Command#password(str[, mask], fn)`
|
||||
* Added `Command#password(str, fn)`
|
||||
|
||||
0.0.1 / 2010-01-03
|
||||
==================
|
||||
|
||||
* Initial release
|
||||
7
node_modules/commander/Makefile
generated
vendored
Normal file
7
node_modules/commander/Makefile
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
TESTS = $(shell find test/test.*.js)
|
||||
|
||||
test:
|
||||
@./test/run $(TESTS)
|
||||
|
||||
.PHONY: test
|
||||
270
node_modules/commander/Readme.md
generated
vendored
Normal file
270
node_modules/commander/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,270 @@
|
||||
# Commander.js
|
||||
|
||||
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/visionmedia/commander).
|
||||
|
||||
[](http://travis-ci.org/visionmedia/commander.js)
|
||||
|
||||
## Installation
|
||||
|
||||
$ npm install commander
|
||||
|
||||
## Option parsing
|
||||
|
||||
Options with commander are defined with the `.option()` method, also serving as documentation for the options. The example below parses args and options from `process.argv`, leaving remaining args as the `program.args` array which were not consumed by options.
|
||||
|
||||
```js
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var program = require('commander');
|
||||
|
||||
program
|
||||
.version('0.0.1')
|
||||
.option('-p, --peppers', 'Add peppers')
|
||||
.option('-P, --pineapple', 'Add pineapple')
|
||||
.option('-b, --bbq', 'Add bbq sauce')
|
||||
.option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble')
|
||||
.parse(process.argv);
|
||||
|
||||
console.log('you ordered a pizza with:');
|
||||
if (program.peppers) console.log(' - peppers');
|
||||
if (program.pineapple) console.log(' - pineappe');
|
||||
if (program.bbq) console.log(' - bbq');
|
||||
console.log(' - %s cheese', program.cheese);
|
||||
```
|
||||
|
||||
Short flags may be passed as a single arg, for example `-abc` is equivalent to `-a -b -c`. Multi-word options such as "--template-engine" are camel-cased, becoming `program.templateEngine` etc.
|
||||
|
||||
## Automated --help
|
||||
|
||||
The help information is auto-generated based on the information commander already knows about your program, so the following `--help` info is for free:
|
||||
|
||||
```
|
||||
$ ./examples/pizza --help
|
||||
|
||||
Usage: pizza [options]
|
||||
|
||||
Options:
|
||||
|
||||
-V, --version output the version number
|
||||
-p, --peppers Add peppers
|
||||
-P, --pineapple Add pineappe
|
||||
-b, --bbq Add bbq sauce
|
||||
-c, --cheese <type> Add the specified type of cheese [marble]
|
||||
-h, --help output usage information
|
||||
|
||||
```
|
||||
|
||||
## Coercion
|
||||
|
||||
```js
|
||||
function range(val) {
|
||||
return val.split('..').map(Number);
|
||||
}
|
||||
|
||||
function list(val) {
|
||||
return val.split(',');
|
||||
}
|
||||
|
||||
program
|
||||
.version('0.0.1')
|
||||
.usage('[options] <file ...>')
|
||||
.option('-i, --integer <n>', 'An integer argument', parseInt)
|
||||
.option('-f, --float <n>', 'A float argument', parseFloat)
|
||||
.option('-r, --range <a>..<b>', 'A range', range)
|
||||
.option('-l, --list <items>', 'A list', list)
|
||||
.option('-o, --optional [value]', 'An optional value')
|
||||
.parse(process.argv);
|
||||
|
||||
console.log(' int: %j', program.integer);
|
||||
console.log(' float: %j', program.float);
|
||||
console.log(' optional: %j', program.optional);
|
||||
program.range = program.range || [];
|
||||
console.log(' range: %j..%j', program.range[0], program.range[1]);
|
||||
console.log(' list: %j', program.list);
|
||||
console.log(' args: %j', program.args);
|
||||
```
|
||||
|
||||
## Custom help
|
||||
|
||||
You can display arbitrary `-h, --help` information
|
||||
by listening for "--help". Commander will automatically
|
||||
exit once you are done so that the remainder of your program
|
||||
does not execute causing undesired behaviours, for example
|
||||
in the following executable "stuff" will not output when
|
||||
`--help` is used.
|
||||
|
||||
```js
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var program = require('../');
|
||||
|
||||
function list(val) {
|
||||
return val.split(',').map(Number);
|
||||
}
|
||||
|
||||
program
|
||||
.version('0.0.1')
|
||||
.option('-f, --foo', 'enable some foo')
|
||||
.option('-b, --bar', 'enable some bar')
|
||||
.option('-B, --baz', 'enable some baz');
|
||||
|
||||
// must be before .parse() since
|
||||
// node's emit() is immediate
|
||||
|
||||
program.on('--help', function(){
|
||||
console.log(' Examples:');
|
||||
console.log('');
|
||||
console.log(' $ custom-help --help');
|
||||
console.log(' $ custom-help -h');
|
||||
console.log('');
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
console.log('stuff');
|
||||
```
|
||||
|
||||
yielding the following help output:
|
||||
|
||||
```
|
||||
|
||||
Usage: custom-help [options]
|
||||
|
||||
Options:
|
||||
|
||||
-h, --help output usage information
|
||||
-V, --version output the version number
|
||||
-f, --foo enable some foo
|
||||
-b, --bar enable some bar
|
||||
-B, --baz enable some baz
|
||||
|
||||
Examples:
|
||||
|
||||
$ custom-help --help
|
||||
$ custom-help -h
|
||||
|
||||
```
|
||||
|
||||
## .prompt(msg, fn)
|
||||
|
||||
Single-line prompt:
|
||||
|
||||
```js
|
||||
program.prompt('name: ', function(name){
|
||||
console.log('hi %s', name);
|
||||
});
|
||||
```
|
||||
|
||||
Multi-line prompt:
|
||||
|
||||
```js
|
||||
program.prompt('description:', function(name){
|
||||
console.log('hi %s', name);
|
||||
});
|
||||
```
|
||||
|
||||
Coercion:
|
||||
|
||||
```js
|
||||
program.prompt('Age: ', Number, function(age){
|
||||
console.log('age: %j', age);
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
program.prompt('Birthdate: ', Date, function(date){
|
||||
console.log('date: %s', date);
|
||||
});
|
||||
```
|
||||
|
||||
## .password(msg[, mask], fn)
|
||||
|
||||
Prompt for password without echoing:
|
||||
|
||||
```js
|
||||
program.password('Password: ', function(pass){
|
||||
console.log('got "%s"', pass);
|
||||
process.stdin.destroy();
|
||||
});
|
||||
```
|
||||
|
||||
Prompt for password with mask char "*":
|
||||
|
||||
```js
|
||||
program.password('Password: ', '*', function(pass){
|
||||
console.log('got "%s"', pass);
|
||||
process.stdin.destroy();
|
||||
});
|
||||
```
|
||||
|
||||
## .confirm(msg, fn)
|
||||
|
||||
Confirm with the given `msg`:
|
||||
|
||||
```js
|
||||
program.confirm('continue? ', function(ok){
|
||||
console.log(' got %j', ok);
|
||||
});
|
||||
```
|
||||
|
||||
## .choose(list, fn)
|
||||
|
||||
Let the user choose from a `list`:
|
||||
|
||||
```js
|
||||
var list = ['tobi', 'loki', 'jane', 'manny', 'luna'];
|
||||
|
||||
console.log('Choose the coolest pet:');
|
||||
program.choose(list, function(i){
|
||||
console.log('you chose %d "%s"', i, list[i]);
|
||||
});
|
||||
```
|
||||
|
||||
## .outputHelp()
|
||||
|
||||
Output help information without exiting.
|
||||
|
||||
## .help()
|
||||
|
||||
Output help information and exit immediately.
|
||||
|
||||
## Links
|
||||
|
||||
- [API documentation](http://visionmedia.github.com/commander.js/)
|
||||
- [ascii tables](https://github.com/LearnBoost/cli-table)
|
||||
- [progress bars](https://github.com/visionmedia/node-progress)
|
||||
- [more progress bars](https://github.com/substack/node-multimeter)
|
||||
- [examples](https://github.com/visionmedia/commander.js/tree/master/examples)
|
||||
|
||||
## License
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
1131
node_modules/commander/index.js
generated
vendored
Normal file
1131
node_modules/commander/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
13
node_modules/commander/package.json
generated
vendored
Normal file
13
node_modules/commander/package.json
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "commander"
|
||||
, "version": "1.1.1"
|
||||
, "description": "the complete solution for node.js command-line programs"
|
||||
, "keywords": ["command", "option", "parser", "prompt", "stdin"]
|
||||
, "author": "TJ Holowaychuk <tj@vision-media.ca>"
|
||||
, "repository": { "type": "git", "url": "https://github.com/visionmedia/commander.js.git" }
|
||||
, "dependencies": { "keypress": "0.1.x"}
|
||||
, "devDependencies": { "should": ">= 0.0.1" }
|
||||
, "scripts": { "test": "make test" }
|
||||
, "main": "index"
|
||||
, "engines": { "node": ">= 0.6.x" }
|
||||
}
|
||||
101
node_modules/js-md5/CHANGELOG.md
generated
vendored
Normal file
101
node_modules/js-md5/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
# Change Log
|
||||
|
||||
## v0.7.3 / 2017-12-18
|
||||
### Fixed
|
||||
- incorrect result when first bit is 1 of bytes. #18
|
||||
|
||||
## v0.7.2 / 2017-10-31
|
||||
### Improved
|
||||
- performance of hBytes increment.
|
||||
|
||||
## v0.7.1 / 2017-10-29
|
||||
### Fixed
|
||||
- incorrect result when file size >= 4G.
|
||||
|
||||
## v0.7.0 / 2017-10-29
|
||||
### Fixed
|
||||
- incorrect result when file size >= 512M.
|
||||
|
||||
## v0.6.1 / 2017-10-07
|
||||
### Fixed
|
||||
- ArrayBuffer.isView issue in IE10.
|
||||
|
||||
### Improved
|
||||
- performance of input check.
|
||||
|
||||
## v0.6.0 / 2017-07-28
|
||||
### Added
|
||||
- support base64 string output.
|
||||
|
||||
## v0.5.0 / 2017-07-14
|
||||
### Added
|
||||
- support for web worker. #11
|
||||
|
||||
### Changed
|
||||
- throw error if input type is incorrect.
|
||||
- prevent webpack to require dependencies.
|
||||
|
||||
## v0.4.2 / 2017-01-18
|
||||
### Fixed
|
||||
- `root` is undefined in some special environment. #7
|
||||
|
||||
## v0.4.1 / 2016-03-31
|
||||
### Removed
|
||||
- length detection in node.js.
|
||||
### Deprecated
|
||||
- `buffer` and replace by `arrayBuffer`.
|
||||
|
||||
## v0.4.0 / 2015-12-28
|
||||
### Added
|
||||
- support for update hash.
|
||||
- support for bytes array output.
|
||||
- support for ArrayBuffer output.
|
||||
- support for AMD.
|
||||
|
||||
## v0.3.0 / 2015-03-07
|
||||
### Added
|
||||
- support byte Array, Uint8Array and ArrayBuffer input.
|
||||
|
||||
## v0.2.2 / 2015-02-01
|
||||
### Fixed
|
||||
- bug when special length.
|
||||
### Improve
|
||||
- performance for node.js.
|
||||
|
||||
## v0.2.1 / 2015-01-13
|
||||
### Improve
|
||||
- performance.
|
||||
|
||||
## v0.2.0 / 2015-01-12
|
||||
### Removed
|
||||
- ascii parameter.
|
||||
### Improve
|
||||
- performance.
|
||||
|
||||
## v0.1.4 / 2015-01-11
|
||||
### Improve
|
||||
- performance.
|
||||
### Added
|
||||
- test cases.
|
||||
|
||||
## v0.1.3 / 2015-01-05
|
||||
### Added
|
||||
- bower package.
|
||||
- travis.
|
||||
- coveralls.
|
||||
### Improved
|
||||
- performance.
|
||||
### Fixed
|
||||
- JSHint warnings.
|
||||
|
||||
## v0.1.2 / 2014-07-27
|
||||
### Fixed
|
||||
- accents bug
|
||||
|
||||
## v0.1.1 / 2014-01-05
|
||||
### Changed
|
||||
- license
|
||||
|
||||
## v0.1.0 / 2014-01-04
|
||||
### Added
|
||||
- initial release
|
||||
20
node_modules/js-md5/LICENSE.txt
generated
vendored
Normal file
20
node_modules/js-md5/LICENSE.txt
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
Copyright 2014-2017 Chen, Yi-Cyuan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
76
node_modules/js-md5/README.md
generated
vendored
Normal file
76
node_modules/js-md5/README.md
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
# js-md5
|
||||
[](https://travis-ci.org/emn178/js-md5)
|
||||
[](https://coveralls.io/r/emn178/js-md5?branch=master)
|
||||
[](https://nodei.co/npm/js-md5/)
|
||||
|
||||
A simple MD5 hash function for JavaScript supports UTF-8 encoding.
|
||||
|
||||
## Demo
|
||||
[MD5 Online](http://emn178.github.io/online-tools/md5.html)
|
||||
[MD5 File Checksum Online](http://emn178.github.io/online-tools/md5_checksum.html)
|
||||
|
||||
## Download
|
||||
[Compress](https://raw.github.com/emn178/js-md5/master/build/md5.min.js)
|
||||
[Uncompress](https://raw.github.com/emn178/js-md5/master/src/md5.js)
|
||||
|
||||
## Installation
|
||||
You can also install js-md5 by using Bower.
|
||||
|
||||
bower install md5
|
||||
|
||||
For node.js, you can use this command to install:
|
||||
|
||||
npm install js-md5
|
||||
|
||||
## Notice
|
||||
`buffer` method is deprecated. This maybe confuse with Buffer in node.js. Please use `arrayBuffer` instead.
|
||||
|
||||
## Usage
|
||||
You could use like this:
|
||||
```JavaScript
|
||||
md5('Message to hash');
|
||||
var hash = md5.create();
|
||||
hash.update('Message to hash');
|
||||
hash.hex();
|
||||
```
|
||||
If you use node.js, you should require the module first:
|
||||
```JavaScript
|
||||
md5 = require('js-md5');
|
||||
```
|
||||
It supports AMD:
|
||||
```JavaScript
|
||||
require(['your/path/md5.js'], function(md5) {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
[See document](https://emn178.github.com/js-md5/doc/)
|
||||
|
||||
## Example
|
||||
```JavaScript
|
||||
md5(''); // d41d8cd98f00b204e9800998ecf8427e
|
||||
md5('The quick brown fox jumps over the lazy dog'); // 9e107d9d372bb6826bd81d3542a419d6
|
||||
md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0
|
||||
|
||||
// It also supports UTF-8 encoding
|
||||
md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07
|
||||
|
||||
// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`
|
||||
md5([]); // d41d8cd98f00b204e9800998ecf8427e
|
||||
md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e
|
||||
|
||||
// Different output
|
||||
md5(''); // d41d8cd98f00b204e9800998ecf8427e
|
||||
md5.hex(''); // d41d8cd98f00b204e9800998ecf8427e
|
||||
md5.array(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
|
||||
md5.digest(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
|
||||
md5.arrayBuffer(''); // ArrayBuffer
|
||||
md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
|
||||
md5.base64(''); // 1B2M2Y8AsgTpgAmY7PhCfg==
|
||||
```
|
||||
|
||||
## License
|
||||
The project is released under the [MIT license](http://www.opensource.org/licenses/MIT).
|
||||
|
||||
## Contact
|
||||
The project's website is located at https://github.com/emn178/js-md5
|
||||
Author: Chen, Yi-Cyuan (emn178@gmail.com)
|
||||
10
node_modules/js-md5/build/md5.min.js
generated
vendored
Normal file
10
node_modules/js-md5/build/md5.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
45
node_modules/js-md5/package.json
generated
vendored
Normal file
45
node_modules/js-md5/package.json
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "js-md5",
|
||||
"version": "0.7.3",
|
||||
"description": "A simple MD5 hash function for JavaScript supports UTF-8 encoding.",
|
||||
"main": "src/md5.js",
|
||||
"devDependencies": {
|
||||
"expect.js": "~0.3.1",
|
||||
"jsdoc": "^3.4.0",
|
||||
"mocha": "~2.3.4",
|
||||
"nyc": "^11.3.0",
|
||||
"requirejs": "^2.1.22",
|
||||
"uglify-js": "^3.1.9",
|
||||
"webworker-threads": "^0.7.11"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "nyc mocha tests/node-test.js",
|
||||
"report": "nyc --reporter=html --reporter=text mocha tests/node-test.js",
|
||||
"coveralls": "nyc report --reporter=text-lcov | coveralls",
|
||||
"doc": "rm -rf doc;jsdoc src README.md -d doc",
|
||||
"compress": "uglifyjs src/md5.js -c -m eval --comments --output build/md5.min.js",
|
||||
"build": "npm run-script compress;npm run-script doc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/emn178/js-md5.git"
|
||||
},
|
||||
"keywords": [
|
||||
"md5",
|
||||
"hash",
|
||||
"encryption",
|
||||
"cryptography",
|
||||
"HMAC"
|
||||
],
|
||||
"license": "MIT",
|
||||
"author": "Chen, Yi-Cyuan <emn178@gmail.com>",
|
||||
"homepage": "https://github.com/emn178/js-md5",
|
||||
"bugs": {
|
||||
"url": "https://github.com/emn178/js-md5/issues"
|
||||
},
|
||||
"nyc": {
|
||||
"exclude": [
|
||||
"tests"
|
||||
]
|
||||
}
|
||||
}
|
||||
683
node_modules/js-md5/src/md5.js
generated
vendored
Normal file
683
node_modules/js-md5/src/md5.js
generated
vendored
Normal file
@@ -0,0 +1,683 @@
|
||||
/**
|
||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||
*
|
||||
* @namespace md5
|
||||
* @version 0.7.3
|
||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||
* @copyright Chen, Yi-Cyuan 2014-2017
|
||||
* @license MIT
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ERROR = 'input is invalid type';
|
||||
var WINDOW = typeof window === 'object';
|
||||
var root = WINDOW ? window : {};
|
||||
if (root.JS_MD5_NO_WINDOW) {
|
||||
WINDOW = false;
|
||||
}
|
||||
var WEB_WORKER = !WINDOW && typeof self === 'object';
|
||||
var NODE_JS = !root.JS_MD5_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
|
||||
if (NODE_JS) {
|
||||
root = global;
|
||||
} else if (WEB_WORKER) {
|
||||
root = self;
|
||||
}
|
||||
var COMMON_JS = !root.JS_MD5_NO_COMMON_JS && typeof module === 'object' && module.exports;
|
||||
var AMD = typeof define === 'function' && define.amd;
|
||||
var ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
|
||||
var HEX_CHARS = '0123456789abcdef'.split('');
|
||||
var EXTRA = [128, 32768, 8388608, -2147483648];
|
||||
var SHIFT = [0, 8, 16, 24];
|
||||
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer', 'base64'];
|
||||
var BASE64_ENCODE_CHAR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
|
||||
|
||||
var blocks = [], buffer8;
|
||||
if (ARRAY_BUFFER) {
|
||||
var buffer = new ArrayBuffer(68);
|
||||
buffer8 = new Uint8Array(buffer);
|
||||
blocks = new Uint32Array(buffer);
|
||||
}
|
||||
|
||||
if (root.JS_MD5_NO_NODE_JS || !Array.isArray) {
|
||||
Array.isArray = function (obj) {
|
||||
return Object.prototype.toString.call(obj) === '[object Array]';
|
||||
};
|
||||
}
|
||||
|
||||
if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
|
||||
ArrayBuffer.isView = function (obj) {
|
||||
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @method hex
|
||||
* @memberof md5
|
||||
* @description Output hash as hex string
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {String} Hex string
|
||||
* @example
|
||||
* md5.hex('The quick brown fox jumps over the lazy dog');
|
||||
* // equal to
|
||||
* md5('The quick brown fox jumps over the lazy dog');
|
||||
*/
|
||||
/**
|
||||
* @method digest
|
||||
* @memberof md5
|
||||
* @description Output hash as bytes array
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {Array} Bytes array
|
||||
* @example
|
||||
* md5.digest('The quick brown fox jumps over the lazy dog');
|
||||
*/
|
||||
/**
|
||||
* @method array
|
||||
* @memberof md5
|
||||
* @description Output hash as bytes array
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {Array} Bytes array
|
||||
* @example
|
||||
* md5.array('The quick brown fox jumps over the lazy dog');
|
||||
*/
|
||||
/**
|
||||
* @method arrayBuffer
|
||||
* @memberof md5
|
||||
* @description Output hash as ArrayBuffer
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {ArrayBuffer} ArrayBuffer
|
||||
* @example
|
||||
* md5.arrayBuffer('The quick brown fox jumps over the lazy dog');
|
||||
*/
|
||||
/**
|
||||
* @method buffer
|
||||
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
|
||||
* @memberof md5
|
||||
* @description Output hash as ArrayBuffer
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {ArrayBuffer} ArrayBuffer
|
||||
* @example
|
||||
* md5.buffer('The quick brown fox jumps over the lazy dog');
|
||||
*/
|
||||
/**
|
||||
* @method base64
|
||||
* @memberof md5
|
||||
* @description Output hash as base64 string
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {String} base64 string
|
||||
* @example
|
||||
* md5.base64('The quick brown fox jumps over the lazy dog');
|
||||
*/
|
||||
var createOutputMethod = function (outputType) {
|
||||
return function (message) {
|
||||
return new Md5(true).update(message)[outputType]();
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @method create
|
||||
* @memberof md5
|
||||
* @description Create Md5 object
|
||||
* @returns {Md5} Md5 object.
|
||||
* @example
|
||||
* var hash = md5.create();
|
||||
*/
|
||||
/**
|
||||
* @method update
|
||||
* @memberof md5
|
||||
* @description Create and update Md5 object
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {Md5} Md5 object.
|
||||
* @example
|
||||
* var hash = md5.update('The quick brown fox jumps over the lazy dog');
|
||||
* // equal to
|
||||
* var hash = md5.create();
|
||||
* hash.update('The quick brown fox jumps over the lazy dog');
|
||||
*/
|
||||
var createMethod = function () {
|
||||
var method = createOutputMethod('hex');
|
||||
if (NODE_JS) {
|
||||
method = nodeWrap(method);
|
||||
}
|
||||
method.create = function () {
|
||||
return new Md5();
|
||||
};
|
||||
method.update = function (message) {
|
||||
return method.create().update(message);
|
||||
};
|
||||
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
||||
var type = OUTPUT_TYPES[i];
|
||||
method[type] = createOutputMethod(type);
|
||||
}
|
||||
return method;
|
||||
};
|
||||
|
||||
var nodeWrap = function (method) {
|
||||
var crypto = eval("require('crypto')");
|
||||
var Buffer = eval("require('buffer').Buffer");
|
||||
var nodeMethod = function (message) {
|
||||
if (typeof message === 'string') {
|
||||
return crypto.createHash('md5').update(message, 'utf8').digest('hex');
|
||||
} else {
|
||||
if (message === null || message === undefined) {
|
||||
throw ERROR;
|
||||
} else if (message.constructor === ArrayBuffer) {
|
||||
message = new Uint8Array(message);
|
||||
}
|
||||
}
|
||||
if (Array.isArray(message) || ArrayBuffer.isView(message) ||
|
||||
message.constructor === Buffer) {
|
||||
return crypto.createHash('md5').update(new Buffer(message)).digest('hex');
|
||||
} else {
|
||||
return method(message);
|
||||
}
|
||||
};
|
||||
return nodeMethod;
|
||||
};
|
||||
|
||||
/**
|
||||
* Md5 class
|
||||
* @class Md5
|
||||
* @description This is internal class.
|
||||
* @see {@link md5.create}
|
||||
*/
|
||||
function Md5(sharedMemory) {
|
||||
if (sharedMemory) {
|
||||
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] =
|
||||
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
|
||||
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||
this.blocks = blocks;
|
||||
this.buffer8 = buffer8;
|
||||
} else {
|
||||
if (ARRAY_BUFFER) {
|
||||
var buffer = new ArrayBuffer(68);
|
||||
this.buffer8 = new Uint8Array(buffer);
|
||||
this.blocks = new Uint32Array(buffer);
|
||||
} else {
|
||||
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
}
|
||||
}
|
||||
this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = this.hBytes = 0;
|
||||
this.finalized = this.hashed = false;
|
||||
this.first = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @method update
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Update hash
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {Md5} Md5 object.
|
||||
* @see {@link md5.update}
|
||||
*/
|
||||
Md5.prototype.update = function (message) {
|
||||
if (this.finalized) {
|
||||
return;
|
||||
}
|
||||
|
||||
var notString, type = typeof message;
|
||||
if (type !== 'string') {
|
||||
if (type === 'object') {
|
||||
if (message === null) {
|
||||
throw ERROR;
|
||||
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
||||
message = new Uint8Array(message);
|
||||
} else if (!Array.isArray(message)) {
|
||||
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
||||
throw ERROR;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw ERROR;
|
||||
}
|
||||
notString = true;
|
||||
}
|
||||
var code, index = 0, i, length = message.length, blocks = this.blocks;
|
||||
var buffer8 = this.buffer8;
|
||||
|
||||
while (index < length) {
|
||||
if (this.hashed) {
|
||||
this.hashed = false;
|
||||
blocks[0] = blocks[16];
|
||||
blocks[16] = blocks[1] = blocks[2] = blocks[3] =
|
||||
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
|
||||
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||
}
|
||||
|
||||
if (notString) {
|
||||
if (ARRAY_BUFFER) {
|
||||
for (i = this.start; index < length && i < 64; ++index) {
|
||||
buffer8[i++] = message[index];
|
||||
}
|
||||
} else {
|
||||
for (i = this.start; index < length && i < 64; ++index) {
|
||||
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (ARRAY_BUFFER) {
|
||||
for (i = this.start; index < length && i < 64; ++index) {
|
||||
code = message.charCodeAt(index);
|
||||
if (code < 0x80) {
|
||||
buffer8[i++] = code;
|
||||
} else if (code < 0x800) {
|
||||
buffer8[i++] = 0xc0 | (code >> 6);
|
||||
buffer8[i++] = 0x80 | (code & 0x3f);
|
||||
} else if (code < 0xd800 || code >= 0xe000) {
|
||||
buffer8[i++] = 0xe0 | (code >> 12);
|
||||
buffer8[i++] = 0x80 | ((code >> 6) & 0x3f);
|
||||
buffer8[i++] = 0x80 | (code & 0x3f);
|
||||
} else {
|
||||
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
||||
buffer8[i++] = 0xf0 | (code >> 18);
|
||||
buffer8[i++] = 0x80 | ((code >> 12) & 0x3f);
|
||||
buffer8[i++] = 0x80 | ((code >> 6) & 0x3f);
|
||||
buffer8[i++] = 0x80 | (code & 0x3f);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = this.start; index < length && i < 64; ++index) {
|
||||
code = message.charCodeAt(index);
|
||||
if (code < 0x80) {
|
||||
blocks[i >> 2] |= code << SHIFT[i++ & 3];
|
||||
} else if (code < 0x800) {
|
||||
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||
} else if (code < 0xd800 || code >= 0xe000) {
|
||||
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||
} else {
|
||||
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
||||
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.lastByteIndex = i;
|
||||
this.bytes += i - this.start;
|
||||
if (i >= 64) {
|
||||
this.start = i - 64;
|
||||
this.hash();
|
||||
this.hashed = true;
|
||||
} else {
|
||||
this.start = i;
|
||||
}
|
||||
}
|
||||
if (this.bytes > 4294967295) {
|
||||
this.hBytes += this.bytes / 4294967296 << 0;
|
||||
this.bytes = this.bytes % 4294967296;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Md5.prototype.finalize = function () {
|
||||
if (this.finalized) {
|
||||
return;
|
||||
}
|
||||
this.finalized = true;
|
||||
var blocks = this.blocks, i = this.lastByteIndex;
|
||||
blocks[i >> 2] |= EXTRA[i & 3];
|
||||
if (i >= 56) {
|
||||
if (!this.hashed) {
|
||||
this.hash();
|
||||
}
|
||||
blocks[0] = blocks[16];
|
||||
blocks[16] = blocks[1] = blocks[2] = blocks[3] =
|
||||
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
|
||||
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||
}
|
||||
blocks[14] = this.bytes << 3;
|
||||
blocks[15] = this.hBytes << 3 | this.bytes >>> 29;
|
||||
this.hash();
|
||||
};
|
||||
|
||||
Md5.prototype.hash = function () {
|
||||
var a, b, c, d, bc, da, blocks = this.blocks;
|
||||
|
||||
if (this.first) {
|
||||
a = blocks[0] - 680876937;
|
||||
a = (a << 7 | a >>> 25) - 271733879 << 0;
|
||||
d = (-1732584194 ^ a & 2004318071) + blocks[1] - 117830708;
|
||||
d = (d << 12 | d >>> 20) + a << 0;
|
||||
c = (-271733879 ^ (d & (a ^ -271733879))) + blocks[2] - 1126478375;
|
||||
c = (c << 17 | c >>> 15) + d << 0;
|
||||
b = (a ^ (c & (d ^ a))) + blocks[3] - 1316259209;
|
||||
b = (b << 22 | b >>> 10) + c << 0;
|
||||
} else {
|
||||
a = this.h0;
|
||||
b = this.h1;
|
||||
c = this.h2;
|
||||
d = this.h3;
|
||||
a += (d ^ (b & (c ^ d))) + blocks[0] - 680876936;
|
||||
a = (a << 7 | a >>> 25) + b << 0;
|
||||
d += (c ^ (a & (b ^ c))) + blocks[1] - 389564586;
|
||||
d = (d << 12 | d >>> 20) + a << 0;
|
||||
c += (b ^ (d & (a ^ b))) + blocks[2] + 606105819;
|
||||
c = (c << 17 | c >>> 15) + d << 0;
|
||||
b += (a ^ (c & (d ^ a))) + blocks[3] - 1044525330;
|
||||
b = (b << 22 | b >>> 10) + c << 0;
|
||||
}
|
||||
|
||||
a += (d ^ (b & (c ^ d))) + blocks[4] - 176418897;
|
||||
a = (a << 7 | a >>> 25) + b << 0;
|
||||
d += (c ^ (a & (b ^ c))) + blocks[5] + 1200080426;
|
||||
d = (d << 12 | d >>> 20) + a << 0;
|
||||
c += (b ^ (d & (a ^ b))) + blocks[6] - 1473231341;
|
||||
c = (c << 17 | c >>> 15) + d << 0;
|
||||
b += (a ^ (c & (d ^ a))) + blocks[7] - 45705983;
|
||||
b = (b << 22 | b >>> 10) + c << 0;
|
||||
a += (d ^ (b & (c ^ d))) + blocks[8] + 1770035416;
|
||||
a = (a << 7 | a >>> 25) + b << 0;
|
||||
d += (c ^ (a & (b ^ c))) + blocks[9] - 1958414417;
|
||||
d = (d << 12 | d >>> 20) + a << 0;
|
||||
c += (b ^ (d & (a ^ b))) + blocks[10] - 42063;
|
||||
c = (c << 17 | c >>> 15) + d << 0;
|
||||
b += (a ^ (c & (d ^ a))) + blocks[11] - 1990404162;
|
||||
b = (b << 22 | b >>> 10) + c << 0;
|
||||
a += (d ^ (b & (c ^ d))) + blocks[12] + 1804603682;
|
||||
a = (a << 7 | a >>> 25) + b << 0;
|
||||
d += (c ^ (a & (b ^ c))) + blocks[13] - 40341101;
|
||||
d = (d << 12 | d >>> 20) + a << 0;
|
||||
c += (b ^ (d & (a ^ b))) + blocks[14] - 1502002290;
|
||||
c = (c << 17 | c >>> 15) + d << 0;
|
||||
b += (a ^ (c & (d ^ a))) + blocks[15] + 1236535329;
|
||||
b = (b << 22 | b >>> 10) + c << 0;
|
||||
a += (c ^ (d & (b ^ c))) + blocks[1] - 165796510;
|
||||
a = (a << 5 | a >>> 27) + b << 0;
|
||||
d += (b ^ (c & (a ^ b))) + blocks[6] - 1069501632;
|
||||
d = (d << 9 | d >>> 23) + a << 0;
|
||||
c += (a ^ (b & (d ^ a))) + blocks[11] + 643717713;
|
||||
c = (c << 14 | c >>> 18) + d << 0;
|
||||
b += (d ^ (a & (c ^ d))) + blocks[0] - 373897302;
|
||||
b = (b << 20 | b >>> 12) + c << 0;
|
||||
a += (c ^ (d & (b ^ c))) + blocks[5] - 701558691;
|
||||
a = (a << 5 | a >>> 27) + b << 0;
|
||||
d += (b ^ (c & (a ^ b))) + blocks[10] + 38016083;
|
||||
d = (d << 9 | d >>> 23) + a << 0;
|
||||
c += (a ^ (b & (d ^ a))) + blocks[15] - 660478335;
|
||||
c = (c << 14 | c >>> 18) + d << 0;
|
||||
b += (d ^ (a & (c ^ d))) + blocks[4] - 405537848;
|
||||
b = (b << 20 | b >>> 12) + c << 0;
|
||||
a += (c ^ (d & (b ^ c))) + blocks[9] + 568446438;
|
||||
a = (a << 5 | a >>> 27) + b << 0;
|
||||
d += (b ^ (c & (a ^ b))) + blocks[14] - 1019803690;
|
||||
d = (d << 9 | d >>> 23) + a << 0;
|
||||
c += (a ^ (b & (d ^ a))) + blocks[3] - 187363961;
|
||||
c = (c << 14 | c >>> 18) + d << 0;
|
||||
b += (d ^ (a & (c ^ d))) + blocks[8] + 1163531501;
|
||||
b = (b << 20 | b >>> 12) + c << 0;
|
||||
a += (c ^ (d & (b ^ c))) + blocks[13] - 1444681467;
|
||||
a = (a << 5 | a >>> 27) + b << 0;
|
||||
d += (b ^ (c & (a ^ b))) + blocks[2] - 51403784;
|
||||
d = (d << 9 | d >>> 23) + a << 0;
|
||||
c += (a ^ (b & (d ^ a))) + blocks[7] + 1735328473;
|
||||
c = (c << 14 | c >>> 18) + d << 0;
|
||||
b += (d ^ (a & (c ^ d))) + blocks[12] - 1926607734;
|
||||
b = (b << 20 | b >>> 12) + c << 0;
|
||||
bc = b ^ c;
|
||||
a += (bc ^ d) + blocks[5] - 378558;
|
||||
a = (a << 4 | a >>> 28) + b << 0;
|
||||
d += (bc ^ a) + blocks[8] - 2022574463;
|
||||
d = (d << 11 | d >>> 21) + a << 0;
|
||||
da = d ^ a;
|
||||
c += (da ^ b) + blocks[11] + 1839030562;
|
||||
c = (c << 16 | c >>> 16) + d << 0;
|
||||
b += (da ^ c) + blocks[14] - 35309556;
|
||||
b = (b << 23 | b >>> 9) + c << 0;
|
||||
bc = b ^ c;
|
||||
a += (bc ^ d) + blocks[1] - 1530992060;
|
||||
a = (a << 4 | a >>> 28) + b << 0;
|
||||
d += (bc ^ a) + blocks[4] + 1272893353;
|
||||
d = (d << 11 | d >>> 21) + a << 0;
|
||||
da = d ^ a;
|
||||
c += (da ^ b) + blocks[7] - 155497632;
|
||||
c = (c << 16 | c >>> 16) + d << 0;
|
||||
b += (da ^ c) + blocks[10] - 1094730640;
|
||||
b = (b << 23 | b >>> 9) + c << 0;
|
||||
bc = b ^ c;
|
||||
a += (bc ^ d) + blocks[13] + 681279174;
|
||||
a = (a << 4 | a >>> 28) + b << 0;
|
||||
d += (bc ^ a) + blocks[0] - 358537222;
|
||||
d = (d << 11 | d >>> 21) + a << 0;
|
||||
da = d ^ a;
|
||||
c += (da ^ b) + blocks[3] - 722521979;
|
||||
c = (c << 16 | c >>> 16) + d << 0;
|
||||
b += (da ^ c) + blocks[6] + 76029189;
|
||||
b = (b << 23 | b >>> 9) + c << 0;
|
||||
bc = b ^ c;
|
||||
a += (bc ^ d) + blocks[9] - 640364487;
|
||||
a = (a << 4 | a >>> 28) + b << 0;
|
||||
d += (bc ^ a) + blocks[12] - 421815835;
|
||||
d = (d << 11 | d >>> 21) + a << 0;
|
||||
da = d ^ a;
|
||||
c += (da ^ b) + blocks[15] + 530742520;
|
||||
c = (c << 16 | c >>> 16) + d << 0;
|
||||
b += (da ^ c) + blocks[2] - 995338651;
|
||||
b = (b << 23 | b >>> 9) + c << 0;
|
||||
a += (c ^ (b | ~d)) + blocks[0] - 198630844;
|
||||
a = (a << 6 | a >>> 26) + b << 0;
|
||||
d += (b ^ (a | ~c)) + blocks[7] + 1126891415;
|
||||
d = (d << 10 | d >>> 22) + a << 0;
|
||||
c += (a ^ (d | ~b)) + blocks[14] - 1416354905;
|
||||
c = (c << 15 | c >>> 17) + d << 0;
|
||||
b += (d ^ (c | ~a)) + blocks[5] - 57434055;
|
||||
b = (b << 21 | b >>> 11) + c << 0;
|
||||
a += (c ^ (b | ~d)) + blocks[12] + 1700485571;
|
||||
a = (a << 6 | a >>> 26) + b << 0;
|
||||
d += (b ^ (a | ~c)) + blocks[3] - 1894986606;
|
||||
d = (d << 10 | d >>> 22) + a << 0;
|
||||
c += (a ^ (d | ~b)) + blocks[10] - 1051523;
|
||||
c = (c << 15 | c >>> 17) + d << 0;
|
||||
b += (d ^ (c | ~a)) + blocks[1] - 2054922799;
|
||||
b = (b << 21 | b >>> 11) + c << 0;
|
||||
a += (c ^ (b | ~d)) + blocks[8] + 1873313359;
|
||||
a = (a << 6 | a >>> 26) + b << 0;
|
||||
d += (b ^ (a | ~c)) + blocks[15] - 30611744;
|
||||
d = (d << 10 | d >>> 22) + a << 0;
|
||||
c += (a ^ (d | ~b)) + blocks[6] - 1560198380;
|
||||
c = (c << 15 | c >>> 17) + d << 0;
|
||||
b += (d ^ (c | ~a)) + blocks[13] + 1309151649;
|
||||
b = (b << 21 | b >>> 11) + c << 0;
|
||||
a += (c ^ (b | ~d)) + blocks[4] - 145523070;
|
||||
a = (a << 6 | a >>> 26) + b << 0;
|
||||
d += (b ^ (a | ~c)) + blocks[11] - 1120210379;
|
||||
d = (d << 10 | d >>> 22) + a << 0;
|
||||
c += (a ^ (d | ~b)) + blocks[2] + 718787259;
|
||||
c = (c << 15 | c >>> 17) + d << 0;
|
||||
b += (d ^ (c | ~a)) + blocks[9] - 343485551;
|
||||
b = (b << 21 | b >>> 11) + c << 0;
|
||||
|
||||
if (this.first) {
|
||||
this.h0 = a + 1732584193 << 0;
|
||||
this.h1 = b - 271733879 << 0;
|
||||
this.h2 = c - 1732584194 << 0;
|
||||
this.h3 = d + 271733878 << 0;
|
||||
this.first = false;
|
||||
} else {
|
||||
this.h0 = this.h0 + a << 0;
|
||||
this.h1 = this.h1 + b << 0;
|
||||
this.h2 = this.h2 + c << 0;
|
||||
this.h3 = this.h3 + d << 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @method hex
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Output hash as hex string
|
||||
* @returns {String} Hex string
|
||||
* @see {@link md5.hex}
|
||||
* @example
|
||||
* hash.hex();
|
||||
*/
|
||||
Md5.prototype.hex = function () {
|
||||
this.finalize();
|
||||
|
||||
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
|
||||
|
||||
return HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
|
||||
HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
|
||||
HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
|
||||
HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
|
||||
HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F];
|
||||
};
|
||||
|
||||
/**
|
||||
* @method toString
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Output hash as hex string
|
||||
* @returns {String} Hex string
|
||||
* @see {@link md5.hex}
|
||||
* @example
|
||||
* hash.toString();
|
||||
*/
|
||||
Md5.prototype.toString = Md5.prototype.hex;
|
||||
|
||||
/**
|
||||
* @method digest
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Output hash as bytes array
|
||||
* @returns {Array} Bytes array
|
||||
* @see {@link md5.digest}
|
||||
* @example
|
||||
* hash.digest();
|
||||
*/
|
||||
Md5.prototype.digest = function () {
|
||||
this.finalize();
|
||||
|
||||
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
|
||||
return [
|
||||
h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 24) & 0xFF,
|
||||
h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 24) & 0xFF,
|
||||
h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 24) & 0xFF,
|
||||
h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 24) & 0xFF
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* @method array
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Output hash as bytes array
|
||||
* @returns {Array} Bytes array
|
||||
* @see {@link md5.array}
|
||||
* @example
|
||||
* hash.array();
|
||||
*/
|
||||
Md5.prototype.array = Md5.prototype.digest;
|
||||
|
||||
/**
|
||||
* @method arrayBuffer
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Output hash as ArrayBuffer
|
||||
* @returns {ArrayBuffer} ArrayBuffer
|
||||
* @see {@link md5.arrayBuffer}
|
||||
* @example
|
||||
* hash.arrayBuffer();
|
||||
*/
|
||||
Md5.prototype.arrayBuffer = function () {
|
||||
this.finalize();
|
||||
|
||||
var buffer = new ArrayBuffer(16);
|
||||
var blocks = new Uint32Array(buffer);
|
||||
blocks[0] = this.h0;
|
||||
blocks[1] = this.h1;
|
||||
blocks[2] = this.h2;
|
||||
blocks[3] = this.h3;
|
||||
return buffer;
|
||||
};
|
||||
|
||||
/**
|
||||
* @method buffer
|
||||
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Output hash as ArrayBuffer
|
||||
* @returns {ArrayBuffer} ArrayBuffer
|
||||
* @see {@link md5.buffer}
|
||||
* @example
|
||||
* hash.buffer();
|
||||
*/
|
||||
Md5.prototype.buffer = Md5.prototype.arrayBuffer;
|
||||
|
||||
/**
|
||||
* @method base64
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Output hash as base64 string
|
||||
* @returns {String} base64 string
|
||||
* @see {@link md5.base64}
|
||||
* @example
|
||||
* hash.base64();
|
||||
*/
|
||||
Md5.prototype.base64 = function () {
|
||||
var v1, v2, v3, base64Str = '', bytes = this.array();
|
||||
for (var i = 0; i < 15;) {
|
||||
v1 = bytes[i++];
|
||||
v2 = bytes[i++];
|
||||
v3 = bytes[i++];
|
||||
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||
BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] +
|
||||
BASE64_ENCODE_CHAR[(v2 << 2 | v3 >>> 6) & 63] +
|
||||
BASE64_ENCODE_CHAR[v3 & 63];
|
||||
}
|
||||
v1 = bytes[i];
|
||||
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||
BASE64_ENCODE_CHAR[(v1 << 4) & 63] +
|
||||
'==';
|
||||
return base64Str;
|
||||
};
|
||||
|
||||
var exports = createMethod();
|
||||
|
||||
if (COMMON_JS) {
|
||||
module.exports = exports;
|
||||
} else {
|
||||
/**
|
||||
* @method md5
|
||||
* @description Md5 hash function, export to global in browsers.
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {String} md5 hashes
|
||||
* @example
|
||||
* md5(''); // d41d8cd98f00b204e9800998ecf8427e
|
||||
* md5('The quick brown fox jumps over the lazy dog'); // 9e107d9d372bb6826bd81d3542a419d6
|
||||
* md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0
|
||||
*
|
||||
* // It also supports UTF-8 encoding
|
||||
* md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07
|
||||
*
|
||||
* // It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`
|
||||
* md5([]); // d41d8cd98f00b204e9800998ecf8427e
|
||||
* md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e
|
||||
*/
|
||||
root.md5 = exports;
|
||||
if (AMD) {
|
||||
define(function () {
|
||||
return exports;
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
13
node_modules/js/History.md
generated
vendored
Normal file
13
node_modules/js/History.md
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
0.1.0 / 2013-04-24
|
||||
==================
|
||||
|
||||
* Add silent flag.
|
||||
* Add ugly output mode.
|
||||
* Attempt to parse code both in expression and statement list contexts.
|
||||
* Use expression result as status.
|
||||
|
||||
0.0.1 / 2013-04-22
|
||||
==================
|
||||
|
||||
* Initial release.
|
||||
21
node_modules/js/LICENSE
generated
vendored
Normal file
21
node_modules/js/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Marco Aurélio
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
29
node_modules/js/README.md
generated
vendored
Normal file
29
node_modules/js/README.md
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# js
|
||||
|
||||
**js** is a a better alternative to `node -p`. It will automatically convert data from and to JSON string representations, and will automatically expose enviroment variables as globals preceded with `$`.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
js <javascript>
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
Using math
|
||||
|
||||
```bash
|
||||
js 2+2
|
||||
```
|
||||
|
||||
Read a field from a JSON file
|
||||
|
||||
```bash
|
||||
js stdin.version < package.json
|
||||
```
|
||||
|
||||
Add a field to a JSON file on the fly
|
||||
|
||||
```bash
|
||||
js 'stdin.foo = "bar", stdin' < in.json > out.json
|
||||
```
|
||||
87
node_modules/js/bin/js
generated
vendored
Executable file
87
node_modules/js/bin/js
generated
vendored
Executable file
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var program = require('commander');
|
||||
|
||||
program
|
||||
.version(JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8')).version)
|
||||
.usage('<javascript>')
|
||||
.option('-r, --raw', 'do not attempt to convert data from JSON')
|
||||
.option('-u, --ugly', 'ugly output (no indentation)')
|
||||
.option('-s, --silent', 'do not print result to standard output')
|
||||
.parse(process.argv);
|
||||
|
||||
var stdin = "";
|
||||
|
||||
if (!process.stdin.isTTY) {
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding('utf8');
|
||||
process.stdin.on('data', function(chunk) {
|
||||
stdin += chunk;
|
||||
})
|
||||
process.stdin.on('end', start);
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
|
||||
function start() {
|
||||
if (!program.raw) {
|
||||
// attempt to interpret stdin as JSON
|
||||
try {
|
||||
stdin = JSON.parse(stdin);
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// expose environment variables as globals preceded with $
|
||||
for (var name in process.env) {
|
||||
var value = process.env[name];
|
||||
|
||||
if (!program.raw) {
|
||||
// attempt to interpret variable as JSON
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
global['$' + name] = value;
|
||||
}
|
||||
|
||||
var result, output;
|
||||
|
||||
try {
|
||||
result = output = eval('(' + (program.args.join(' ') || 'undefined') + ')');
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
result = output = eval(program.args.join(' ') || 'undefined');
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof output == 'string') {
|
||||
if (output[output.length - 1] != '\n') {
|
||||
output = output + '\n';
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
if (program.ugly) {
|
||||
output = JSON.stringify(output) + '\n';
|
||||
} else {
|
||||
output = JSON.stringify(output, null, 2) + '\n';
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
if (!program.silent) {
|
||||
process.stdout.write(output);
|
||||
}
|
||||
|
||||
process.exit(result ? 0 : 1);
|
||||
}
|
||||
12
node_modules/js/package.json
generated
vendored
Normal file
12
node_modules/js/package.json
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "js",
|
||||
"description": "A better `node -p`.",
|
||||
"author": "Marco Aurelio <thecoreh@gmail.com>",
|
||||
"version": "0.1.0",
|
||||
"bin": {
|
||||
"js": "./bin/js"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": "~1.1.1"
|
||||
}
|
||||
}
|
||||
101
node_modules/keypress/README.md
generated
vendored
Normal file
101
node_modules/keypress/README.md
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
keypress
|
||||
========
|
||||
### Make any Node ReadableStream emit "keypress" events
|
||||
|
||||
|
||||
Previous to Node `v0.8.x`, there was an undocumented `"keypress"` event that
|
||||
`process.stdin` would emit when it was a TTY. Some people discovered this hidden
|
||||
gem, and started using it in their own code.
|
||||
|
||||
Now in Node `v0.8.x`, this `"keypress"` event does not get emitted by default,
|
||||
but rather only when it is being used in conjuction with the `readline` (or by
|
||||
extension, the `repl`) module.
|
||||
|
||||
This module is the exact logic from the node `v0.8.x` releases ripped out into its
|
||||
own module.
|
||||
|
||||
__Bonus:__ Now with mouse support!
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Install with `npm`:
|
||||
|
||||
``` bash
|
||||
$ npm install keypress
|
||||
```
|
||||
|
||||
Or add it to the `"dependencies"` section of your _package.json_ file.
|
||||
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
#### Listening for "keypress" events
|
||||
|
||||
``` js
|
||||
var keypress = require('keypress');
|
||||
|
||||
// make `process.stdin` begin emitting "keypress" events
|
||||
keypress(process.stdin);
|
||||
|
||||
// listen for the "keypress" event
|
||||
process.stdin.on('keypress', function (ch, key) {
|
||||
console.log('got "keypress"', key);
|
||||
if (key && key.ctrl && key.name == 'c') {
|
||||
process.stdin.pause();
|
||||
}
|
||||
});
|
||||
|
||||
process.stdin.setRawMode(true);
|
||||
process.stdin.resume();
|
||||
```
|
||||
|
||||
#### Listening for "mousepress" events
|
||||
|
||||
``` js
|
||||
var keypress = require('keypress');
|
||||
|
||||
// make `process.stdin` begin emitting "mousepress" (and "keypress") events
|
||||
keypress(process.stdin);
|
||||
|
||||
// you must enable the mouse events before they will begin firing
|
||||
keypress.enableMouse(process.stdout);
|
||||
|
||||
process.stdin.on('mousepress', function (info) {
|
||||
console.log('got "mousepress" event at %d x %d', info.x, info.y);
|
||||
});
|
||||
|
||||
process.on('exit', function () {
|
||||
// disable mouse on exit, so that the state
|
||||
// is back to normal for the terminal
|
||||
keypress.disableMouse(process.stdout);
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
346
node_modules/keypress/index.js
generated
vendored
Normal file
346
node_modules/keypress/index.js
generated
vendored
Normal file
@@ -0,0 +1,346 @@
|
||||
|
||||
/**
|
||||
* This module offers the internal "keypress" functionality from node-core's
|
||||
* `readline` module, for your own programs and modules to use.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* require('keypress')(process.stdin);
|
||||
*
|
||||
* process.stdin.on('keypress', function (ch, key) {
|
||||
* console.log(ch, key);
|
||||
* if (key.ctrl && key.name == 'c') {
|
||||
* process.stdin.pause();
|
||||
* }
|
||||
* });
|
||||
* proces.stdin.resume();
|
||||
*/
|
||||
var exports = module.exports = keypress;
|
||||
|
||||
exports.enableMouse = function (stream) {
|
||||
stream.write('\x1b' +'[?1000h')
|
||||
}
|
||||
|
||||
exports.disableMouse = function (stream) {
|
||||
stream.write('\x1b' +'[?1000l')
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* accepts a readable Stream instance and makes it emit "keypress" events
|
||||
*/
|
||||
|
||||
function keypress(stream) {
|
||||
if (isEmittingKeypress(stream)) return;
|
||||
stream._emitKeypress = true;
|
||||
|
||||
function onData(b) {
|
||||
if (stream.listeners('keypress').length > 0) {
|
||||
emitKey(stream, b);
|
||||
} else {
|
||||
// Nobody's watching anyway
|
||||
stream.removeListener('data', onData);
|
||||
stream.on('newListener', onNewListener);
|
||||
}
|
||||
}
|
||||
|
||||
function onNewListener(event) {
|
||||
if (event == 'keypress') {
|
||||
stream.on('data', onData);
|
||||
stream.removeListener('newListener', onNewListener);
|
||||
}
|
||||
}
|
||||
|
||||
if (stream.listeners('keypress').length > 0) {
|
||||
stream.on('data', onData);
|
||||
} else {
|
||||
stream.on('newListener', onNewListener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the stream is already emitting "keypress" events.
|
||||
* `false` otherwise.
|
||||
*/
|
||||
|
||||
function isEmittingKeypress(stream) {
|
||||
var rtn = stream._emitKeypress;
|
||||
if (!rtn) {
|
||||
// hack: check for the v0.6.x "data" event
|
||||
stream.listeners('data').forEach(function (l) {
|
||||
if (l.name == 'onData' && /emitKey/.test(l.toString())) {
|
||||
rtn = true;
|
||||
stream._emitKeypress = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!rtn) {
|
||||
// hack: check for the v0.6.x "newListener" event
|
||||
stream.listeners('newListener').forEach(function (l) {
|
||||
if (l.name == 'onNewListener' && /keypress/.test(l.toString())) {
|
||||
rtn = true;
|
||||
stream._emitKeypress = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Some patterns seen in terminal key escape codes, derived from combos seen
|
||||
at http://www.midnight-commander.org/browser/lib/tty/key.c
|
||||
|
||||
ESC letter
|
||||
ESC [ letter
|
||||
ESC [ modifier letter
|
||||
ESC [ 1 ; modifier letter
|
||||
ESC [ num char
|
||||
ESC [ num ; modifier char
|
||||
ESC O letter
|
||||
ESC O modifier letter
|
||||
ESC O 1 ; modifier letter
|
||||
ESC N letter
|
||||
ESC [ [ num ; modifier char
|
||||
ESC [ [ 1 ; modifier letter
|
||||
ESC ESC [ num char
|
||||
ESC ESC O letter
|
||||
|
||||
- char is usually ~ but $ and ^ also happen with rxvt
|
||||
- modifier is 1 +
|
||||
(shift * 1) +
|
||||
(left_alt * 2) +
|
||||
(ctrl * 4) +
|
||||
(right_alt * 8)
|
||||
- two leading ESCs apparently mean the same as one leading ESC
|
||||
*/
|
||||
|
||||
// Regexes used for ansi escape code splitting
|
||||
var metaKeyCodeRe = /^(?:\x1b)([a-zA-Z0-9])$/;
|
||||
var functionKeyCodeRe =
|
||||
/^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/;
|
||||
|
||||
function emitKey(stream, s) {
|
||||
var ch,
|
||||
key = {
|
||||
name: undefined,
|
||||
ctrl: false,
|
||||
meta: false,
|
||||
shift: false
|
||||
},
|
||||
parts;
|
||||
|
||||
if (Buffer.isBuffer(s)) {
|
||||
if (s[0] > 127 && s[1] === undefined) {
|
||||
s[0] -= 128;
|
||||
s = '\x1b' + s.toString(stream.encoding || 'utf-8');
|
||||
} else {
|
||||
s = s.toString(stream.encoding || 'utf-8');
|
||||
}
|
||||
}
|
||||
|
||||
key.sequence = s;
|
||||
|
||||
if (s === '\r' || s === '\n') {
|
||||
// enter
|
||||
key.name = 'enter';
|
||||
|
||||
} else if (s === '\t') {
|
||||
// tab
|
||||
key.name = 'tab';
|
||||
|
||||
} else if (s === '\b' || s === '\x7f' ||
|
||||
s === '\x1b\x7f' || s === '\x1b\b') {
|
||||
// backspace or ctrl+h
|
||||
key.name = 'backspace';
|
||||
key.meta = (s.charAt(0) === '\x1b');
|
||||
|
||||
} else if (s === '\x1b' || s === '\x1b\x1b') {
|
||||
// escape key
|
||||
key.name = 'escape';
|
||||
key.meta = (s.length === 2);
|
||||
|
||||
} else if (s === ' ' || s === '\x1b ') {
|
||||
key.name = 'space';
|
||||
key.meta = (s.length === 2);
|
||||
|
||||
} else if (s <= '\x1a') {
|
||||
// ctrl+letter
|
||||
key.name = String.fromCharCode(s.charCodeAt(0) + 'a'.charCodeAt(0) - 1);
|
||||
key.ctrl = true;
|
||||
|
||||
} else if (s.length === 1 && s >= 'a' && s <= 'z') {
|
||||
// lowercase letter
|
||||
key.name = s;
|
||||
|
||||
} else if (s.length === 1 && s >= 'A' && s <= 'Z') {
|
||||
// shift+letter
|
||||
key.name = s.toLowerCase();
|
||||
key.shift = true;
|
||||
|
||||
} else if (parts = metaKeyCodeRe.exec(s)) {
|
||||
// meta+character key
|
||||
key.name = parts[1].toLowerCase();
|
||||
key.meta = true;
|
||||
key.shift = /^[A-Z]$/.test(parts[1]);
|
||||
|
||||
} else if (parts = functionKeyCodeRe.exec(s)) {
|
||||
// ansi escape sequence
|
||||
|
||||
// reassemble the key code leaving out leading \x1b's,
|
||||
// the modifier key bitflag and any meaningless "1;" sequence
|
||||
var code = (parts[1] || '') + (parts[2] || '') +
|
||||
(parts[4] || '') + (parts[6] || ''),
|
||||
modifier = (parts[3] || parts[5] || 1) - 1;
|
||||
|
||||
// Parse the key modifier
|
||||
key.ctrl = !!(modifier & 4);
|
||||
key.meta = !!(modifier & 10);
|
||||
key.shift = !!(modifier & 1);
|
||||
key.code = code;
|
||||
|
||||
// Parse the key itself
|
||||
switch (code) {
|
||||
/* xterm/gnome ESC O letter */
|
||||
case 'OP': key.name = 'f1'; break;
|
||||
case 'OQ': key.name = 'f2'; break;
|
||||
case 'OR': key.name = 'f3'; break;
|
||||
case 'OS': key.name = 'f4'; break;
|
||||
|
||||
/* xterm/rxvt ESC [ number ~ */
|
||||
case '[11~': key.name = 'f1'; break;
|
||||
case '[12~': key.name = 'f2'; break;
|
||||
case '[13~': key.name = 'f3'; break;
|
||||
case '[14~': key.name = 'f4'; break;
|
||||
|
||||
/* from Cygwin and used in libuv */
|
||||
case '[[A': key.name = 'f1'; break;
|
||||
case '[[B': key.name = 'f2'; break;
|
||||
case '[[C': key.name = 'f3'; break;
|
||||
case '[[D': key.name = 'f4'; break;
|
||||
case '[[E': key.name = 'f5'; break;
|
||||
|
||||
/* common */
|
||||
case '[15~': key.name = 'f5'; break;
|
||||
case '[17~': key.name = 'f6'; break;
|
||||
case '[18~': key.name = 'f7'; break;
|
||||
case '[19~': key.name = 'f8'; break;
|
||||
case '[20~': key.name = 'f9'; break;
|
||||
case '[21~': key.name = 'f10'; break;
|
||||
case '[23~': key.name = 'f11'; break;
|
||||
case '[24~': key.name = 'f12'; break;
|
||||
|
||||
/* xterm ESC [ letter */
|
||||
case '[A': key.name = 'up'; break;
|
||||
case '[B': key.name = 'down'; break;
|
||||
case '[C': key.name = 'right'; break;
|
||||
case '[D': key.name = 'left'; break;
|
||||
case '[E': key.name = 'clear'; break;
|
||||
case '[F': key.name = 'end'; break;
|
||||
case '[H': key.name = 'home'; break;
|
||||
|
||||
/* xterm/gnome ESC O letter */
|
||||
case 'OA': key.name = 'up'; break;
|
||||
case 'OB': key.name = 'down'; break;
|
||||
case 'OC': key.name = 'right'; break;
|
||||
case 'OD': key.name = 'left'; break;
|
||||
case 'OE': key.name = 'clear'; break;
|
||||
case 'OF': key.name = 'end'; break;
|
||||
case 'OH': key.name = 'home'; break;
|
||||
|
||||
/* xterm/rxvt ESC [ number ~ */
|
||||
case '[1~': key.name = 'home'; break;
|
||||
case '[2~': key.name = 'insert'; break;
|
||||
case '[3~': key.name = 'delete'; break;
|
||||
case '[4~': key.name = 'end'; break;
|
||||
case '[5~': key.name = 'pageup'; break;
|
||||
case '[6~': key.name = 'pagedown'; break;
|
||||
|
||||
/* putty */
|
||||
case '[[5~': key.name = 'pageup'; break;
|
||||
case '[[6~': key.name = 'pagedown'; break;
|
||||
|
||||
/* rxvt */
|
||||
case '[7~': key.name = 'home'; break;
|
||||
case '[8~': key.name = 'end'; break;
|
||||
|
||||
/* rxvt keys with modifiers */
|
||||
case '[a': key.name = 'up'; key.shift = true; break;
|
||||
case '[b': key.name = 'down'; key.shift = true; break;
|
||||
case '[c': key.name = 'right'; key.shift = true; break;
|
||||
case '[d': key.name = 'left'; key.shift = true; break;
|
||||
case '[e': key.name = 'clear'; key.shift = true; break;
|
||||
|
||||
case '[2$': key.name = 'insert'; key.shift = true; break;
|
||||
case '[3$': key.name = 'delete'; key.shift = true; break;
|
||||
case '[5$': key.name = 'pageup'; key.shift = true; break;
|
||||
case '[6$': key.name = 'pagedown'; key.shift = true; break;
|
||||
case '[7$': key.name = 'home'; key.shift = true; break;
|
||||
case '[8$': key.name = 'end'; key.shift = true; break;
|
||||
|
||||
case 'Oa': key.name = 'up'; key.ctrl = true; break;
|
||||
case 'Ob': key.name = 'down'; key.ctrl = true; break;
|
||||
case 'Oc': key.name = 'right'; key.ctrl = true; break;
|
||||
case 'Od': key.name = 'left'; key.ctrl = true; break;
|
||||
case 'Oe': key.name = 'clear'; key.ctrl = true; break;
|
||||
|
||||
case '[2^': key.name = 'insert'; key.ctrl = true; break;
|
||||
case '[3^': key.name = 'delete'; key.ctrl = true; break;
|
||||
case '[5^': key.name = 'pageup'; key.ctrl = true; break;
|
||||
case '[6^': key.name = 'pagedown'; key.ctrl = true; break;
|
||||
case '[7^': key.name = 'home'; key.ctrl = true; break;
|
||||
case '[8^': key.name = 'end'; key.ctrl = true; break;
|
||||
|
||||
/* misc. */
|
||||
case '[Z': key.name = 'tab'; key.shift = true; break;
|
||||
default: key.name = 'undefined'; break;
|
||||
|
||||
}
|
||||
} else if (s.length > 1 && s[0] !== '\x1b') {
|
||||
// Got a longer-than-one string of characters.
|
||||
// Probably a paste, since it wasn't a control sequence.
|
||||
Array.prototype.forEach.call(s, function(c) {
|
||||
emitKey(stream, c);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.code == '[M') {
|
||||
key.name = 'mouse';
|
||||
var s = key.sequence;
|
||||
var b = s.charCodeAt(3);
|
||||
key.x = s.charCodeAt(4) - 040;
|
||||
key.y = s.charCodeAt(5) - 040;
|
||||
|
||||
key.scroll = 0;
|
||||
|
||||
key.ctrl = !!(1<<4 & b);
|
||||
key.meta = !!(1<<3 & b);
|
||||
key.shift = !!(1<<2 & b);
|
||||
|
||||
key.release = (3 & b) === 3;
|
||||
|
||||
if (1<<6 & b) { //scroll
|
||||
key.scroll = 1 & b ? 1 : -1;
|
||||
}
|
||||
|
||||
if (!key.release && !key.scroll) {
|
||||
key.button = b & 3;
|
||||
}
|
||||
}
|
||||
|
||||
// Don't emit a key if no name was found
|
||||
if (key.name === undefined) {
|
||||
key = undefined;
|
||||
}
|
||||
|
||||
if (s.length === 1) {
|
||||
ch = s;
|
||||
}
|
||||
|
||||
if (key && key.name == 'mouse') {
|
||||
stream.emit('mousepress', key)
|
||||
} else if (key || ch) {
|
||||
stream.emit('keypress', ch, key);
|
||||
}
|
||||
}
|
||||
20
node_modules/keypress/package.json
generated
vendored
Normal file
20
node_modules/keypress/package.json
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "keypress",
|
||||
"version": "0.1.0",
|
||||
"description": "Make any Node ReadableStream emit \"keypress\" events",
|
||||
"author": "Nathan Rajlich <nathan@tootallnate.net> (http://tootallnate.net)",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/TooTallNate/keypress.git"
|
||||
},
|
||||
"keywords": [
|
||||
"keypress",
|
||||
"readline",
|
||||
"core"
|
||||
],
|
||||
"license": "MIT"
|
||||
}
|
||||
28
node_modules/keypress/test.js
generated
vendored
Normal file
28
node_modules/keypress/test.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
var keypress = require('./')
|
||||
keypress(process.stdin)
|
||||
|
||||
if (process.stdin.setRawMode)
|
||||
process.stdin.setRawMode(true)
|
||||
else
|
||||
require('tty').setRawMode(true)
|
||||
|
||||
process.stdin.on('keypress', function (c, key) {
|
||||
console.log(0, c, key)
|
||||
if (key && key.ctrl && key.name == 'c') {
|
||||
process.stdin.pause()
|
||||
}
|
||||
})
|
||||
process.stdin.on('mousepress', function (mouse) {
|
||||
console.log(mouse)
|
||||
})
|
||||
|
||||
keypress.enableMouse(process.stdout)
|
||||
process.on('exit', function () {
|
||||
//disable mouse on exit, so that the state is back to normal
|
||||
//for the terminal.
|
||||
keypress.disableMouse(process.stdout)
|
||||
})
|
||||
|
||||
process.stdin.resume()
|
||||
|
||||
21
node_modules/luch-request/LICENSE.txt
generated
vendored
Normal file
21
node_modules/luch-request/LICENSE.txt
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) [2022] [luch]
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
70
node_modules/luch-request/history.md
generated
vendored
Normal file
70
node_modules/luch-request/history.md
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
## [3.0.8](https://github.com/lei-mu/luch-request/compare/3.0.7...3.0.8) (2022-08-23)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* `put` 方法增加快手小程序和京东小程序的支持 ([7e15dff](https://github.com/lei-mu/luch-request/commit/7e15dff0ac343ccbd6a298c7c9ae8ef0e2148eb9))
|
||||
* 参考axio源代码 添加支持paramsSerializer。 ([cae1043](https://github.com/lei-mu/luch-request/commit/cae10430dc7222d85e0cadb13512898d66998547))
|
||||
* 返回数据增加`rawData`,保留返回的原始数据 ([3924b7c](https://github.com/lei-mu/luch-request/commit/3924b7c3ea444526be436a31f9e7d5623749580b))
|
||||
* 局部请求配置支持baseURL ([df2d98f](https://github.com/lei-mu/luch-request/commit/df2d98fc063f356ffd525158e9cd47d7eb24f68f))
|
||||
|
||||
|
||||
|
||||
|
||||
## 3.0.7 (2021-09-04)
|
||||
|
||||
1. Bug Fix: 修复通过 `Request.config` 设置全局参数,多个实例`config`存在共同引用bug
|
||||
|
||||
|
||||
## 3.0.6 (2021-05-10)
|
||||
|
||||
1. New Feature: APP端 增加`responseType`配置项
|
||||
|
||||
## 3.0.5 (2021-01-10)
|
||||
### Features
|
||||
|
||||
* [重要] APP不再支持`CONNECT`、`HEAD`、`TRACE`请求方式。[uni.request](https://uniapp.dcloud.io/api/request/request)
|
||||
* [重要]全局默认`timeout`由`30000`ms,改为`60000`ms
|
||||
* [重要]增加`index.d.ts`文件支持。感谢`Mr_Mao`的支持。github:`https://github.com/TuiMao233`
|
||||
* [重要]网络请求相关接口 uni.request、uni.uploadFile、uni.downloadFile 支持 timeout 参数。
|
||||
* [重要]返回结果response 增加`fullPath`参数。
|
||||
|
||||
## 3.0.4 (2020-07-05)
|
||||
|
||||
1. New Feature: request 方法增加 ` firstIpv4 `配置项
|
||||
1. New Feature: 增加 ` middleware `通用请求方法
|
||||
|
||||
## 3.0.3 (2020-06-16)
|
||||
|
||||
1. Bug Fix: 修复` params ` 选项对数组格式化错误bug
|
||||
|
||||
## 3.0.2 (2020-06-04)
|
||||
|
||||
1. Bug Fix: 修复文件上传和request 配置缺少字段bug
|
||||
|
||||
## 3.0.1 (2020-06-02)
|
||||
|
||||
1. Bug Fix: 请求方式都为` GET `的bug
|
||||
|
||||
## 3.0.0 (2020-06-01)
|
||||
|
||||
1. New Feature: 支持多拦截器
|
||||
1. New Feature: 支持局部配置自定义验证器
|
||||
|
||||
## 2.0.1 (2020-05-01)
|
||||
|
||||
1. Bug Fix: 修复多实例全局配置共用问题
|
||||
|
||||
## 2.0.0 (2020-04-24)
|
||||
|
||||
1. New Feature: 增加 request ` withCredentials `选项(仅h5端支持)
|
||||
1. New Feature: h5端 upload 增加 ` files ` ` file `选项。[uni.uploadFile](https://uniapp.dcloud.io/api/request/network-file?id=uploadfile "uni.uploadFile")
|
||||
1. Enhancement: ` params ` 选项参数格式化方法使用axios 格式化方法
|
||||
1. Bug Fix: 对upload 返回data 为空字符串的情况容错
|
||||
1. Change: 修改header与全局合并方式。当前:header = Object.assign(全局,局部)
|
||||
|
||||
## 0.0.0 (2019-05)
|
||||
|
||||
1. luch-request created
|
||||
|
||||
|
||||
106
node_modules/luch-request/package.json
generated
vendored
Normal file
106
node_modules/luch-request/package.json
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
{
|
||||
"name": "luch-request",
|
||||
"version": "3.0.8",
|
||||
"description": "基于Promise实现uni-app request 请求插件",
|
||||
"keywords": [
|
||||
"uni-app",
|
||||
"request",
|
||||
"Promise",
|
||||
"luch",
|
||||
"luch-request"
|
||||
],
|
||||
"main": "src/lib/luch-request.js",
|
||||
"scripts": {
|
||||
"dev": "rollup -c",
|
||||
"watch": "rollup -c -w",
|
||||
"build": "rimraf DCloud && rollup -c --environment NODE_ENV:production",
|
||||
"zipD": "node node/zipDCloudPlugin.js && node node/zipDCloudDemo.js",
|
||||
"docs": "vuepress dev docs",
|
||||
"docs:build": "vuepress build docs",
|
||||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -w -r 0",
|
||||
"pub": "npm publish && cnpm sync luch-request",
|
||||
"pub:alpha": "npm publish --tag=alpha && cnpm sync luch-request",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/lei-mu/luch-request.git"
|
||||
},
|
||||
"author": "luch",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/lei-mu/luch-request/issues"
|
||||
},
|
||||
"homepage": "https://www.quanzhan.co/luch-request/",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.9.0",
|
||||
"@babel/plugin-proposal-class-properties": "^7.8.3",
|
||||
"@babel/plugin-transform-arrow-functions": "^7.8.3",
|
||||
"@babel/preset-env": "^7.9.5",
|
||||
"@vuepress/plugin-active-header-links": "^1.5.0",
|
||||
"@vuepress/plugin-pwa": "^1.5.2",
|
||||
"archiver": "^4.0.1",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"commitizen": "^4.2.4",
|
||||
"conventional-changelog-cli": "^2.1.1",
|
||||
"cz-conventional-changelog": "^3.2.0",
|
||||
"eslint": "^6.8.0",
|
||||
"grunt": "^1.1.0",
|
||||
"grunt-babel": "^8.0.0",
|
||||
"load-grunt-tasks": "^5.1.0",
|
||||
"node-zip": "^1.1.1",
|
||||
"rollup-plugin-babel": "^4.4.0",
|
||||
"rollup-plugin-commonjs": "^10.1.0",
|
||||
"rollup-plugin-copy": "^3.3.0",
|
||||
"rollup-plugin-eslint": "^7.0.0",
|
||||
"rollup-plugin-json": "^4.0.0",
|
||||
"rollup-plugin-live-server": "^1.0.3",
|
||||
"rollup-plugin-node-resolve": "^5.2.0",
|
||||
"rollup-plugin-replace": "^2.2.0",
|
||||
"rollup-plugin-uglify": "^6.0.4",
|
||||
"rollup-plugin-zip": "^1.0.0",
|
||||
"validate-commit-msg": "^2.14.0",
|
||||
"vuepress": "^1.4.1"
|
||||
},
|
||||
"config": {
|
||||
"commitizen": {
|
||||
"path": "./node_modules/cz-conventional-changelog"
|
||||
},
|
||||
"ghooks": {
|
||||
"commit-msg": "validate-commit-msg"
|
||||
},
|
||||
"validate-commit-msg": {
|
||||
"types": [
|
||||
"feat",
|
||||
"fix",
|
||||
"docs",
|
||||
"style",
|
||||
"refactor",
|
||||
"perf",
|
||||
"test",
|
||||
"build",
|
||||
"ci",
|
||||
"chore",
|
||||
"revert"
|
||||
],
|
||||
"scope": {
|
||||
"required": false,
|
||||
"allowed": [
|
||||
"*"
|
||||
],
|
||||
"validate": false,
|
||||
"multiple": false
|
||||
},
|
||||
"warnOnFail": false,
|
||||
"maxSubjectLength": 100,
|
||||
"subjectPattern": ".+",
|
||||
"subjectPatternErrorMsg": "subject does not match subject pattern!",
|
||||
"helpMessage": "",
|
||||
"autoFix": false
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@dcloudio/types": "^2.0.16"
|
||||
}
|
||||
}
|
||||
260
node_modules/luch-request/readme.md
generated
vendored
Normal file
260
node_modules/luch-request/readme.md
generated
vendored
Normal file
@@ -0,0 +1,260 @@
|
||||
# luch-request
|
||||
|
||||
[](https://www.npmjs.com/package/luch-request "npm")
|
||||
[](https://www.npmjs.com/package/luch-request "npm")
|
||||
[](https://github.com/lei-mu/luch-request "github")
|
||||
[](https://github.com/lei-mu/luch-request "github stars")
|
||||
[](https://github.com/lei-mu/luch-request "github forks")
|
||||
|
||||
- 基于 Promise 对象实现更简单的 request 使用方式,支持请求和响应拦截
|
||||
- 支持全局挂载
|
||||
- 支持多个全局配置实例
|
||||
- 支持自定义验证器
|
||||
- 支持文件上传/下载
|
||||
- 支持task 操作
|
||||
- 支持自定义参数
|
||||
- 支持多拦截器
|
||||
- 对参数的处理比uni.request 更强
|
||||
|
||||
安装
|
||||
------------
|
||||
###### 使用npm
|
||||
|
||||
``` javascript
|
||||
npm i luch-request -S
|
||||
```
|
||||
使用npm前阅读[快速上手](https://www.quanzhan.co/luch-request/handbook/#npm "快速上手")
|
||||
|
||||
|
||||
###### github
|
||||
|
||||
[github](https://github.com/lei-mu/luch-request "github")
|
||||
安装依赖后 ` npm run build ` ,使用DCloud/luch-request 文件夹即可
|
||||
|
||||
|
||||
###### DCloud插件市场:
|
||||
|
||||
[DCloud插件市场](https://ext.dcloud.net.cn/plugin?id=392 "DCloud插件市场")
|
||||
|
||||
Example
|
||||
------------
|
||||
创建实例
|
||||
|
||||
``` javascript
|
||||
import Request from '@/utils/luch-request/index.js' // 下载的插件
|
||||
// import Request from 'luch-request' // 使用npm
|
||||
|
||||
const http = new Request();
|
||||
```
|
||||
|
||||
执行` GET `请求
|
||||
|
||||
``` javascript
|
||||
http.get('/user/login', {params: {userName: 'name', password: '123456'}}).then(res => {
|
||||
|
||||
}).catch(err => {
|
||||
|
||||
})
|
||||
// 局部修改配置,局部配置优先级高于全局配置
|
||||
http.get('/user/login', {
|
||||
params: {userName: 'name', password: '123456'}, /* 会加在url上 */
|
||||
header: {}, /* 会与全局header合并,如有同名属性,局部覆盖全局 */
|
||||
dataType: 'json',
|
||||
// 注:如果局部custom与全局custom有同名属性,则后面的属性会覆盖前面的属性,相当于Object.assign(全局,局部)
|
||||
custom: {auth: true}, // 可以加一些自定义参数,在拦截器等地方使用。比如这里我加了一个auth,可在拦截器里拿到,如果true就传token
|
||||
// #ifndef MP-ALIPAY
|
||||
responseType: 'text',
|
||||
// #endif
|
||||
// #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN
|
||||
timeout: 60000, // H5(HBuilderX 2.9.9+)、APP(HBuilderX 2.9.9+)、微信小程序(2.10.0)、支付宝小程序
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
sslVerify: true, // 验证 ssl 证书 仅5+App安卓端支持(HBuilderX 2.3.3+)
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
withCredentials: false, // 跨域请求时是否携带凭证(cookies)仅H5支持(HBuilderX 2.6.15+)
|
||||
// #endif
|
||||
// 返回当前请求的task, options。请勿在此处修改options。非必填
|
||||
getTask: (task, options) => {
|
||||
// setTimeout(() => {
|
||||
// task.abort()
|
||||
// }, 500)
|
||||
},
|
||||
// 自定义验证器。statusCode必存在。非必填
|
||||
validateStatus: function validateStatus(statusCode) {
|
||||
return statusCode >= 200 && statusCode < 300
|
||||
}
|
||||
}).then(res => {
|
||||
|
||||
}).catch(err => {
|
||||
|
||||
})
|
||||
```
|
||||
执行` POST `请求
|
||||
|
||||
``` javascript
|
||||
http.post('/user/login', {userName: 'name', password: '123456'} ).then(res => {
|
||||
|
||||
}).catch(err => {
|
||||
|
||||
})
|
||||
// 局部修改配置,局部配置优先级高于全局配置
|
||||
http.post('/user/login', {userName: 'name', password: '123456'}, {
|
||||
params: {}, /* 会加在url上 */
|
||||
header: {}, /* 会与全局header合并,如有同名属性,局部覆盖全局 */
|
||||
dataType: 'json',
|
||||
// 注:如果局部custom与全局custom有同名属性,则后面的属性会覆盖前面的属性,相当于Object.assign(全局,局部)
|
||||
custom: {auth: true}, // 可以加一些自定义参数,在拦截器等地方使用。比如这里我加了一个auth,可在拦截器里拿到,如果true就传token
|
||||
// #ifndef MP-ALIPAY
|
||||
responseType: 'text',
|
||||
// #endif
|
||||
// #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN
|
||||
timeout: 60000, // H5(HBuilderX 2.9.9+)、APP(HBuilderX 2.9.9+)、微信小程序(2.10.0)、支付宝小程序
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
sslVerify: true, // 验证 ssl 证书 仅5+App安卓端支持(HBuilderX 2.3.3+)
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
withCredentials: false, // 跨域请求时是否携带凭证(cookies)仅H5支持(HBuilderX 2.6.15+)
|
||||
// #endif
|
||||
// 返回当前请求的task, options。请勿在此处修改options。非必填
|
||||
getTask: (task, options) => {
|
||||
// setTimeout(() => {
|
||||
// task.abort()
|
||||
// }, 500)
|
||||
},
|
||||
// 自定义验证器。statusCode必存在。非必填
|
||||
validateStatus: function validateStatus(statusCode) {
|
||||
return statusCode >= 200 && statusCode < 300
|
||||
}
|
||||
}).then(res => {
|
||||
|
||||
}).catch(err => {
|
||||
|
||||
})
|
||||
```
|
||||
执行` upload `请求
|
||||
|
||||
``` javascript
|
||||
http.upload('api/upload/img', {
|
||||
params: {}, /* 会加在url上 */
|
||||
// #ifdef APP-PLUS || H5
|
||||
files: [], // 需要上传的文件列表。使用 files 时,filePath 和 name 不生效。App、H5( 2.6.15+)
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
fileType: 'image/video/audio', // 仅支付宝小程序,且必填。
|
||||
// #endif
|
||||
filePath: '', // 要上传文件资源的路径。
|
||||
// 注:如果局部custom与全局custom有同名属性,则后面的属性会覆盖前面的属性,相当于Object.assign(全局,局部)
|
||||
custom: {auth: true}, // 可以加一些自定义参数,在拦截器等地方使用。比如这里我加了一个auth,可在拦截器里拿到,如果true就传token
|
||||
name: 'file', // 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容
|
||||
// #ifdef H5 || APP-PLUS
|
||||
timeout: 60000, // H5(HBuilderX 2.9.9+)、APP(HBuilderX 2.9.9+)
|
||||
// #endif
|
||||
header: {}, /* 会与全局header合并,如有同名属性,局部覆盖全局 */
|
||||
formData: {}, // HTTP 请求中其他额外的 form data
|
||||
// 返回当前请求的task, options。请勿在此处修改options。非必填
|
||||
getTask: (task, options) => {
|
||||
// task.onProgressUpdate((res) => {
|
||||
// console.log('上传进度' + res.progress);
|
||||
// console.log('已经上传的数据长度' + res.totalBytesSent);
|
||||
// console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
|
||||
//
|
||||
// // 测试条件,取消上传任务。
|
||||
// if (res.progress > 50) {
|
||||
// uploadTask.abort();
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}).then(res => {
|
||||
// 返回的res.data 已经进行JSON.parse
|
||||
}).catch(err => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
luch-request Guide
|
||||
------------
|
||||
[luch-request 官网地址](https://www.quanzhan.co/luch-request/ "luch-request 官网地址")
|
||||
<br>
|
||||
[github](https://github.com/lei-mu/luch-request "github")
|
||||
|
||||
友情链接
|
||||
------------
|
||||
#### vue-admin-beautiful
|
||||
**vue-admin-beautiful** ——<a href="https://github.com/chuzhixin/vue-admin-beautiful" target="_blank">企业级、通用型中后台前端解决方案(基于vue/cli 4 最新版,同时支持电脑,手机,平板)</a>
|
||||
|
||||
**vue-admin-beautiful** ——<a href="http://beautiful.panm.cn/vue-admin-beautiful/#/index" target="_blank">在线演示</a>
|
||||
|
||||
#### uView
|
||||
<a href="https://uviewui.com" target="_blank">uView 文档</a> ——超棒的移动跨端框架,文档详细,上手容易
|
||||
|
||||
常见问题
|
||||
------------
|
||||
1. 为什么会请求两次?
|
||||
- 总有些小白问这些很那啥的问题,有两种可能,一种是‘post三次握手’,还有一种可能是`本地访问接口时跨域请求,所以浏览器会先发一个option 去预测能否成功,然后再发一个真正的请求`(自己观察请求头,Request Method,百度简单请求)。
|
||||
2. 如何跨域?
|
||||
- 问的人不少,可以先百度了解一下。<a href="https://ask.dcloud.net.cn/article/35267" target="_blank">如何跨域</a>
|
||||
3. post 怎么传不了数组的参数啊?
|
||||
- <a href="https://uniapp.dcloud.io/api/request/request" target="_blank">uni-request</a> <br>
|
||||
可以点击看一下uni-request 的api 文档,data支持的文件类型只有<code>Object/String/ArrayBuffer</code>这个真跟我没啥关系 0.0
|
||||
4. TypeError: undefined is not an object (evaluating 'this.$http.get')
|
||||
- 不知道为啥问的人这么多?太基础了,百度学习一下 export default 和export,头大。
|
||||
- `import { http } from '@/utils/luch-request/index.js'`
|
||||
5. 什么参数需要在` setConfig ` 设置?什么参数需要在` request ` 拦截器设置?
|
||||
- ` setConfig ` 适用于设置一些静态的/默认的参数;比如header 里的一些默认值、默认全局参数(全局请求配置)。` token ` 并不适合在这里设置。
|
||||
- ` interceptors.request ` 拦截器适用范围较广,但我仍然建议把一些静态的东西放在 ` setConfig ` 里。拦截器会在每次请求调用,而 ` setConfig ` 仅在调用时修改一遍。
|
||||
|
||||
tip
|
||||
------------
|
||||
- nvue 不支持全局挂载
|
||||
- 当前的hbuilderx 版本号:beat-3.0.4 alpha-3.0.4
|
||||
- 推荐使用下载插件的方式使用。如果本插件完全满足你的需求可直接使用 ` npm `安装
|
||||
- license: MIT
|
||||
|
||||
|
||||
issue
|
||||
------------
|
||||
- DCloud: 有任何问题或者建议可以=> <a href="https://ask.dcloud.net.cn/question/74922" target="_blank">issue提交</a>,先给个五星好评QAQ!!
|
||||
- github: [Issues](https://github.com/lei-mu/luch-request/issues "Issues")
|
||||
|
||||
|
||||
作者想说
|
||||
------------
|
||||
- 写代码很容易,为了让你们看懂写文档真的很lei 0.0
|
||||
- 最近发现有插件与我雷同,当初接触uni-app 就发现插件市场虽然有封装的不错的request库,但是都没有对多全局配置做处理,都是通过修改源码的方式配置。我首先推出通过class类,并仿照axios的api实现request请求库,并起名‘仿axios封装request网络请求库,支持拦截器全局配置’。他们虽然修改了部分代码,但是功能与性能并没有优化,反而使代码很冗余。希望能推出新的功能,和性能更加强悍的请求库。(2019-05)
|
||||
- 任何形式的‘参考’、‘借鉴’,请标明作者
|
||||
```javascript
|
||||
<a href="https://ext.dcloud.net.cn/plugin?id=392">luch-request</a>
|
||||
```
|
||||
- 关于问问题
|
||||
1. 首先请善于利用搜索引擎,不管百度,还是Google,遇到问题请先自己尝试解决。自己尝试过无法解决,再问。
|
||||
2. 不要问类似为什么我的xx无法使用这种问题。请仔细阅读文档,检查代码,或者说明运行环境,把相关代码贴至评论或者发送至我的邮箱,还可以点击上面的issue提交,在里面提问,可能我在里面已经回答了。
|
||||
3. 我的代码如果真的出现bug,或者你有好的建议、需求,可以提issue,我看到后会立即解决
|
||||
|
||||
- 如何问问题
|
||||
1. 问问题之前请换位思考,如果自己要解决这个问题,需要哪些信息
|
||||
2. 仔细阅读文档,检查代码
|
||||
3. 说明运行环境,比如:app端 ios、android 版本号、手机机型、普遍现象还是个别现象(越详细越好)
|
||||
4. 发出代码片段或者截图至邮箱(很重要)
|
||||
5. 或者可以在上方的'issue提交' 里发出详细的问题描述
|
||||
6. 以上都觉得解决不了你的问题,可以加QQ:`370306150`
|
||||
|
||||
个人网站
|
||||
------------
|
||||
- 欢迎大家都来踩一踩<a href="https://www.quanzhan.co/" target="_blank">luch的博客</a> 0.0
|
||||
|
||||
|
||||
|
||||
|
||||
土豪赞赏
|
||||
------------
|
||||
[](https://www.quanzhan.co/luch-request/acknowledgement/#前言 "wechat 打赏")
|
||||
[](https://www.quanzhan.co/luch-request/acknowledgement/#前言 "支付宝 打赏")
|
||||
|
||||
[打赏事宜具体说明](https://www.quanzhan.co/luch-request/acknowledgement/#前言 "打赏事宜具体说明")
|
||||
|
||||
|
||||
###### 您的鼓励是我更新的动力
|
||||
|
||||
#### 创作不易,五星好评你懂得!
|
||||
100
node_modules/luch-request/src/lib/adapters/index.js
generated
vendored
Normal file
100
node_modules/luch-request/src/lib/adapters/index.js
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
import buildURL from '../helpers/buildURL'
|
||||
import buildFullPath from '../core/buildFullPath'
|
||||
import settle from '../core/settle'
|
||||
import {isUndefined} from "../utils"
|
||||
|
||||
/**
|
||||
* 返回可选值存在的配置
|
||||
* @param {Array} keys - 可选值数组
|
||||
* @param {Object} config2 - 配置
|
||||
* @return {{}} - 存在的配置项
|
||||
*/
|
||||
const mergeKeys = (keys, config2) => {
|
||||
let config = {}
|
||||
keys.forEach(prop => {
|
||||
if (!isUndefined(config2[prop])) {
|
||||
config[prop] = config2[prop]
|
||||
}
|
||||
})
|
||||
return config
|
||||
}
|
||||
export default (config) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let fullPath = buildURL(buildFullPath(config.baseURL, config.url), config.params, config.paramsSerializer)
|
||||
const _config = {
|
||||
url: fullPath,
|
||||
header: config.header,
|
||||
complete: (response) => {
|
||||
config.fullPath = fullPath
|
||||
response.config = config
|
||||
response.rawData = response.data
|
||||
try {
|
||||
// 对可能字符串不是json 的情况容错
|
||||
if (typeof response.data === 'string') {
|
||||
response.data = JSON.parse(response.data)
|
||||
}
|
||||
// eslint-disable-next-line no-empty
|
||||
} catch (e) {
|
||||
}
|
||||
settle(resolve, reject, response)
|
||||
}
|
||||
}
|
||||
let requestTask
|
||||
if (config.method === 'UPLOAD') {
|
||||
delete _config.header['content-type']
|
||||
delete _config.header['Content-Type']
|
||||
let otherConfig = {
|
||||
// #ifdef MP-ALIPAY
|
||||
fileType: config.fileType,
|
||||
// #endif
|
||||
filePath: config.filePath,
|
||||
name: config.name
|
||||
}
|
||||
const optionalKeys = [
|
||||
// #ifdef APP-PLUS || H5
|
||||
'files',
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
'file',
|
||||
// #endif
|
||||
// #ifdef H5 || APP-PLUS
|
||||
'timeout',
|
||||
// #endif
|
||||
'formData'
|
||||
]
|
||||
requestTask = uni.uploadFile({..._config, ...otherConfig, ...mergeKeys(optionalKeys, config)})
|
||||
} else if (config.method === 'DOWNLOAD') {
|
||||
// #ifdef H5 || APP-PLUS
|
||||
if (!isUndefined(config['timeout'])) {
|
||||
_config['timeout'] = config['timeout']
|
||||
}
|
||||
// #endif
|
||||
requestTask = uni.downloadFile(_config)
|
||||
} else {
|
||||
const optionalKeys = [
|
||||
'data',
|
||||
'method',
|
||||
// #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN
|
||||
'timeout',
|
||||
// #endif
|
||||
'dataType',
|
||||
// #ifndef MP-ALIPAY
|
||||
'responseType',
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
'sslVerify',
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
'withCredentials',
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
'firstIpv4',
|
||||
// #endif
|
||||
]
|
||||
requestTask = uni.request({..._config, ...mergeKeys(optionalKeys, config)})
|
||||
}
|
||||
if (config.getTask) {
|
||||
config.getTask(requestTask, config)
|
||||
}
|
||||
})
|
||||
}
|
||||
51
node_modules/luch-request/src/lib/core/InterceptorManager.js
generated
vendored
Normal file
51
node_modules/luch-request/src/lib/core/InterceptorManager.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
'use strict'
|
||||
|
||||
|
||||
function InterceptorManager() {
|
||||
this.handlers = []
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new interceptor to the stack
|
||||
*
|
||||
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
||||
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
||||
*
|
||||
* @return {Number} An ID used to remove interceptor later
|
||||
*/
|
||||
InterceptorManager.prototype.use = function use(fulfilled, rejected) {
|
||||
this.handlers.push({
|
||||
fulfilled: fulfilled,
|
||||
rejected: rejected
|
||||
})
|
||||
return this.handlers.length - 1
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an interceptor from the stack
|
||||
*
|
||||
* @param {Number} id The ID that was returned by `use`
|
||||
*/
|
||||
InterceptorManager.prototype.eject = function eject(id) {
|
||||
if (this.handlers[id]) {
|
||||
this.handlers[id] = null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over all the registered interceptors
|
||||
*
|
||||
* This method is particularly useful for skipping over any
|
||||
* interceptors that may have become `null` calling `eject`.
|
||||
*
|
||||
* @param {Function} fn The function to call for each interceptor
|
||||
*/
|
||||
InterceptorManager.prototype.forEach = function forEach(fn) {
|
||||
this.handlers.forEach(h => {
|
||||
if (h !== null) {
|
||||
fn(h)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default InterceptorManager
|
||||
197
node_modules/luch-request/src/lib/core/Request.js
generated
vendored
Normal file
197
node_modules/luch-request/src/lib/core/Request.js
generated
vendored
Normal file
@@ -0,0 +1,197 @@
|
||||
/**
|
||||
* @Class Request
|
||||
* @description luch-request http请求插件
|
||||
* @Author lu-ch
|
||||
* @Email webwork.s@qq.com
|
||||
* 文档: https://www.quanzhan.co/luch-request/
|
||||
* github: https://github.com/lei-mu/luch-request
|
||||
* DCloud: http://ext.dcloud.net.cn/plugin?id=392
|
||||
*/
|
||||
|
||||
|
||||
import dispatchRequest from './dispatchRequest'
|
||||
import InterceptorManager from './InterceptorManager'
|
||||
import mergeConfig from './mergeConfig'
|
||||
import defaults from './defaults'
|
||||
import { isPlainObject } from '../utils'
|
||||
import clone from '../utils/clone'
|
||||
|
||||
export default class Request {
|
||||
/**
|
||||
* @param {Object} arg - 全局配置
|
||||
* @param {String} arg.baseURL - 全局根路径
|
||||
* @param {Object} arg.header - 全局header
|
||||
* @param {String} arg.method = [GET|POST|PUT|DELETE|CONNECT|HEAD|OPTIONS|TRACE] - 全局默认请求方式
|
||||
* @param {String} arg.dataType = [json] - 全局默认的dataType
|
||||
* @param {String} arg.responseType = [text|arraybuffer] - 全局默认的responseType。支付宝小程序不支持
|
||||
* @param {Object} arg.custom - 全局默认的自定义参数
|
||||
* @param {Number} arg.timeout - 全局默认的超时时间,单位 ms。默认60000。H5(HBuilderX 2.9.9+)、APP(HBuilderX 2.9.9+)、微信小程序(2.10.0)、支付宝小程序
|
||||
* @param {Boolean} arg.sslVerify - 全局默认的是否验证 ssl 证书。默认true.仅App安卓端支持(HBuilderX 2.3.3+)
|
||||
* @param {Boolean} arg.withCredentials - 全局默认的跨域请求时是否携带凭证(cookies)。默认false。仅H5支持(HBuilderX 2.6.15+)
|
||||
* @param {Boolean} arg.firstIpv4 - 全DNS解析时优先使用ipv4。默认false。仅 App-Android 支持 (HBuilderX 2.8.0+)
|
||||
* @param {Function(statusCode):Boolean} arg.validateStatus - 全局默认的自定义验证器。默认statusCode >= 200 && statusCode < 300
|
||||
*/
|
||||
constructor(arg = {}) {
|
||||
if (!isPlainObject(arg)) {
|
||||
arg = {}
|
||||
console.warn('设置全局参数必须接收一个Object')
|
||||
}
|
||||
this.config = clone({...defaults, ...arg})
|
||||
this.interceptors = {
|
||||
request: new InterceptorManager(),
|
||||
response: new InterceptorManager()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Function
|
||||
* @param {Request~setConfigCallback} f - 设置全局默认配置
|
||||
*/
|
||||
setConfig(f) {
|
||||
this.config = f(this.config)
|
||||
}
|
||||
|
||||
middleware(config) {
|
||||
config = mergeConfig(this.config, config)
|
||||
let chain = [dispatchRequest, undefined]
|
||||
let promise = Promise.resolve(config)
|
||||
|
||||
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
||||
chain.unshift(interceptor.fulfilled, interceptor.rejected)
|
||||
})
|
||||
|
||||
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
||||
chain.push(interceptor.fulfilled, interceptor.rejected)
|
||||
})
|
||||
|
||||
while (chain.length) {
|
||||
promise = promise.then(chain.shift(), chain.shift())
|
||||
}
|
||||
|
||||
return promise
|
||||
}
|
||||
|
||||
/**
|
||||
* @Function
|
||||
* @param {Object} config - 请求配置项
|
||||
* @prop {String} options.url - 请求路径
|
||||
* @prop {Object} options.data - 请求参数
|
||||
* @prop {Object} [options.responseType = config.responseType] [text|arraybuffer] - 响应的数据类型
|
||||
* @prop {Object} [options.dataType = config.dataType] - 如果设为 json,会尝试对返回的数据做一次 JSON.parse
|
||||
* @prop {Object} [options.header = config.header] - 请求header
|
||||
* @prop {Object} [options.method = config.method] - 请求方法
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
request(config = {}) {
|
||||
return this.middleware(config)
|
||||
}
|
||||
|
||||
get(url, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
method: 'GET',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
post(url, data, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
data,
|
||||
method: 'POST',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
// #ifndef MP-ALIPAY || MP-KUAISHOU || MP-JD
|
||||
put(url, data, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
data,
|
||||
method: 'PUT',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-BAIDU
|
||||
delete(url, data, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
data,
|
||||
method: 'DELETE',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
// #ifdef H5 || MP-WEIXIN
|
||||
connect(url, data, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
data,
|
||||
method: 'CONNECT',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
// #ifdef H5 || MP-WEIXIN || MP-BAIDU
|
||||
head(url, data, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
data,
|
||||
method: 'HEAD',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-BAIDU
|
||||
options(url, data, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
data,
|
||||
method: 'OPTIONS',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
// #ifdef H5 || MP-WEIXIN
|
||||
trace(url, data, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
data,
|
||||
method: 'TRACE',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
upload(url, config = {}) {
|
||||
config.url = url
|
||||
config.method = 'UPLOAD'
|
||||
return this.middleware(config)
|
||||
}
|
||||
|
||||
download(url, config = {}) {
|
||||
config.url = url
|
||||
config.method = 'DOWNLOAD'
|
||||
return this.middleware(config)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* setConfig回调
|
||||
* @return {Object} - 返回操作后的config
|
||||
* @callback Request~setConfigCallback
|
||||
* @param {Object} config - 全局默认config
|
||||
*/
|
||||
20
node_modules/luch-request/src/lib/core/buildFullPath.js
generated
vendored
Normal file
20
node_modules/luch-request/src/lib/core/buildFullPath.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
import isAbsoluteURL from '../helpers/isAbsoluteURL'
|
||||
import combineURLs from '../helpers/combineURLs'
|
||||
|
||||
/**
|
||||
* Creates a new URL by combining the baseURL with the requestedURL,
|
||||
* only when the requestedURL is not already an absolute URL.
|
||||
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
||||
*
|
||||
* @param {string} baseURL The base URL
|
||||
* @param {string} requestedURL Absolute or relative URL to combine
|
||||
* @returns {string} The combined full path
|
||||
*/
|
||||
export default function buildFullPath(baseURL, requestedURL) {
|
||||
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
||||
return combineURLs(baseURL, requestedURL)
|
||||
}
|
||||
return requestedURL
|
||||
}
|
||||
31
node_modules/luch-request/src/lib/core/defaults.js
generated
vendored
Normal file
31
node_modules/luch-request/src/lib/core/defaults.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* 默认的全局配置
|
||||
*/
|
||||
|
||||
|
||||
export default {
|
||||
baseURL: '',
|
||||
header: {},
|
||||
method: 'GET',
|
||||
dataType: 'json',
|
||||
paramsSerializer: null,
|
||||
// #ifndef MP-ALIPAY
|
||||
responseType: 'text',
|
||||
// #endif
|
||||
custom: {},
|
||||
// #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN
|
||||
timeout: 60000,
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
sslVerify: true,
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
withCredentials: false,
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
firstIpv4: false,
|
||||
// #endif
|
||||
validateStatus: function validateStatus(status) {
|
||||
return status >= 200 && status < 300
|
||||
}
|
||||
}
|
||||
6
node_modules/luch-request/src/lib/core/dispatchRequest.js
generated
vendored
Normal file
6
node_modules/luch-request/src/lib/core/dispatchRequest.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import adapter from '../adapters/index'
|
||||
|
||||
|
||||
export default (config) => {
|
||||
return adapter(config)
|
||||
}
|
||||
103
node_modules/luch-request/src/lib/core/mergeConfig.js
generated
vendored
Normal file
103
node_modules/luch-request/src/lib/core/mergeConfig.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
import {deepMerge, isUndefined} from '../utils'
|
||||
|
||||
/**
|
||||
* 合并局部配置优先的配置,如果局部有该配置项则用局部,如果全局有该配置项则用全局
|
||||
* @param {Array} keys - 配置项
|
||||
* @param {Object} globalsConfig - 当前的全局配置
|
||||
* @param {Object} config2 - 局部配置
|
||||
* @return {{}}
|
||||
*/
|
||||
const mergeKeys = (keys, globalsConfig, config2) => {
|
||||
let config = {}
|
||||
keys.forEach(prop => {
|
||||
if (!isUndefined(config2[prop])) {
|
||||
config[prop] = config2[prop]
|
||||
} else if (!isUndefined(globalsConfig[prop])) {
|
||||
config[prop] = globalsConfig[prop]
|
||||
}
|
||||
})
|
||||
return config
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param globalsConfig - 当前实例的全局配置
|
||||
* @param config2 - 当前的局部配置
|
||||
* @return - 合并后的配置
|
||||
*/
|
||||
export default (globalsConfig, config2 = {}) => {
|
||||
const method = config2.method || globalsConfig.method || 'GET'
|
||||
let config = {
|
||||
baseURL: config2.baseURL || globalsConfig.baseURL || '',
|
||||
method: method,
|
||||
url: config2.url || '',
|
||||
params: config2.params || {},
|
||||
custom: {...(globalsConfig.custom || {}), ...(config2.custom || {})},
|
||||
header: deepMerge(globalsConfig.header || {}, config2.header || {})
|
||||
}
|
||||
const defaultToConfig2Keys = ['getTask', 'validateStatus', 'paramsSerializer']
|
||||
config = {...config, ...mergeKeys(defaultToConfig2Keys, globalsConfig, config2)}
|
||||
|
||||
// eslint-disable-next-line no-empty
|
||||
if (method === 'DOWNLOAD') {
|
||||
// #ifdef H5 || APP-PLUS
|
||||
if (!isUndefined(config2.timeout)) {
|
||||
config['timeout'] = config2['timeout']
|
||||
} else if (!isUndefined(globalsConfig.timeout)) {
|
||||
config['timeout'] = globalsConfig['timeout']
|
||||
}
|
||||
// #endif
|
||||
} else if (method === 'UPLOAD') {
|
||||
delete config.header['content-type']
|
||||
delete config.header['Content-Type']
|
||||
const uploadKeys = [
|
||||
// #ifdef APP-PLUS || H5
|
||||
'files',
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
'fileType',
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
'file',
|
||||
// #endif
|
||||
'filePath',
|
||||
'name',
|
||||
// #ifdef H5 || APP-PLUS
|
||||
'timeout',
|
||||
// #endif
|
||||
'formData',
|
||||
]
|
||||
uploadKeys.forEach(prop => {
|
||||
if (!isUndefined(config2[prop])) {
|
||||
config[prop] = config2[prop]
|
||||
}
|
||||
})
|
||||
// #ifdef H5 || APP-PLUS
|
||||
if (isUndefined(config.timeout) && !isUndefined(globalsConfig.timeout)) {
|
||||
config['timeout'] = globalsConfig['timeout']
|
||||
}
|
||||
// #endif
|
||||
} else {
|
||||
const defaultsKeys = [
|
||||
'data',
|
||||
// #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN
|
||||
'timeout',
|
||||
// #endif
|
||||
'dataType',
|
||||
// #ifndef MP-ALIPAY
|
||||
'responseType',
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
'sslVerify',
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
'withCredentials',
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
'firstIpv4',
|
||||
// #endif
|
||||
]
|
||||
config = {...config, ...mergeKeys(defaultsKeys, globalsConfig, config2)}
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
16
node_modules/luch-request/src/lib/core/settle.js
generated
vendored
Normal file
16
node_modules/luch-request/src/lib/core/settle.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Resolve or reject a Promise based on response status.
|
||||
*
|
||||
* @param {Function} resolve A function that resolves the promise.
|
||||
* @param {Function} reject A function that rejects the promise.
|
||||
* @param {object} response The response.
|
||||
*/
|
||||
export default function settle(resolve, reject, response) {
|
||||
const validateStatus = response.config.validateStatus
|
||||
const status = response.statusCode
|
||||
if (status && (!validateStatus || validateStatus(status))) {
|
||||
resolve(response)
|
||||
} else {
|
||||
reject(response)
|
||||
}
|
||||
}
|
||||
64
node_modules/luch-request/src/lib/helpers/buildURL.js
generated
vendored
Normal file
64
node_modules/luch-request/src/lib/helpers/buildURL.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
'use strict'
|
||||
|
||||
import * as utils from './../utils'
|
||||
|
||||
function encode(val) {
|
||||
return encodeURIComponent(val).replace(/%40/gi, '@').replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%20/g, '+').replace(/%5B/gi, '[').replace(/%5D/gi, ']')
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a URL by appending params to the end
|
||||
*
|
||||
* @param {string} url The base of the url (e.g., http://www.google.com)
|
||||
* @param {object} [params] The params to be appended
|
||||
* @returns {string} The formatted url
|
||||
*/
|
||||
export default function buildURL(url, params, paramsSerializer) {
|
||||
/*eslint no-param-reassign:0*/
|
||||
if (!params) {
|
||||
return url
|
||||
}
|
||||
|
||||
var serializedParams
|
||||
if (paramsSerializer) {
|
||||
serializedParams = paramsSerializer(params)
|
||||
} else if (utils.isURLSearchParams(params)) {
|
||||
serializedParams = params.toString()
|
||||
} else {
|
||||
var parts = []
|
||||
|
||||
utils.forEach(params, function serialize(val, key) {
|
||||
if (val === null || typeof val === 'undefined') {
|
||||
return
|
||||
}
|
||||
|
||||
if (utils.isArray(val)) {
|
||||
key = key + '[]'
|
||||
} else {
|
||||
val = [val]
|
||||
}
|
||||
|
||||
utils.forEach(val, function parseValue(v) {
|
||||
if (utils.isDate(v)) {
|
||||
v = v.toISOString()
|
||||
} else if (utils.isObject(v)) {
|
||||
v = JSON.stringify(v)
|
||||
}
|
||||
parts.push(encode(key) + '=' + encode(v))
|
||||
})
|
||||
})
|
||||
|
||||
serializedParams = parts.join('&')
|
||||
}
|
||||
|
||||
if (serializedParams) {
|
||||
var hashmarkIndex = url.indexOf('#')
|
||||
if (hashmarkIndex !== -1) {
|
||||
url = url.slice(0, hashmarkIndex)
|
||||
}
|
||||
|
||||
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
14
node_modules/luch-request/src/lib/helpers/combineURLs.js
generated
vendored
Normal file
14
node_modules/luch-request/src/lib/helpers/combineURLs.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Creates a new URL by combining the specified URLs
|
||||
*
|
||||
* @param {string} baseURL The base URL
|
||||
* @param {string} relativeURL The relative URL
|
||||
* @returns {string} The combined URL
|
||||
*/
|
||||
export default function combineURLs(baseURL, relativeURL) {
|
||||
return relativeURL
|
||||
? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
||||
: baseURL
|
||||
}
|
||||
14
node_modules/luch-request/src/lib/helpers/isAbsoluteURL.js
generated
vendored
Normal file
14
node_modules/luch-request/src/lib/helpers/isAbsoluteURL.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Determines whether the specified URL is absolute
|
||||
*
|
||||
* @param {string} url The URL to test
|
||||
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
||||
*/
|
||||
export default function isAbsoluteURL(url) {
|
||||
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
||||
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
||||
// by any combination of letters, digits, plus, period, or hyphen.
|
||||
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url)
|
||||
}
|
||||
120
node_modules/luch-request/src/lib/luch-request.d.ts
generated
vendored
Normal file
120
node_modules/luch-request/src/lib/luch-request.d.ts
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
type AnyObject = Record<string | number | symbol, any>
|
||||
type HttpPromise<T> = Promise<HttpResponse<T>>;
|
||||
type Tasks = UniApp.RequestTask | UniApp.UploadTask | UniApp.DownloadTask
|
||||
export interface RequestTask {
|
||||
abort: () => void;
|
||||
offHeadersReceived: () => void;
|
||||
onHeadersReceived: () => void;
|
||||
}
|
||||
export interface HttpRequestConfig<T = Tasks> {
|
||||
/** 请求基地址 */
|
||||
baseURL?: string;
|
||||
/** 请求服务器接口地址 */
|
||||
url?: string;
|
||||
|
||||
/** 请求查询参数,自动拼接为查询字符串 */
|
||||
params?: AnyObject;
|
||||
/** 请求体参数 */
|
||||
data?: AnyObject;
|
||||
|
||||
/** 文件对应的 key */
|
||||
name?: string;
|
||||
/** HTTP 请求中其他额外的 form data */
|
||||
formData?: AnyObject;
|
||||
/** 要上传文件资源的路径。 */
|
||||
filePath?: string;
|
||||
/** 需要上传的文件列表。使用 files 时,filePath 和 name 不生效,App、H5( 2.6.15+) */
|
||||
files?: Array<{
|
||||
name?: string;
|
||||
file?: File;
|
||||
uri: string;
|
||||
}>;
|
||||
/** 要上传的文件对象,仅H5(2.6.15+)支持 */
|
||||
file?: File;
|
||||
|
||||
/** 请求头信息 */
|
||||
header?: AnyObject;
|
||||
/** 请求方式 */
|
||||
method?: "GET" | "POST" | "PUT" | "DELETE" | "CONNECT" | "HEAD" | "OPTIONS" | "TRACE" | "UPLOAD" | "DOWNLOAD";
|
||||
/** 如果设为 json,会尝试对返回的数据做一次 JSON.parse */
|
||||
dataType?: string;
|
||||
/** 设置响应的数据类型,支付宝小程序不支持 */
|
||||
responseType?: "text" | "arraybuffer";
|
||||
/** 自定义参数 */
|
||||
custom?: AnyObject;
|
||||
/** 超时时间,仅微信小程序(2.10.0)、支付宝小程序支持 */
|
||||
timeout?: number;
|
||||
/** DNS解析时优先使用ipv4,仅 App-Android 支持 (HBuilderX 2.8.0+) */
|
||||
firstIpv4?: boolean;
|
||||
/** 验证 ssl 证书 仅5+App安卓端支持(HBuilderX 2.3.3+) */
|
||||
sslVerify?: boolean;
|
||||
/** 跨域请求时是否携带凭证(cookies)仅H5支持(HBuilderX 2.6.15+) */
|
||||
withCredentials?: boolean;
|
||||
|
||||
/** 返回当前请求的task, options。请勿在此处修改options。 */
|
||||
getTask?: (task: T, options: HttpRequestConfig<T>) => void;
|
||||
/** 全局自定义验证器 */
|
||||
validateStatus?: (statusCode: number) => boolean | void;
|
||||
/** params 参数自定义处理 */
|
||||
paramsSerializer?: (params: AnyObject) => string | void;
|
||||
}
|
||||
export interface HttpResponse<T = any> {
|
||||
config: HttpRequestConfig;
|
||||
statusCode: number;
|
||||
cookies: Array<string>;
|
||||
data: T;
|
||||
errMsg: string;
|
||||
header: AnyObject;
|
||||
rawData: T;
|
||||
}
|
||||
export interface HttpUploadResponse<T = any> {
|
||||
config: HttpRequestConfig;
|
||||
statusCode: number;
|
||||
data: T;
|
||||
errMsg: string;
|
||||
rawData: T;
|
||||
}
|
||||
export interface HttpDownloadResponse extends HttpResponse {
|
||||
tempFilePath: string;
|
||||
}
|
||||
export interface HttpError {
|
||||
config: HttpRequestConfig;
|
||||
statusCode?: number;
|
||||
cookies?: Array<string>;
|
||||
data?: any;
|
||||
errMsg: string;
|
||||
header?: AnyObject;
|
||||
}
|
||||
export interface HttpInterceptorManager<V, E = V> {
|
||||
use(
|
||||
onFulfilled?: (config: V) => Promise<V> | V,
|
||||
onRejected?: (config: E) => Promise<E> | E
|
||||
): void;
|
||||
eject(id: number): void;
|
||||
}
|
||||
export abstract class HttpRequestAbstract {
|
||||
constructor(config?: HttpRequestConfig);
|
||||
config: HttpRequestConfig;
|
||||
interceptors: {
|
||||
request: HttpInterceptorManager<HttpRequestConfig, HttpRequestConfig>;
|
||||
response: HttpInterceptorManager<HttpResponse, HttpError>;
|
||||
}
|
||||
middleware<T = any>(config: HttpRequestConfig): HttpPromise<T>;
|
||||
request<T = any>(config: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
get<T = any>(url: string, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
upload<T = any>(url: string, config?: HttpRequestConfig<UniApp.UploadTask>): HttpPromise<T>;
|
||||
delete<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
head<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
post<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
put<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
connect<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
options<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
trace<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
|
||||
download(url: string, config?: HttpRequestConfig<UniApp.DownloadTask>): Promise<HttpDownloadResponse>;
|
||||
|
||||
setConfig(onSend: (config: HttpRequestConfig) => HttpRequestConfig): void;
|
||||
}
|
||||
|
||||
declare class HttpRequest extends HttpRequestAbstract { }
|
||||
export default HttpRequest;
|
||||
2
node_modules/luch-request/src/lib/luch-request.js
generated
vendored
Normal file
2
node_modules/luch-request/src/lib/luch-request.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import Request from './core/Request'
|
||||
export default Request
|
||||
135
node_modules/luch-request/src/lib/utils.js
generated
vendored
Normal file
135
node_modules/luch-request/src/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
'use strict'
|
||||
|
||||
// utils is a library of generic helper functions non-specific to axios
|
||||
|
||||
var toString = Object.prototype.toString
|
||||
|
||||
/**
|
||||
* Determine if a value is an Array
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is an Array, otherwise false
|
||||
*/
|
||||
export function isArray (val) {
|
||||
return toString.call(val) === '[object Array]'
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a value is an Object
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is an Object, otherwise false
|
||||
*/
|
||||
export function isObject (val) {
|
||||
return val !== null && typeof val === 'object'
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a value is a Date
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is a Date, otherwise false
|
||||
*/
|
||||
export function isDate (val) {
|
||||
return toString.call(val) === '[object Date]'
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a value is a URLSearchParams object
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
||||
*/
|
||||
export function isURLSearchParams (val) {
|
||||
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Iterate over an Array or an Object invoking a function for each item.
|
||||
*
|
||||
* If `obj` is an Array callback will be called passing
|
||||
* the value, index, and complete array for each item.
|
||||
*
|
||||
* If 'obj' is an Object callback will be called passing
|
||||
* the value, key, and complete object for each property.
|
||||
*
|
||||
* @param {Object|Array} obj The object to iterate
|
||||
* @param {Function} fn The callback to invoke for each item
|
||||
*/
|
||||
export function forEach (obj, fn) {
|
||||
// Don't bother if no value provided
|
||||
if (obj === null || typeof obj === 'undefined') {
|
||||
return
|
||||
}
|
||||
|
||||
// Force an array if not already something iterable
|
||||
if (typeof obj !== 'object') {
|
||||
/*eslint no-param-reassign:0*/
|
||||
obj = [obj]
|
||||
}
|
||||
|
||||
if (isArray(obj)) {
|
||||
// Iterate over array values
|
||||
for (var i = 0, l = obj.length; i < l; i++) {
|
||||
fn.call(null, obj[i], i, obj)
|
||||
}
|
||||
} else {
|
||||
// Iterate over object keys
|
||||
for (var key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
fn.call(null, obj[key], key, obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为boolean 值
|
||||
* @param val
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isBoolean(val) {
|
||||
return typeof val === 'boolean'
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为真正的对象{} new Object
|
||||
* @param {any} obj - 检测的对象
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isPlainObject(obj) {
|
||||
return Object.prototype.toString.call(obj) === '[object Object]'
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Function equal to merge with the difference being that no reference
|
||||
* to original objects is kept.
|
||||
*
|
||||
* @see merge
|
||||
* @param {Object} obj1 Object to merge
|
||||
* @returns {Object} Result of all merge properties
|
||||
*/
|
||||
export function deepMerge(/* obj1, obj2, obj3, ... */) {
|
||||
let result = {}
|
||||
function assignValue(val, key) {
|
||||
if (typeof result[key] === 'object' && typeof val === 'object') {
|
||||
result[key] = deepMerge(result[key], val)
|
||||
} else if (typeof val === 'object') {
|
||||
result[key] = deepMerge({}, val)
|
||||
} else {
|
||||
result[key] = val
|
||||
}
|
||||
}
|
||||
for (let i = 0, l = arguments.length; i < l; i++) {
|
||||
forEach(arguments[i], assignValue)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export function isUndefined (val) {
|
||||
return typeof val === 'undefined'
|
||||
}
|
||||
264
node_modules/luch-request/src/lib/utils/clone.js
generated
vendored
Normal file
264
node_modules/luch-request/src/lib/utils/clone.js
generated
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
/* eslint-disable */
|
||||
var clone = (function() {
|
||||
'use strict';
|
||||
|
||||
function _instanceof(obj, type) {
|
||||
return type != null && obj instanceof type;
|
||||
}
|
||||
|
||||
var nativeMap;
|
||||
try {
|
||||
nativeMap = Map;
|
||||
} catch(_) {
|
||||
// maybe a reference error because no `Map`. Give it a dummy value that no
|
||||
// value will ever be an instanceof.
|
||||
nativeMap = function() {};
|
||||
}
|
||||
|
||||
var nativeSet;
|
||||
try {
|
||||
nativeSet = Set;
|
||||
} catch(_) {
|
||||
nativeSet = function() {};
|
||||
}
|
||||
|
||||
var nativePromise;
|
||||
try {
|
||||
nativePromise = Promise;
|
||||
} catch(_) {
|
||||
nativePromise = function() {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones (copies) an Object using deep copying.
|
||||
*
|
||||
* This function supports circular references by default, but if you are certain
|
||||
* there are no circular references in your object, you can save some CPU time
|
||||
* by calling clone(obj, false).
|
||||
*
|
||||
* Caution: if `circular` is false and `parent` contains circular references,
|
||||
* your program may enter an infinite loop and crash.
|
||||
*
|
||||
* @param `parent` - the object to be cloned
|
||||
* @param `circular` - set to true if the object to be cloned may contain
|
||||
* circular references. (optional - true by default)
|
||||
* @param `depth` - set to a number if the object is only to be cloned to
|
||||
* a particular depth. (optional - defaults to Infinity)
|
||||
* @param `prototype` - sets the prototype to be used when cloning an object.
|
||||
* (optional - defaults to parent prototype).
|
||||
* @param `includeNonEnumerable` - set to true if the non-enumerable properties
|
||||
* should be cloned as well. Non-enumerable properties on the prototype
|
||||
* chain will be ignored. (optional - false by default)
|
||||
*/
|
||||
function clone(parent, circular, depth, prototype, includeNonEnumerable) {
|
||||
if (typeof circular === 'object') {
|
||||
depth = circular.depth;
|
||||
prototype = circular.prototype;
|
||||
includeNonEnumerable = circular.includeNonEnumerable;
|
||||
circular = circular.circular;
|
||||
}
|
||||
// maintain two arrays for circular references, where corresponding parents
|
||||
// and children have the same index
|
||||
var allParents = [];
|
||||
var allChildren = [];
|
||||
|
||||
var useBuffer = typeof Buffer != 'undefined';
|
||||
|
||||
if (typeof circular == 'undefined')
|
||||
circular = true;
|
||||
|
||||
if (typeof depth == 'undefined')
|
||||
depth = Infinity;
|
||||
|
||||
// recurse this function so we don't reset allParents and allChildren
|
||||
function _clone(parent, depth) {
|
||||
// cloning null always returns null
|
||||
if (parent === null)
|
||||
return null;
|
||||
|
||||
if (depth === 0)
|
||||
return parent;
|
||||
|
||||
var child;
|
||||
var proto;
|
||||
if (typeof parent != 'object') {
|
||||
return parent;
|
||||
}
|
||||
|
||||
if (_instanceof(parent, nativeMap)) {
|
||||
child = new nativeMap();
|
||||
} else if (_instanceof(parent, nativeSet)) {
|
||||
child = new nativeSet();
|
||||
} else if (_instanceof(parent, nativePromise)) {
|
||||
child = new nativePromise(function (resolve, reject) {
|
||||
parent.then(function(value) {
|
||||
resolve(_clone(value, depth - 1));
|
||||
}, function(err) {
|
||||
reject(_clone(err, depth - 1));
|
||||
});
|
||||
});
|
||||
} else if (clone.__isArray(parent)) {
|
||||
child = [];
|
||||
} else if (clone.__isRegExp(parent)) {
|
||||
child = new RegExp(parent.source, __getRegExpFlags(parent));
|
||||
if (parent.lastIndex) child.lastIndex = parent.lastIndex;
|
||||
} else if (clone.__isDate(parent)) {
|
||||
child = new Date(parent.getTime());
|
||||
} else if (useBuffer && Buffer.isBuffer(parent)) {
|
||||
if (Buffer.from) {
|
||||
// Node.js >= 5.10.0
|
||||
child = Buffer.from(parent);
|
||||
} else {
|
||||
// Older Node.js versions
|
||||
child = new Buffer(parent.length);
|
||||
parent.copy(child);
|
||||
}
|
||||
return child;
|
||||
} else if (_instanceof(parent, Error)) {
|
||||
child = Object.create(parent);
|
||||
} else {
|
||||
if (typeof prototype == 'undefined') {
|
||||
proto = Object.getPrototypeOf(parent);
|
||||
child = Object.create(proto);
|
||||
}
|
||||
else {
|
||||
child = Object.create(prototype);
|
||||
proto = prototype;
|
||||
}
|
||||
}
|
||||
|
||||
if (circular) {
|
||||
var index = allParents.indexOf(parent);
|
||||
|
||||
if (index != -1) {
|
||||
return allChildren[index];
|
||||
}
|
||||
allParents.push(parent);
|
||||
allChildren.push(child);
|
||||
}
|
||||
|
||||
if (_instanceof(parent, nativeMap)) {
|
||||
parent.forEach(function(value, key) {
|
||||
var keyChild = _clone(key, depth - 1);
|
||||
var valueChild = _clone(value, depth - 1);
|
||||
child.set(keyChild, valueChild);
|
||||
});
|
||||
}
|
||||
if (_instanceof(parent, nativeSet)) {
|
||||
parent.forEach(function(value) {
|
||||
var entryChild = _clone(value, depth - 1);
|
||||
child.add(entryChild);
|
||||
});
|
||||
}
|
||||
|
||||
for (var i in parent) {
|
||||
var attrs = Object.getOwnPropertyDescriptor(parent, i);
|
||||
if (attrs) {
|
||||
child[i] = _clone(parent[i], depth - 1);
|
||||
}
|
||||
|
||||
try {
|
||||
var objProperty = Object.getOwnPropertyDescriptor(parent, i);
|
||||
if (objProperty.set === 'undefined') {
|
||||
// no setter defined. Skip cloning this property
|
||||
continue;
|
||||
}
|
||||
child[i] = _clone(parent[i], depth - 1);
|
||||
} catch(e){
|
||||
if (e instanceof TypeError) {
|
||||
// when in strict mode, TypeError will be thrown if child[i] property only has a getter
|
||||
// we can't do anything about this, other than inform the user that this property cannot be set.
|
||||
continue
|
||||
} else if (e instanceof ReferenceError) {
|
||||
//this may happen in non strict mode
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Object.getOwnPropertySymbols) {
|
||||
var symbols = Object.getOwnPropertySymbols(parent);
|
||||
for (var i = 0; i < symbols.length; i++) {
|
||||
// Don't need to worry about cloning a symbol because it is a primitive,
|
||||
// like a number or string.
|
||||
var symbol = symbols[i];
|
||||
var descriptor = Object.getOwnPropertyDescriptor(parent, symbol);
|
||||
if (descriptor && !descriptor.enumerable && !includeNonEnumerable) {
|
||||
continue;
|
||||
}
|
||||
child[symbol] = _clone(parent[symbol], depth - 1);
|
||||
Object.defineProperty(child, symbol, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
if (includeNonEnumerable) {
|
||||
var allPropertyNames = Object.getOwnPropertyNames(parent);
|
||||
for (var i = 0; i < allPropertyNames.length; i++) {
|
||||
var propertyName = allPropertyNames[i];
|
||||
var descriptor = Object.getOwnPropertyDescriptor(parent, propertyName);
|
||||
if (descriptor && descriptor.enumerable) {
|
||||
continue;
|
||||
}
|
||||
child[propertyName] = _clone(parent[propertyName], depth - 1);
|
||||
Object.defineProperty(child, propertyName, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
return _clone(parent, depth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple flat clone using prototype, accepts only objects, usefull for property
|
||||
* override on FLAT configuration object (no nested props).
|
||||
*
|
||||
* USE WITH CAUTION! This may not behave as you wish if you do not know how this
|
||||
* works.
|
||||
*/
|
||||
clone.clonePrototype = function clonePrototype(parent) {
|
||||
if (parent === null)
|
||||
return null;
|
||||
|
||||
var c = function () {};
|
||||
c.prototype = parent;
|
||||
return new c();
|
||||
};
|
||||
|
||||
// private utility functions
|
||||
|
||||
function __objToStr(o) {
|
||||
return Object.prototype.toString.call(o);
|
||||
}
|
||||
clone.__objToStr = __objToStr;
|
||||
|
||||
function __isDate(o) {
|
||||
return typeof o === 'object' && __objToStr(o) === '[object Date]';
|
||||
}
|
||||
clone.__isDate = __isDate;
|
||||
|
||||
function __isArray(o) {
|
||||
return typeof o === 'object' && __objToStr(o) === '[object Array]';
|
||||
}
|
||||
clone.__isArray = __isArray;
|
||||
|
||||
function __isRegExp(o) {
|
||||
return typeof o === 'object' && __objToStr(o) === '[object RegExp]';
|
||||
}
|
||||
clone.__isRegExp = __isRegExp;
|
||||
|
||||
function __getRegExpFlags(re) {
|
||||
var flags = '';
|
||||
if (re.global) flags += 'g';
|
||||
if (re.ignoreCase) flags += 'i';
|
||||
if (re.multiline) flags += 'm';
|
||||
return flags;
|
||||
}
|
||||
clone.__getRegExpFlags = __getRegExpFlags;
|
||||
|
||||
return clone;
|
||||
})();
|
||||
|
||||
export default clone
|
||||
Reference in New Issue
Block a user