simov / slugify

Slugifies a string
MIT License
1.47k stars 126 forks source link

Provide esm version #173

Open tobiasdiez opened 1 year ago

tobiasdiez commented 1 year ago

With more and more build tools (vite, nuxt, etc) going towards an esm-first build, it would be nice if a proper esm interface could be provided, i.e. transpile and distribute esm version, including correct export declaration in package.json.

michaelhays commented 1 year ago

Found a few PRs that seem to address this: https://github.com/simov/slugify/pull/43, https://github.com/simov/slugify/pull/160, https://github.com/simov/slugify/pull/171

For those of you using TypeScript and "type": "module", I'm using this as a workaround:

/imports/slugify.ts

/**
 * Hack to make 'slugify' import work with "type": "module".
 */
import slugify from 'slugify'

export default slugify as unknown as typeof slugify.default

/src/someFile.ts

import slugify from '~/imports/slugify.js'

const slug = slugify('Some Name')
tyteen4a03 commented 2 months ago

+1 on this!

kmturley commented 2 months ago

Another alternative is to disable TypeScript checking for that line:

// @ts-ignore
slugify('some string')

Although this is not ideal