@encfy/core
v0.2.0
Published
Pure TypeScript text tools: encoding, hashing, text transformation, generators, Brazilian document validation and PDF generation. Zero dependencies, works in browsers, Node.js and Deno.
Maintainers
Readme
@encfy/core
Pure TypeScript text and PDF tools with zero runtime dependencies. Works in browsers, Node.js (>= 18), Deno and Bun.
This package powers the free tools on encfy.com and the local tools of the Encfy MCP Server. Everything here is pure computation: no I/O, no state, no network.
npm install @encfy/core
# or
pnpm add @encfy/coreUsage
import { base64Encode, sha256, slugify, validateCpf, uuidV4 } from "@encfy/core";
base64Encode("Olá"); // "T2zDoQ=="
await sha256("abc"); // "ba7816bf..."
slugify("Olá Mundo!"); // "ola-mundo"
validateCpf("529.982.247-25"); // { valid: true, formatted: "529.982.247-25", ... }
uuidV4(); // "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"Modules
| Module | Functions |
|---|---|
| encoding | base64Encode/Decode, urlEncode/Decode, htmlEntitiesEncode/Decode, morseEncode/Decode, natoEncode/Decode, rot, rot13, rot47, hexEncode/Decode, binaryEncode/Decode, removeDiacritics |
| hashing | md5 (sync), sha1, sha256, sha384, sha512 (Web Crypto, async), hash(algorithm, input) |
| text | slugify, changeCase (upper, lower, title, sentence, camel, pascal, snake, kebab, constant, alternating, inverse), trimText, dedupLines, sortLines, reverseLines, shuffleLines, stripHtml, reverseText, upsideDownText, addPrefixSuffix, addLineNumbers, countText, extractNumbers/Emails/Urls |
| generators | uuidV4, uuidV4Batch, isUuid, timestampToDate, dateToTimestamp, minutesToHours, hoursToMinutes, hexToRgb, rgbToHex, parseRgb, rgbToHsl, hslToRgb, parseColor, randomHexColor, randomString |
| pdf | createPdf (sync, deterministic), createEncryptedPdf (AES-256, async), pdfPageDimensions, PDF_PAGE_SIZES |
| validation | validateCpf, isValidCpf, formatCpf, generateCpf, validateCnpj (numeric and alphanumeric), isValidCnpj, formatCnpj, generateCnpj, formatCep, isValidCepFormat, isValidEmail |
Generate blank pages, lined / graph / dot-grid paper, plain text, form fields, files of an exact size and password-protected files — handy as fixtures for upload, parser and preview tests. Ready-made files are published at encfy.com/tools/pdf/sample-pdf-files/.
import { createPdf, createEncryptedPdf } from "@encfy/core";
createPdf(); // 1 blank A4 page
createPdf({ size: "letter", orientation: "landscape", pages: 10 });
createPdf({ pattern: "grid", spacingMm: 5, color: "#c8c8c8" });
createPdf({ text: ["First page", "Second page"], pageNumbers: true });
createPdf({ fields: [{ type: "text", name: "email" }, { type: "checkbox", name: "accept" }] });
createPdf({ padToBytes: 10 * 1024 * 1024 }); // exactly 10 MB, still valid
await createEncryptedPdf({ userPassword: "secret" }); // AES-256 (PDF 2.0 / R6)
await createEncryptedPdf({ userPassword: "", ownerPassword: "owner", permissions: { print: false, copy: false } });createPdf returns a Uint8Array and always produces the same bytes for the
same options. createEncryptedPdf uses random salts and keys unless you pass a
seed (only for public fixtures, since it makes the key predictable). Text uses
the built-in Helvetica font, so characters outside Windows-1252 become ?.
Free vs premium
Everything in this package is free and MIT-licensed. Tools that need server-side secrets or external data (HMAC, UUID v7, QR codes, JSON/CSV/YAML/XML conversion, CEP lookup, CPF/CNPJ enrichment) live in the Encfy REST API.
Development
pnpm install
pnpm --filter @encfy/core test
pnpm --filter @encfy/core buildLicense
MIT © Maicon Schmitz / Encfy
