Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@types/jsdom
Advanced tools
The @types/jsdom package provides TypeScript type definitions for jsdom, a pure-JavaScript implementation of many web standards, notably the WHATWG DOM and HTML Standards. It allows for the simulation of a web browser's environment in Node.js, enabling the testing of web pages and applications without a browser. This package is essential for TypeScript developers working with jsdom, as it offers type checking and IntelliSense support in code editors.
Creating a new JSDOM instance
This feature allows you to create a new JSDOM instance, simulating an HTML page. It is useful for testing and scraping web content in a Node.js environment.
import { JSDOM } from 'jsdom';
const dom = new JSDOM(`<html><body><p>Hello world</p></body></html>`);
Querying elements
After creating a JSDOM instance, you can query elements within the simulated page using standard DOM APIs, such as `querySelector`. This is particularly useful for testing DOM manipulation and event handling.
const paragraph = dom.window.document.querySelector('p');
console.log(paragraph.textContent); // Outputs: Hello world
Modifying elements
This feature demonstrates modifying the content of an element within the JSDOM instance. It's a common operation for testing dynamic web applications.
paragraph.textContent = 'Goodbye world';
console.log(dom.window.document.querySelector('p').textContent); // Outputs: Goodbye world
Cheerio is a fast, flexible, and lean implementation of core jQuery designed specifically for the server. Unlike @types/jsdom, which simulates a full web browser environment, Cheerio parses, manipulates, and renders HTML on the server without implementing a full DOM or requiring a browser. It's more lightweight and faster for simple web scraping and page manipulation tasks.
Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. It is capable of rendering and testing web pages in a real browser environment. Compared to @types/jsdom, Puppeteer is more powerful for end-to-end testing and web scraping, especially for dynamic websites that require JavaScript execution, but it is also heavier and requires a Chromium or Chrome installation.
npm install --save @types/jsdom
This package contains type definitions for jsdom (https://github.com/jsdom/jsdom).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jsdom
Additional Details
These definitions were written by Leonard Thieu https://github.com/leonard-thieu, and Johan Palmfjord https://github.com/palmfjord.
FAQs
TypeScript definitions for jsdom
The npm package @types/jsdom receives a total of 3,397,484 weekly downloads. As such, @types/jsdom popularity was classified as popular.
We found that @types/jsdom demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.