# dafont.js Scraper / wrapper **Node.js (ESM)** untuk [dafont.com](https://www.dafont.com). Bisa dipakai sebagai **CLI** maupun di-import sebagai **module**. --- ## Fitur | Fitur | Keterangan | |-------|------------| | Search | Cari font berdasarkan kata kunci | | New | Daftar font terbaru | | Top | Font terpopuler (yesterday / all-time) | | Category | Font per kategori (pakai cat id) | | Author | Semua font dari satu author | | Detail | Info lengkap 1 font (downloads, license, preview, files, dll) | | URL download | Ambil link ZIP langsung | --- ## Instalasi Butuh **Node.js 18+** (karena pakai native `fetch`). ```bash npm install cheerio ``` Simpan file `dafont.js` di folder project-mu. --- ## CLI ```bash node dafont.js [args] ``` ### Commands | Command | Argumen | Contoh | |---------|---------|--------| | `search` | ` [page]` | `node dafont.js search coolvetica` | | `new` | `[page]` | `node dafont.js new 1` | | `top` | `[page] [yesterday\|alltime]` | `node dafont.js top 1 alltime` | | `category` | ` [page]` | `node dafont.js category 101` | | `author` | ` [page]` | `node dafont.js author mans-greback.d2878` | | `font` | `` | `node dafont.js font super-bouncer` | | `url` | `` | `node dafont.js url super-bouncer` | ### Contoh output **Search** ```bash node dafont.js search coolvetica ``` ```json [ { "name": "Coolvetica", "slug": "coolvetica", "url": "https://www.dafont.com/coolvetica.font", "downloadUrl": "https://dl.dafont.com/dl/?f=coolvetica", "preview": "https://www.dafont.com/img/preview/c/o/coolvetica3.png", "downloads": 16423642, "downloadsYesterday": 4698, "license": "Free for personal use", "author": "Typodermic Fonts", "authorSlug": "typodermic-fonts.d1705", "categories": ["Basic", "Sans serif"] } ] ``` **Detail font** ```bash node dafont.js font super-bouncer ``` ```json { "name": "Super Bouncer", "slug": "super-bouncer", "url": "https://www.dafont.com/super-bouncer.font", "downloadUrl": "https://dl.dafont.com/dl/?f=super_bouncer", "preview": "https://www.dafont.com/img/preview/s/u/super_bouncer0.png", "illustration": "https://www.dafont.com/img/illustration/s/u/super_bouncer.png", "author": "fsuarez913", "authorSlug": "fsuarez913.d3946", "categories": [ { "name": "Fancy", "url": "https://www.dafont.com/mtheme.php?id=1" }, { "name": "Cartoon", "url": "https://www.dafont.com/theme.php?cat=101" } ], "downloads": 129422, "downloadsYesterday": 3361, "license": "100% Free", "files": ["Super Bouncer.ttf"], "firstSeen": "July 14, 2026", "note": "Free for personal use & commercial use. ..." } ``` --- ## Sebagai Module ```js import { search, getNewFonts, getTopFonts, getCategoryFonts, getAuthorFonts, getFont, getDownloadUrl, delay, } from './dafont.js'; // Cari font const hasil = await search('pixel', 1); console.log(hasil); // Font baru const baru = await getNewFonts(1); // Top all-time const top = await getTopFonts(1, 'alltime'); // Kategori Cartoon (cat=101) const cartoon = await getCategoryFonts(101, 1); // Detail const detail = await getFont('super-bouncer'); // URL download saja const url = getDownloadUrl('super-bouncer'); // → https://dl.dafont.com/dl/?f=super_bouncer // Jeda antar request (disarankan) await delay(1500); ``` --- ## Field yang dikembalikan ### List (search / new / top / category / author) | Field | Tipe | Keterangan | |-------|------|------------| | `name` | string | Nama font | | `slug` | string | Identifier (untuk URL & download) | | `url` | string | Halaman font di dafont | | `downloadUrl` | string | Link ZIP | | `preview` | string \| null | URL thumbnail preview | | `downloads` | number \| null | Total download | | `downloadsYesterday` | number \| null | Download kemarin | | `license` | string \| null | Jenis lisensi | | `author` | string \| null | Nama author | | `authorSlug` | string \| null | Slug author | | `categories` | string[] \| null | Kategori | ### Detail (`font`) Semua field di atas, plus: | Field | Tipe | Keterangan | |-------|------|------------| | `illustration` | string \| null | Gambar ilustrasi besar | | `files` | string[] | Nama file di dalam ZIP (`.ttf` / `.otf`) | | `firstSeen` | string \| null | Tanggal pertama muncul di dafont | | `note` | string \| null | Catatan dari author | | `categories` | `{ name, url }[]` | Kategori + link | --- ## Kategori populer (cat id) | ID | Kategori | |----|----------| | `101` | Fancy → Cartoon | | `103` | Fancy → Groovy | | `110` | Fancy → Horror | | `501` | Basic → Sans serif | | `601` | Script → Calligraphy | | `603` | Script → Handwritten | | `604` | Script → Brush | | `606` | Script → Graffiti | Lihat semua tema di [dafont.com/themes.php](https://www.dafont.com/themes.php). --- ## Catatan - Gunakan jeda antar request (`delay(1000–2000)`) agar tidak membebani server. - Endpoint `/search.php` di-disallow di `robots.txt` — pakai secukupnya. - Link download (`dl.dafont.com`) valid; buka lewat browser dari halaman font biasanya langsung dapat ZIP. - Encoding nama author kadang terlihat aneh (`M�ns`) karena charset halaman sumber (ISO-8859-1). - Lisensi font **wajib dicek** sebelum dipakai komersial. Field `license` hanya indikasi dari dafont. --- ## Lisensi kode Bebas dipakai & dimodifikasi.