Skip to content

Commit

Permalink
feat: 添加 .d.ts 文件定义,支持 ts
Browse files Browse the repository at this point in the history
  • Loading branch information
yaohaixiao committed Jul 6, 2024
1 parent f7d37d1 commit 541f818
Show file tree
Hide file tree
Showing 95 changed files with 1,064 additions and 3 deletions.
51 changes: 49 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yaohaixiao/types.js",
"version": "2.4.0",
"version": "2.5.0",
"description": "types.js - 专注于检测 JavaScript 数据类型的工具库。",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -47,6 +47,7 @@
"buffer": "^6.0.3",
"commitlint": "^17.4.4",
"conventional-changelog-cli": "^2.2.2",
"dts-gen": "^0.10.3",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"eslint-import-resolver-jest": "^3.0.2",
Expand Down
96 changes: 96 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"compilerOptions": {
"declaration": true,
// 生成 .d.ts 文件
"emitDeclarationOnly": true,
// 只生成声明文件而不生成 JavaScript 文件
"outDir": "./types",
// 声明文件输出目录,可以根据需要更改
"allowJs": true,
// 允许编译 .js 文件
"rootDir": "./"
// 源文件目录,可以根据需要更改
},
"include": [
// 包含的文件范围,根据项目实际路径修改
"./index.js",
"./is.js",
"./isAlpha.js",
"./isArray.js",
"./isArrayLike.js",
"./isArrayLikeObject.js",
"./isArguments.js",
"./isArrayBuffer.js",
"./isInt8Array.js",
"./isUint8Array.js",
"./isUint8ClampedArray.js",
"./isInt16Array.js",
"./isUint16Array.js",
"./isInt32Array.js",
"./isUint32Array.js",
"./isFloat32Array.js",
"./isFloat64Array.js",
"./isBigInt64Array.js",
"./isBigUint64Array.js",
"./isBigInt.js",
"./isBase64.js",
"./isBinary.js",
"./isBlank.js",
"./isBoolean.js",
"./isBuffer.js",
"./isConstructor.js",
"./isDataView.js",
"./isDate.js",
"./isDOM.js",
"./isElement.js",
"./isEmail.js",
"./isEmpty.js",
"./isEmptyArray.js",
"./isEmptyObject.js",
"./isError.js",
"./isEven.js",
"./isFloat.js",
"./isFragment.js",
"./isFunction.js",
"./isGuid.js",
"./isHash.js",
"./isHex.js",
"./isHTML.js",
"./isHTMLCollection.js",
"./isInfinite.js",
"./isInteger.js",
"./isIPAddress.js",
"./isJSON.js",
"./isLength.js",
"./isMap.js",
"./isNativeFunction.js",
"./isNull.js",
"./isNumber.js",
"./isNumeric.js",
"./isObject.js",
"./isObjectLike.js",
"./isOdd.js",
"./isChinese.js",
"./isPhoneNumber.js",
"./isPlainObject.js",
"./isPrime.js",
"./isPromise.js",
"./isPrototype.js",
"./isRegExp.js",
"./isSet.js",
"./isString.js",
"./isSVG.js",
"./isSymbol.js",
"./isTextNode.js",
"./isTime.js",
"./isTypedArray.js",
"./isUndefined.js",
"./isURL.js",
"./isUUID.js",
"./isValue.js",
"./isVNode.js",
"./isWeakMap.js",
"./isWeakSet.js",
"./isXML.js"
]
}
10 changes: 10 additions & 0 deletions types/_getExactTypeOfNumber.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default _getExactTypeOfNumber;
/**
* (私有方法)获取确切的数值类型
* ========================================================================
* @method _getExactTypeOfNumber
* @private
* @param {Number} val - 要检测的数值
* @returns {String} - 返回数值类型:integer、float、infinite
*/
declare function _getExactTypeOfNumber(val: number): string;
10 changes: 10 additions & 0 deletions types/_getExactTypeOfObject.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default _getExactTypeOfObject;
/**
* (私有方法)获取确切的对象类型
* ========================================================================
* @method _getExactTypeOfString
* @private
* @param {String} val - 要检测的字符串
* @returns {String} 返回对象类型:prototype、vnode、xml
*/
declare function _getExactTypeOfObject(val: string): string;
10 changes: 10 additions & 0 deletions types/_getExactTypeOfString.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default _getExactTypeOfString;
/**
* (私有方法)获取确切的字符串类型
* ========================================================================
* @method _getExactTypeOfString
* @private
* @param {String} val - 要检测的字符串
* @returns {String} 返回字符串类型:blank、chinese、email、empty... 等等
*/
declare function _getExactTypeOfString(val: string): string;
2 changes: 2 additions & 0 deletions types/_getTypes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default _getTypes;
declare function _getTypes(METHODS: any): (val: any) => {};
2 changes: 2 additions & 0 deletions types/_getURLPattern.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default _getURLPattern;
declare function _getURLPattern(): RegExp;
10 changes: 10 additions & 0 deletions types/_isDate.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default _isDate;
/**
* 检测测试数据是否为有效的日期(字符串)
* ========================================================================
* @method _isDate
* @private
* @param {String} str - 待检测数据(字符串)
* @returns {Boolean}
*/
declare function _isDate(str: string): boolean;
10 changes: 10 additions & 0 deletions types/_isTime.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default _isTime;
/**
* 检测测试数据是否为有效的时间(字符串)
* ========================================================================
* @method _isTime
* @private
* @param {String} str - 待检测数据(字符串)
* @returns {Boolean}
*/
declare function _isTime(str: string): boolean;
9 changes: 9 additions & 0 deletions types/_type.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default _type;
/**
* 检测数据类型,返回检测数据类型的字符串
* ========================================================================
* @method _type
* @param {*} val - 要检测的任意值
* @returns {String}
*/
declare function _type(val: any): string;
35 changes: 35 additions & 0 deletions types/enum/objects.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export default OBJECTS;
declare const OBJECTS: {
'[object Null]': string;
'[object Set]': string;
'[object WeakSet]': string;
'[object Map]': string;
'[object WeakMap]': string;
'[object Array]': string;
'[object Arguments]': string;
'[object DataView]': string;
'[object ArrayBuffer]': string;
'[object Int8Array]': string;
'[object Uint8Array]': string;
'[object Uint8ClampedArray]': string;
'[object Int16Array]': string;
'[object Uint16Array]': string;
'[object Int32Array]': string;
'[object Uint32Array]': string;
'[object Float32Array]': string;
'[object Float64Array]': string;
'[object BigInt64Array]': string;
'[object BigUint64Array]': string;
'[object Object]': string;
'[object Boolean]': string;
'[object String]': string;
'[object Number]': string;
'[object Date]': string;
'[object Error]': string;
'[object DocumentFragment]': string;
'[object Function]': string;
'[object NodeList]': string;
'[object Promise]': string;
'[object RegExp]': string;
'[object Text]': string;
};
2 changes: 2 additions & 0 deletions types/enum/tags.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default TAGS;
declare const TAGS: string[];
39 changes: 39 additions & 0 deletions types/enum/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export default TYPES;
declare namespace TYPES {
let BIG_INT: string;
let BOOLEAN: string;
let NULL: string;
let NUMBER: string;
let UNDEFINED: string;
let STRING: string;
let SYMBOL: string;
let SET: string;
let WEAK_SET: string;
let MAP: string;
let WEAK_MAP: string;
let ARRAY: string;
let ARGUMENTS: string;
let DATA_VIEW: string;
let ARRAY_BUFFER: string;
let INT8_ARRAY: string;
let UNIT8_ARRAY: string;
let UNIT8_CLAMPED_ARRAY: string;
let INT16_ARRAY: string;
let UNIT16_ARRAY: string;
let INT32_ARRAY: string;
let UNIT32_ARRAY: string;
let FLOAT32_ARRAY: string;
let FLOAT64_ARRAY: string;
let BIG_INT64_ARRAY: string;
let BIG_UINT64_ARRAY: string;
let OBJECT: string;
let COLLECTION: string;
let DATE: string;
let ELEMENT: string;
let ERROR: string;
let FRAGMENT: string;
let FUNCTION: string;
let PROMISE: string;
let REGEXP: string;
let TEXT: string;
}
10 changes: 10 additions & 0 deletions types/hasOwn.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default hasOwn;
/**
* 检测对象自身属性中是否具有指定的属性。
* ========================================================================
* @method hasOwn
* @param {Object} obj - (必须)检测的目标对象
* @param {String} prop - (必须)属性名
* @returns {Boolean}
*/
declare function hasOwn(obj: any, prop: string): boolean;
2 changes: 2 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default Types;
declare const Types: (val: any) => {};
11 changes: 11 additions & 0 deletions types/is.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default is;
/**
* 检测数据类型,返回检测数据类型的字符串
* ========================================================================
* @method is
* @category Lang
* @see _type
* @param {*} val - 要检测的任意值
* @returns {String} 返回确切的数据类型名称
*/
declare function is(val: any): string;
10 changes: 10 additions & 0 deletions types/isAlpha.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default isAlpha;
/**
* 检测测试数据是否仅包含英文字符
* ========================================================================
* @method isAlpha
* @since 2.1.0
* @param {String} str - 要检测的数据
* @returns {Boolean} 'str' 仅包含英文字符,返回 true,否则返回 false
*/
declare function isAlpha(str: string): boolean;
9 changes: 9 additions & 0 deletions types/isArguments.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default isArguments;
/**
* 检测测试数据是否为 arguments 对象
* ========================================================================
* @method isArguments
* @param {*} val - 要检测的数据
* @return {Boolean} ‘val’ 是 Arguments 对象,返回 true,否则返回 false;
*/
declare function isArguments(val: any): boolean;
Loading

0 comments on commit 541f818

Please sign in to comment.