Skip to content

Commit

Permalink
feat: adjest debug
Browse files Browse the repository at this point in the history
  • Loading branch information
fupengl committed Jun 10, 2021
1 parent 02f0e0a commit 940833d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
8 changes: 3 additions & 5 deletions src/bom/append-script.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import throwError from '../throw-error';
import { ensure } from '../debug';

function appendScript({ src, ...rest }: Partial<HTMLScriptElement>) {
if (!src) {
throw throwError('src required');
}
ensure(!src, 'src required');

const isExist = document.querySelector(`script[src='${src}']`) !== null;
if (isExist) {
Expand All @@ -13,7 +11,7 @@ function appendScript({ src, ...rest }: Partial<HTMLScriptElement>) {

const script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
script.src = src!;
for (const attr in rest) {
script[attr] = rest[attr];
}
Expand Down
2 changes: 1 addition & 1 deletion src/bom/execute-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 复制到剪切板
* @param textValue
*/
function executeCopy(textValue) {
function executeCopy(textValue: string) {
const input = document.createElement('textarea');
document.body.appendChild(input);
input.value = textValue;
Expand Down
12 changes: 12 additions & 0 deletions src/debug.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import isFunction from './is/is-Function';

/**
* 如果值有问题则报错
* @param condition
Expand All @@ -9,6 +11,16 @@ export function ensure(condition: boolean, msg: string): asserts condition {
}
}

/**
* 如果fn不是一个函数就报typeError
* @param fn
* @return fn 如果fn是函数,则返回函数,否则报错
*/
export function ensureCallable<T extends Function = any>(fn: any): T {
if (isFunction(fn)) throw new TypeError(fn + ' is not a function');
return fn;
}

/**
* 如果值有问题则warn
* @param condition
Expand Down
6 changes: 1 addition & 5 deletions src/function/next-tick.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import isFunction from '../is/is-Function';

const ensureCallable = function (fn) {
if (isFunction(fn)) throw new TypeError(fn + ' is not a function');
return fn;
};
import { ensureCallable } from '../debug';

function _nextTick(): (callback: Function, ...args: any[]) => void {
// nodejs
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export * from './function';
export * from './object';
export * from './regex_constant';

export type { PropertyName, Dictionary, ClassType } from './type';
export type { PropertyName, PropertyPath, Dictionary, ClassType } from './type';

0 comments on commit 940833d

Please sign in to comment.