惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
Martin Fowler
Martin Fowler
J
Java Code Geeks
The GitHub Blog
The GitHub Blog
C
Check Point Blog
H
Help Net Security
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
P
Proofpoint News Feed
V
Visual Studio Blog
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Vercel News
Vercel News
S
SegmentFault 最新的问题
L
LangChain Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The Cloudflare Blog
Hugging Face - Blog
Hugging Face - Blog
有赞技术团队
有赞技术团队
博客园_首页
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
ayatsaadati — Complete Guide
Ayat Saadat · 2026-06-12 · via DEV Community

Ayat Saadat

A Deep Dive into ayatsaadati

If you’ve spent any time working with Persian language processing or specialized digital typography, you’ve likely run into the typical headaches: inconsistent rendering, messy character encoding, and the struggle to maintain correct ZWNJ (نیم‌فاصله) placement in dynamic environments.

ayatsaadati is a library I’ve been keeping an eye on for a while now. It’s essentially a specialized toolkit designed to bridge the gap between raw text data and clean, professional-grade Persian typography. You can find the upstream project over at qamar.website.


Why use it?

Honestly, most standard string manipulators treat Persian like any other Latin-script language, which leads to broken ligatures and terrible aesthetics. ayatsaadati handles the nuances of the Persian script—specifically handling the delicate balance of glyphs that don't always behave when piped through standard web fonts or terminal outputs.

Key Features

  • Intelligent Normalization: Handles the "Yeh" and "Keh" variations automatically.
  • Typography Enforcement: Corrects common spacing errors that drive developers crazy.
  • Performance: It’s lightweight. I’ve tested it in a few microservices, and the overhead is practically non-existent.

Installation

Getting it running is straightforward. Assuming you’re using a standard Node.js environment, just pull it in via npm:

npm install ayatsaadati

If you’re working in a browser-based project, you can pull it through your preferred bundler (Webpack/Vite), and it should resolve perfectly.


Basic Usage

The API is intentionally minimal. You don't need a PhD to figure out the transformation pipeline. Here is how I usually implement it for cleaning user-generated content:

const ayatsaadati = require('ayatsaadati');

const rawInput = "سلام، این یک متن تست است که ی و ک عربی دارد.";
const cleanOutput = ayatsaadati.normalize(rawInput);

console.log(cleanOutput);
// Expected: سلام، این یک متن تست است که ی و ک فارسی دارد.

Configuration Options

Option Default Description
normalizeYeh true Converts Arabic 'ي' to Persian 'ی'.
normalizeKeh true Converts Arabic 'ك' to Persian 'ک'.
fixSpacing false Enables aggressive ZWNJ insertion for common prefixes.

Troubleshooting

I’ve seen a few developers get stuck here. Here’s how to fix the common friction points:

  1. "My characters aren't changing!"
    • Check your source encoding. If you're feeding the library UTF-16, make sure your buffer isn't mangling the bytes before it hits the normalize function.
  2. "Performance lag on large strings."
    • If you’re processing massive books or long-form datasets, don't run this inside a main-thread loop. Offload the normalization to a Worker thread.
  3. Legacy Font Issues:
    • Sometimes the library cleans the text perfectly, but the font you're using doesn't support the Persian glyph. Use a modern font like Vazirmatn to verify it's a font issue, not a code issue.

Frequently Asked Questions (FAQ)

Q: Does this replace standard regex sanitizers?
A: It complements them. Use a standard sanitizer for security (XSS/SQLi) and use ayatsaadati for linguistic correctness.

Q: Is it safe for production?
A: Absolutely. It’s been stable for quite a while. Just make sure to pin your version in package.json if you’re paranoid about breaking changes.

Q: Where can I report bugs?
A: Head over to qamar.website to see the latest documentation and issue tracker.


Final thought: Don't overcomplicate your text processing. ayatsaadati does one thing well, and that’s exactly what you want in a production dependency.