yoastjs
v1.0.0
Published
SEO & readability analyzer built on top of Yoast SEO
Maintainers
Readme
yoastjs
Simple SEO & Readability Analysis for JavaScript — powered by Yoast SEO
yoastjs is a lightweight wrapper built on top of Yoast SEO that makes SEO and readability analysis easy to use in Node.js, browsers, ESM, CJS, and TypeScript — without dealing with Yoast’s internal APIs or module compatibility issues.
❗ The Problem with Yoast SEO in Modern JS
The official Yoast SEO (yoastseo) package is CommonJS-only.
This causes multiple issues in modern JavaScript projects:
- ❌ Does not work cleanly with ES Modules
- ❌ Difficult to import in TypeScript (NodeNext / ESM)
- ❌ Breaks in browser environments without heavy polyfills
- ❌ No default types for seamless TS usage
Using Yoast directly often results in:
require is not definedCannot use import statement outside a module- Broken builds in Vite / Next.js / ESBuild
✅ How yoastjs Solves This
yoastjs abstracts all Yoast SEO internals and provides:
- ✅ Dual builds: ESM + CommonJS
- ✅ Browser-compatible bundle
- ✅ Node.js support
- ✅ First-class TypeScript types
- ✅ No need to import Yoast directly
- ✅ Automatic environment resolution via
exports
You write modern import syntax, and the correct build is picked automatically.
✨ Features
- Built on top of Yoast SEO
- Simple one-function API
- SEO + Readability analysis
- Works in Node & Browser
- Supports ESM, CJS, TypeScript
- Fully typed results
- Tree-shakable
- Zero configuration
📦 Installation
npm install yoastjsor
pnpm add yoastjsor
yarn add yoastjs🚀 Quick Start
ESM / TypeScript
import { analyzeContent } from "yoastjs";
const result = analyzeContent({
title: "What is SEO?",
slug: "what-is-seo",
description: "Learn what SEO is and why it matters",
content: "SEO stands for Search Engine Optimization...",
keyphrase: "SEO",
});
console.dir(result);CommonJS (Node.js)
const { analyzeContent } = require("yoastjs");
const result = analyzeContent({
content: "SEO stands for Search Engine Optimization...",
keyphrase: "SEO",
});
console.dir(result);Browser (Vite / Webpack / ESBuild)
import { analyzeContent } from "yoastjs";
const analysis = analyzeContent({
content: document.querySelector("#editor").value,
keyphrase: "javascript seo",
});
console.dir(analysis);🧠 API
analyzeContent(input)
Runs SEO and readability analysis on the provided content.
interface AnalyzeInput {
title?: string;
slug?: string;
description?: string;
content?: string;
keyphrase?: string;
locale?: string; // default: "en_US"
}📊 Result Format
{
seo: AnalyzerResult;
readability: AnalyzerResult;
}AnalyzerResult
interface AnalyzerResult {
score: number;
rating: "good" | "ok" | "bad" | "feedback" | "error";
results: AnalysisItem[];
}🌍 Locale Support
English (en_US) by default.
🛠 Build & Compatibility
This package ships environment-specific builds:
| Environment | Supported | | ----------- | --------- | | Node.js | ✅ | | Browser | ✅ | | ESM | ✅ | | CommonJS | ✅ | | TypeScript | ✅ |
Thanks to conditional exports, bundlers automatically select the correct version.
📁 Package Output
dist/
├── browser/
│ ├── index.js
│ └── index.d.ts
├── node/
│ ├── index.js
│ ├── index.cjs
│ └── index.d.ts🤝 Why yoastjs?
Because content analysis should be simple, not blocked by legacy module formats.
yoastjs lets you use Yoast’s powerful engine in modern JavaScript without friction.
📝 License
MIT
