Skip to content

Commit

Permalink
feat:add the umd & cjs & es6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
karlsbeard committed Aug 22, 2024
1 parent 45c872d commit 36f3fe0
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,37 @@ export const TTs = {
},

}

function makeHandlers() {
const handlers = {} as { [K in keyof typeof TTs]: typeof TTs[K] }
for (const key in TTs) {
if (key.startsWith('_'))
continue
handlers[key] = TTs[key]

Check failure on line 81 in src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ toTree: <T extends BaseTreeNode>(list: T[], config?: Partial<Config>) => T[]; toList: <T extends BaseTreeNode>(tree: T[], config?: Partial<Config>) => T[]; }'.

Check failure on line 81 in src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ toTree<T extends BaseTreeNode>(list: T[], config?: Partial<Config>): T[]; toList<T extends BaseTreeNode>(tree: T[], config?: Partial<Config>): T[]; }'.
}
return handlers
}

const handlers = makeHandlers()

const treeHandler = {
...handlers,
createInstance(config: Partial<Config> = {}) {
const obj = {}
for (const key in handlers) {
const func = handlers[key]

Check failure on line 93 in src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ toTree: <T extends BaseTreeNode>(list: T[], config?: Partial<Config>) => T[]; toList: <T extends BaseTreeNode>(tree: T[], config?: Partial<Config>) => T[]; }'.
obj[key] = (...args) => func(...args, config)

Check failure on line 94 in src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 94 in src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Rest parameter 'args' implicitly has an 'any[]' type.
}
return obj
},
}

if (typeof window !== 'undefined') {
// @ts-expect-error global variable
window.TTs = treeHandler
}
else if (typeof exports !== 'undefined') {
module.exports = treeHandler
}

export default treeHandler

0 comments on commit 36f3fe0

Please sign in to comment.