Skip to content

Commit

Permalink
Merge pull request #7 from Marinerer/kitify
Browse files Browse the repository at this point in the history
Kitify
  • Loading branch information
Marinerer authored Dec 11, 2024
2 parents 6a82301 + 9b71704 commit 3f6fd35
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 12 deletions.
15 changes: 15 additions & 0 deletions libs/kitify/config.mjs
Original file line number Diff line number Diff line change
@@ -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',
}
3 changes: 0 additions & 3 deletions libs/kitify/index.js

This file was deleted.

15 changes: 10 additions & 5 deletions libs/kitify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"
},
Expand All @@ -30,7 +36,6 @@
"keywords": [
"kitify",
"kit",
"JavaScript kit",
"utility",
"functions",
"lodash"
Expand Down
1 change: 1 addition & 0 deletions libs/kitify/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './type'
36 changes: 36 additions & 0 deletions libs/kitify/src/type.ts
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 4 additions & 3 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion scripts/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 中的构建配置

/**
Expand Down

0 comments on commit 3f6fd35

Please sign in to comment.