UNPKG

everyutil

Version:

A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.

21 lines (20 loc) 677 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.shiftText = void 0; /** * Shifts characters in the string like a Caesar cipher. * * Example: shiftText("abc", 1) → "bcd" * * @author @dailker * @param {string} str - The input string. * @param {number} shift - The number of positions to shift each letter. * @returns {string} The shifted string. */ function shiftText(str, shift) { return str.replace(/[a-z]/gi, c => { const base = c >= 'a' && c <= 'z' ? 97 : 65; return String.fromCharCode(((c.charCodeAt(0) - base + shift) % 26 + 26) % 26 + base); }); } exports.shiftText = shiftText;