Skip to content

Commit

Permalink
Generate correct typings
Browse files Browse the repository at this point in the history
Removes `.npmignore` for source
maps.
Moves exports inline.
Refactors Integers.
  • Loading branch information
texastoland committed Mar 13, 2022
1 parent f9130c3 commit d04cde5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 0 additions & 2 deletions .npmignore

This file was deleted.

20 changes: 12 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @param {(name: string) => T} mapper
* @returns {{ [name: string]: T }}
*/
const Values = (mapper) =>
export const Values = (mapper) =>
new Proxy(
{},
{
Expand All @@ -12,17 +12,21 @@ const Values = (mapper) =>
}
)

const Strings = Values((name) => name)
export const Strings = Values((name) => name)

const LowerCased = Values((name) => name.toLowerCase())
export const LowerCased = Values((name) => name.toLowerCase())

const Symbols = Values(Symbol)
export const Symbols = Values(Symbol)

const Integers = (startIndex = 0) => {
export const Counter = (startIndex = 0) => {
/** @type {Map<string, number>} */
const indexOfName = new Map()
return Values((name) =>
indexOfName.set(name, indexOfName.size + startIndex).get(name)
return Values(
(name) =>
/** @type {!number} nonnull */ (
indexOfName.set(name, indexOfName.size + startIndex).get(name)
)
)
}

export { Values, Strings, LowerCased, Symbols, Integers }
export const Integers = Counter()
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"main": "dist/enum-xyz.cjs",
"module": "dist/enum-xyz.module.js",
"unpkg": "dist/enum-xyz.umd.js",
"types": "dist/enum-xyz.d.ts",
"scripts": {
"dev": "microbundle watch",
"format": "prettier --write *.{js,json,md}",
Expand Down
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"checkJs": true,
"strict": true
}
}

0 comments on commit d04cde5

Please sign in to comment.