Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

es6 module? #1

Closed
mbykov opened this issue Sep 14, 2021 · 4 comments
Closed

es6 module? #1

mbykov opened this issue Sep 14, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@mbykov
Copy link

mbykov commented Sep 14, 2021

Hi,

are you planning to rewrite js-jieba as a es6 module?

For now I've got

import { Jieba } from 'js-jieba'
import { JiebaDict, HMMModel, UserDict, IDF, StopWords } from 'js-jieba/dist/dict.zh-cn'

ReferenceError: module is not defined
at eval (/node_modules/js-jieba/dist/dict.zh-cn.js:3:1)

@josudoey josudoey added the enhancement New feature or request label Jun 10, 2022
@josudoey
Copy link
Owner

this is great recommendation~

@josudoey
Copy link
Owner

the workaround solution.
you can use

import { createRequire } from 'module'
const {
    JiebaDict, HMMModel, UserDict, IDF, StopWords
} = createRequire(import.meta.url)('js-jieba/dist/dict.zh-cn.js')

@josudoey
Copy link
Owner

I need find the solution for how to make es6 module dict.

@josudoey
Copy link
Owner

hihi~ after v1.0.8 you can use es6 module for dict

import {
  JiebaDict, HMMModel,
  UserDict, IDF, StopWords
} from 'jieba-zh-tw'
import createJieba from 'js-jieba'

const jieba = createJieba(
  Buffer.from(JiebaDict),
  Buffer.from(HMMModel),
  Buffer.from(UserDict),
  Buffer.from(IDF),
  Buffer.from(StopWords)
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants