UNPKG

sikits

Version:

A powerful and comprehensive utility library for JavaScript and TypeScript with 100+ functions for strings, numbers, arrays, and objects

251 lines (250 loc) โ€ข 7.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.rangeRandomEmojis = exports.rangeRandomHexColors = exports.rangeRandomColors = exports.rangeRandomStrings = exports.rangeRandom = exports.rangePrimes = exports.rangeFibonacci = exports.rangeBusinessDays = exports.rangeWeekends = exports.rangeWeekdays = exports.rangeYears = exports.rangeMonths = exports.rangeDates = exports.rangeChars = exports.rangeLength = exports.rangeReverse = exports.range = void 0; /** * Creates a range of numbers */ const range = (start, end, step = 1) => { const result = []; for (let i = start; i <= end; i += step) { result.push(i); } return result; }; exports.range = range; /** * Creates a range of numbers in reverse order */ const rangeReverse = (start, end, step = 1) => { const result = []; for (let i = start; i >= end; i -= step) { result.push(i); } return result; }; exports.rangeReverse = rangeReverse; /** * Creates a range of numbers with specified length */ const rangeLength = (start, length, step = 1) => { const result = []; for (let i = 0; i < length; i++) { result.push(start + i * step); } return result; }; exports.rangeLength = rangeLength; /** * Creates a range of characters */ const rangeChars = (start, end) => { const startCode = start.charCodeAt(0); const endCode = end.charCodeAt(0); const result = []; for (let i = startCode; i <= endCode; i++) { result.push(String.fromCharCode(i)); } return result; }; exports.rangeChars = rangeChars; /** * Creates a range of dates */ const rangeDates = (start, end, stepDays = 1) => { const result = []; const current = new Date(start); while (current <= end) { result.push(new Date(current)); current.setDate(current.getDate() + stepDays); } return result; }; exports.rangeDates = rangeDates; /** * Creates a range of months */ const rangeMonths = (start, end) => { const result = []; const current = new Date(start); while (current <= end) { result.push(new Date(current)); current.setMonth(current.getMonth() + 1); } return result; }; exports.rangeMonths = rangeMonths; /** * Creates a range of years */ const rangeYears = (start, end) => { const result = []; const current = new Date(start); while (current <= end) { result.push(new Date(current)); current.setFullYear(current.getFullYear() + 1); } return result; }; exports.rangeYears = rangeYears; /** * Creates a range of weekdays */ const rangeWeekdays = (start, end) => { const result = []; const current = new Date(start); while (current <= end) { const dayOfWeek = current.getDay(); if (dayOfWeek !== 0 && dayOfWeek !== 6) { // Skip weekends result.push(new Date(current)); } current.setDate(current.getDate() + 1); } return result; }; exports.rangeWeekdays = rangeWeekdays; /** * Creates a range of weekends */ const rangeWeekends = (start, end) => { const result = []; const current = new Date(start); while (current <= end) { const dayOfWeek = current.getDay(); if (dayOfWeek === 0 || dayOfWeek === 6) { // Only weekends result.push(new Date(current)); } current.setDate(current.getDate() + 1); } return result; }; exports.rangeWeekends = rangeWeekends; /** * Creates a range of business days (excluding weekends and holidays) */ const rangeBusinessDays = (start, end, holidays = []) => { const result = []; const current = new Date(start); while (current <= end) { const dayOfWeek = current.getDay(); const isWeekend = dayOfWeek === 0 || dayOfWeek === 6; const isHoliday = holidays.some(holiday => holiday.getFullYear() === current.getFullYear() && holiday.getMonth() === current.getMonth() && holiday.getDate() === current.getDate()); if (!isWeekend && !isHoliday) { result.push(new Date(current)); } current.setDate(current.getDate() + 1); } return result; }; exports.rangeBusinessDays = rangeBusinessDays; /** * Creates a range of Fibonacci numbers */ const rangeFibonacci = (count) => { const result = []; let a = 0, b = 1; for (let i = 0; i < count; i++) { result.push(a); [a, b] = [b, a + b]; } return result; }; exports.rangeFibonacci = rangeFibonacci; /** * Creates a range of prime numbers */ const rangePrimes = (count) => { const result = []; let num = 2; while (result.length < count) { if (isPrime(num)) { result.push(num); } num++; } return result; }; exports.rangePrimes = rangePrimes; /** * Helper function to check if a number is prime */ const isPrime = (num) => { if (num < 2) return false; if (num === 2) return true; if (num % 2 === 0) return false; for (let i = 3; i <= Math.sqrt(num); i += 2) { if (num % i === 0) return false; } return true; }; /** * Creates a range of random numbers */ const rangeRandom = (count, min = 0, max = 100) => { const result = []; for (let i = 0; i < count; i++) { result.push(Math.floor(Math.random() * (max - min + 1)) + min); } return result; }; exports.rangeRandom = rangeRandom; /** * Creates a range of random strings */ const rangeRandomStrings = (count, length = 8) => { const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const result = []; for (let i = 0; i < count; i++) { let str = ''; for (let j = 0; j < length; j++) { str += chars.charAt(Math.floor(Math.random() * chars.length)); } result.push(str); } return result; }; exports.rangeRandomStrings = rangeRandomStrings; /** * Creates a range of random colors */ const rangeRandomColors = (count) => { const result = []; for (let i = 0; i < count; i++) { const r = Math.floor(Math.random() * 256); const g = Math.floor(Math.random() * 256); const b = Math.floor(Math.random() * 256); result.push(`rgb(${r}, ${g}, ${b})`); } return result; }; exports.rangeRandomColors = rangeRandomColors; /** * Creates a range of random hex colors */ const rangeRandomHexColors = (count) => { const result = []; for (let i = 0; i < count; i++) { const color = '#' + Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0'); result.push(color); } return result; }; exports.rangeRandomHexColors = rangeRandomHexColors; /** * Creates a range of random emojis */ const rangeRandomEmojis = (count) => { const emojis = ['๐Ÿ˜€', '๐Ÿ˜ƒ', '๐Ÿ˜„', '๐Ÿ˜', '๐Ÿ˜†', '๐Ÿ˜…', '๐Ÿ˜‚', '๐Ÿคฃ', '๐Ÿ˜Š', '๐Ÿ˜‡', '๐Ÿ™‚', '๐Ÿ™ƒ', '๐Ÿ˜‰', '๐Ÿ˜Œ', '๐Ÿ˜', '๐Ÿฅฐ', '๐Ÿ˜˜', '๐Ÿ˜—', '๐Ÿ˜™', '๐Ÿ˜š', '๐Ÿ˜‹', '๐Ÿ˜›', '๐Ÿ˜', '๐Ÿ˜œ', '๐Ÿคช', '๐Ÿคจ', '๐Ÿง', '๐Ÿค“', '๐Ÿ˜Ž', '๐Ÿคฉ', '๐Ÿฅณ', '๐Ÿ˜', '๐Ÿ˜’', '๐Ÿ˜ž', '๐Ÿ˜”', '๐Ÿ˜Ÿ', '๐Ÿ˜•', '๐Ÿ™', 'โ˜น๏ธ', '๐Ÿ˜ฃ', '๐Ÿ˜–', '๐Ÿ˜ซ', '๐Ÿ˜ฉ', '๐Ÿฅบ', '๐Ÿ˜ข', '๐Ÿ˜ญ', '๐Ÿ˜ค', '๐Ÿ˜ ', '๐Ÿ˜ก', '๐Ÿคฌ', '๐Ÿคฏ', '๐Ÿ˜ณ', '๐Ÿฅต', '๐Ÿฅถ', '๐Ÿ˜ฑ', '๐Ÿ˜จ', '๐Ÿ˜ฐ', '๐Ÿ˜ฅ', '๐Ÿ˜“', '๐Ÿค—', '๐Ÿค”', '๐Ÿคญ', '๐Ÿคซ', '๐Ÿคฅ', '๐Ÿ˜ถ', '๐Ÿ˜', '๐Ÿ˜‘', '๐Ÿ˜ฏ', '๐Ÿ˜ฆ', '๐Ÿ˜ง', '๐Ÿ˜ฎ', '๐Ÿ˜ฒ', '๐Ÿฅฑ', '๐Ÿ˜ด', '๐Ÿคค', '๐Ÿ˜ช', '๐Ÿ˜ต', '๐Ÿค', '๐Ÿฅด', '๐Ÿคข', '๐Ÿคฎ', '๐Ÿคง', '๐Ÿ˜ท', '๐Ÿค’', '๐Ÿค•', '๐Ÿค‘', '๐Ÿค ']; const result = []; for (let i = 0; i < count; i++) { const randomIndex = Math.floor(Math.random() * emojis.length); result.push(emojis[randomIndex]); } return result; }; exports.rangeRandomEmojis = rangeRandomEmojis;