Skip to content

Commit

Permalink
v2.11.22
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxinssfd committed Jul 11, 2021
1 parent 2a63eb6 commit 26a2595
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 42 deletions.
42 changes: 23 additions & 19 deletions lib-cjs/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function polling(callback, interval, immediate = true) {
}
function timeout() {
const delay = interval - diff;
timer = window.setTimeout(() => {
timer = setTimeout(() => {
if (status !== state.running)
return;
const now = Date.now();
Expand Down Expand Up @@ -477,47 +477,51 @@ function likeKeys(target, key) {
exports.likeKeys = likeKeys;
/**
* 命令行的参数转为Map
* @notice 部分命令行工具中"--"是全写,"-"是缩写 这里未分
* @param arr 命令行参数数组
* @param prefix 前缀 --d --f 前缀是"--"
* @param defaultKey 如果前面没有变量名那么使用默认
*/
function parseCmdParams(arr, prefix = "-", defaultKey = "default") {
const list = arr.slice();
let currentKey = defaultKey;
const isKeyReg = new RegExp(`^${prefix}`);
const eqReg = /([^=]+)=([\s\S]+)?/;
const isKeyReg = new RegExp(`^${prefix}`);
const list = arr.slice();
const map = new Map();
function getKey(key) {
let currentKey = defaultKey;
let item;
function setKey() {
let key = item.replace(isKeyReg, "");
if (eqReg.test(key)) {
key = RegExp.$1;
const value = RegExp.$2;
value && list.unshift(value);
}
return key;
currentKey = key;
if (!map.has(currentKey)) {
map.set(currentKey, true);
}
}
function setValue(currentValue) {
switch (dataType_1.typeOf(currentValue)) {
// fullFight
function setValue() {
const existValue = map.get(currentKey);
switch (dataType_1.typeOf(existValue)) {
case "undefined":
case "boolean":
map.set(currentKey, it);
map.set(currentKey, item);
break;
case "array":
currentValue.push(it);
existValue.push(item);
break;
default:
map.set(currentKey, [currentValue, it]);
map.set(currentKey, [existValue, item]);
}
}
let it;
while (it = list.shift()) {
if (isKeyReg.test(it)) {
currentKey = getKey(it.replace(isKeyReg, ""));
if (!map.has(currentKey)) {
map.set(currentKey, true);
}
while (item = list.shift()) {
if (isKeyReg.test(item)) {
setKey();
continue;
}
setValue(map.get(currentKey));
setValue();
}
return map;
}
Expand Down
1 change: 1 addition & 0 deletions lib-cjs/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ exports.addDragEventListener = addDragEventListener;
* 改成这样可以把数据控制在函数内部
* @example
* onDragEvent(({onDown, onMove, onUp}) => {
* // 目前只有第一次挂载的函数有效,后面的都无效。 那么是否应该可以更改呢
* onDown((e, currentXY) => {
* console.log("down", e, currentXY);
* });
Expand Down
42 changes: 23 additions & 19 deletions lib-es/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export function polling(callback, interval, immediate = true) {
}
function timeout() {
const delay = interval - diff;
timer = window.setTimeout(() => {
timer = setTimeout(() => {
if (status !== state.running)
return;
const now = Date.now();
Expand Down Expand Up @@ -455,47 +455,51 @@ export function likeKeys(target, key) {
}
/**
* 命令行的参数转为Map
* @notice 部分命令行工具中"--"是全写,"-"是缩写 这里未分
* @param arr 命令行参数数组
* @param prefix 前缀 --d --f 前缀是"--"
* @param defaultKey 如果前面没有变量名那么使用默认
*/
export function parseCmdParams(arr, prefix = "-", defaultKey = "default") {
const list = arr.slice();
let currentKey = defaultKey;
const isKeyReg = new RegExp(`^${prefix}`);
const eqReg = /([^=]+)=([\s\S]+)?/;
const isKeyReg = new RegExp(`^${prefix}`);
const list = arr.slice();
const map = new Map();
function getKey(key) {
let currentKey = defaultKey;
let item;
function setKey() {
let key = item.replace(isKeyReg, "");
if (eqReg.test(key)) {
key = RegExp.$1;
const value = RegExp.$2;
value && list.unshift(value);
}
return key;
currentKey = key;
if (!map.has(currentKey)) {
map.set(currentKey, true);
}
}
function setValue(currentValue) {
switch (typeOf(currentValue)) {
// fullFight
function setValue() {
const existValue = map.get(currentKey);
switch (typeOf(existValue)) {
case "undefined":
case "boolean":
map.set(currentKey, it);
map.set(currentKey, item);
break;
case "array":
currentValue.push(it);
existValue.push(item);
break;
default:
map.set(currentKey, [currentValue, it]);
map.set(currentKey, [existValue, item]);
}
}
let it;
while (it = list.shift()) {
if (isKeyReg.test(it)) {
currentKey = getKey(it.replace(isKeyReg, ""));
if (!map.has(currentKey)) {
map.set(currentKey, true);
}
while (item = list.shift()) {
if (isKeyReg.test(item)) {
setKey();
continue;
}
setValue(map.get(currentKey));
setValue();
}
return map;
}
1 change: 1 addition & 0 deletions lib-es/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export function addDragEventListener({ el, onDown, onMove, onUp, capture = { dow
* 改成这样可以把数据控制在函数内部
* @example
* onDragEvent(({onDown, onMove, onUp}) => {
* // 目前只有第一次挂载的函数有效,后面的都无效。 那么是否应该可以更改呢
* onDown((e, currentXY) => {
* console.log("down", e, currentXY);
* });
Expand Down
6 changes: 3 additions & 3 deletions lib-umd/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mxssfd/ts-utils",
"version": "2.11.21",
"version": "2.11.22",
"description": "utils工具函数ts/js库",
"main": "./lib-umd/index.js",
"module": "./lib-es/index.js",
Expand Down
1 change: 1 addition & 0 deletions types/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ declare type ArrayLikeType<T> = T extends ArrayLike<infer R> ? R : never;
export declare function likeKeys(target: object | Map<string, any>, key: string | RegExp): string[];
/**
* 命令行的参数转为Map
* @notice 部分命令行工具中"--"是全写,"-"是缩写 这里未分
* @param arr 命令行参数数组
* @param prefix 前缀 --d --f 前缀是"--"
* @param defaultKey 如果前面没有变量名那么使用默认
Expand Down
1 change: 1 addition & 0 deletions types/event.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ declare type DragHook<T> = (cb: T) => void;
* 改成这样可以把数据控制在函数内部
* @example
* onDragEvent(({onDown, onMove, onUp}) => {
* // 目前只有第一次挂载的函数有效,后面的都无效。 那么是否应该可以更改呢
* onDown((e, currentXY) => {
* console.log("down", e, currentXY);
* });
Expand Down

0 comments on commit 26a2595

Please sign in to comment.