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

static text() method is not actually exported #2402

Closed
Hashbrown777 opened this issue Mar 10, 2022 · 5 comments · Fixed by #2506
Closed

static text() method is not actually exported #2402

Hashbrown777 opened this issue Mar 10, 2022 · 5 comments · Fixed by #2506

Comments

@Hashbrown777
Copy link

Hashbrown777 commented Mar 10, 2022

As mentioned in the README:

You may also render the text content of a Cheerio object using the text static method:

const $ = cheerio.load('This is <em>content</em>.');
cheerio.text($('body'));
//=> This is content.

Yet neither index.d.ts nor index.js actually forwards text from lib/static.{d.ts,js} (it appears to re-export methods one-by-one for some reason, and misses text).

image

As a workaround I tried importing static directly, but it doesnt like it.

image

Using import {text} from 'cheerio/lib/static' gets past typescript complaints, but for some reason doesn't transpile to mjs well.

image

So [at least in typescript targeting ES2020 using modules] it's impossible to use the text static method.

@Hashbrown777
Copy link
Author

Hashbrown777 commented Mar 10, 2022

1.0.0-rc.10 pulled via npm, btw

but it's clear to see from the source that only root, parseHTML, merge, and contains are exported even though text is intended to be exported

@brettz9
Copy link

brettz9 commented Mar 21, 2022

Looks like this is a document bug; see #2286 for what it apparently actually should be. Also for cheerio.html() missing.

@Hashbrown777
Copy link
Author

@brettz9 no he's using the object methods, not the static ones, that pull request should definitely not go through.

He's breaking the readme, not fixing the issue https://github.com/cheeriojs/cheerio/pull/2286/files

He's changed the static call cheerio.text($('body')); to a call to the member function (of the document) $.text($('body'));.
If he's willing to use member functions, he could have just done $('body').text(), he's completely missed the point.

@brettz9
Copy link

brettz9 commented Mar 23, 2022

Ok, but the big problem now is that the static functions aren't exported and that PR is the only issue I see doing anything to draw attention to what a user can do. That doesn't make it right, but it does point to the need to get the main issue resolved.

@fb55
Copy link
Member

fb55 commented Mar 23, 2022

I'm happy to accept a PR that adds the missing exports. Agreed they should be there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants