question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

static `text()` method is not actually exported

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
brettz9commented, Mar 21, 2022

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

0reactions
fb55commented, Mar 23, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Class with static methods vs exported functions typescript
I've inherited a code base where the team is using classes with static methods instead of functions for helper methods. I've never seen...
Read more >
Export-CSV but append static text in one column? - TechNet
I have a script I've cobbled together which exports about 5 columns of server info to CSV. Actually, I have *several* scripts.
Read more >
Static methods from classes exported as default are not made ...
I'm documenting this behavior in the examples below. I have used ns[Math.random() < 2 && 'name'] to test for dynamic property accesses since ......
Read more >
export - JavaScript - MDN Web Docs
The export declaration is used to export values from a JavaScript module. Exported values can then be imported into other programs with the ......
Read more >
16. Modules - Exploring JS
Can I use destructuring in an import statement? 16.9.5. Are named exports necessary? Why not default-export objects? 16.9.6. Can I eval() the code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found