diff --git a/libs/kitify/config.mjs b/libs/kitify/config.mjs new file mode 100644 index 0000000..1da2592 --- /dev/null +++ b/libs/kitify/config.mjs @@ -0,0 +1,15 @@ +export default { + input: [ + { + input: 'src/index.ts', + name: 'kitify', + }, + { + input: 'src/type.ts', + name: 'kitifyType', + }, + ], + formats: ['cjs', 'esm', 'umd'], + target: ['es2015', 'es5'], + outDir: 'dist', +} diff --git a/libs/kitify/index.js b/libs/kitify/index.js deleted file mode 100644 index 0bb58d3..0000000 --- a/libs/kitify/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export function assign(...args) { - return Object.assign(...args) -} diff --git a/libs/kitify/package.json b/libs/kitify/package.json index 14ee735..56da49d 100644 --- a/libs/kitify/package.json +++ b/libs/kitify/package.json @@ -2,17 +2,23 @@ "name": "kitify", "version": "0.0.7", "description": "kitify is a JavaScript utility library that provides a whole mess of useful helper functions and supports modularity.", - "type": "module", "main": "dist/index.js", + "module": "dist/index.mjs", "unpkg": "dist/index.min.js", "jsdelivr": "dist/index.min.js", "types": "dist/index.d.ts", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.js", - "module": "./dist/index.js", - "require": "./dist/index.cjs" + "import": "./dist/index.mjs", + "module": "./dist/index.mjs", + "require": "./dist/index.js" + }, + "./type": { + "types": "./dist/type.d.ts", + "import": "./dist/type.mjs", + "module": "./dist/type.mjs", + "require": "./dist/type.js" }, "./*": "./dist/*" }, @@ -30,7 +36,6 @@ "keywords": [ "kitify", "kit", - "JavaScript kit", "utility", "functions", "lodash" diff --git a/libs/kitify/src/index.ts b/libs/kitify/src/index.ts new file mode 100644 index 0000000..b26944f --- /dev/null +++ b/libs/kitify/src/index.ts @@ -0,0 +1 @@ +export * from './type' diff --git a/libs/kitify/src/type.ts b/libs/kitify/src/type.ts new file mode 100644 index 0000000..7e9dd08 --- /dev/null +++ b/libs/kitify/src/type.ts @@ -0,0 +1,36 @@ +export function isType(value: any, type?: string): string | boolean { + const valType = Object.prototype.toString.call(value).slice(8, -1).toLowerCase() + if (type && typeof type === 'string') { + return valType === type.toLowerCase() + } + return valType +} + +export const isString = (value: any) => typeof value === 'string' +export const isNumber = (value: any) => typeof value === 'number' +export const isBoolean = (value: any) => typeof value === 'boolean' +export const isArray = (value: any) => Array.isArray(value) +export const isFunction = (value: any) => typeof value === 'function' +export const isSymbol = (value: any) => typeof value === 'symbol' +export const isBigInt = (value: any) => typeof value === 'bigint' +export const isObject = (value: any) => isType(value, 'object') + +export const isNil = (value: any) => value === null || value === undefined + +export const isEmpty = (value: any) => { + if (isNil(value)) { + return true + } + if (typeof value === 'string') { + return value.trim() === '' + } + if (Array.isArray(value)) { + return value.length === 0 + } + if (typeof value === 'object') { + return Object.keys(value).length === 0 + } + return false +} + +export const isInvalid = (value: any) => isNil(value) || Number.isNaN(value) diff --git a/scripts/build.js b/scripts/build.js index 23a84ed..219ba6a 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -18,9 +18,10 @@ const args = minimist(process.argv.slice(2)) const watchMode = args.watch const PROD = !args.watch -async function readLibConfig(libPath) { +async function readLibConfig(libPath, type) { try { - const { default: result } = await import(path.join(libPath, BUILD_LIB_CONFIG_FILE)) + const _path = path.join(libPath, BUILD_LIB_CONFIG_FILE + (type === 'module' ? '.js' : '.mjs')) + const { default: result } = await import(_path) if (typeof result === 'function') { return await Promise.resolve().then(result) } else { @@ -60,8 +61,8 @@ function generateConfig(input, config = {}, pkg, cli = {}) { async function getLibConfig(libName, cli = {}) { const libPath = getLibPath(libName) - const _config = await readLibConfig(libPath) const libPkg = await readPackage(libPath) + const _config = await readLibConfig(libPath, libPkg.type) const userConfig = _config || libPkg[BUILD_LIB_CONFIG_KEY] || {} const libInput = cli.input || userConfig.input || './src/index.ts' diff --git a/scripts/const.js b/scripts/const.js index a0f8b83..e46af86 100644 --- a/scripts/const.js +++ b/scripts/const.js @@ -12,7 +12,7 @@ export const BUILD_MODULES = ['libs/*/package.json'] // 所有的构建模块 export const BUILD_BROWSERSLIST = '> 0.25%, not dead' export const BUILD_TS_TARGET = ['es2018', 'es2015'] export const BUILD_FORMATS = ['esm', 'cjs', 'umd'] -export const BUILD_LIB_CONFIG_FILE = 'config.js' // 构建配置文件 +export const BUILD_LIB_CONFIG_FILE = 'config' // 构建配置文件 export const BUILD_LIB_CONFIG_KEY = 'buildOptions' // package.json 中的构建配置 /**