emojify-lyrics
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -7,3 +7,4 @@ export interface EmojifyOptions { | ||
multimojiChance?: number; | ||
allowFlags?: boolean; | ||
} | ||
export declare function emojify(inputText: string, { replace, replaceChance, tripleCooldown, tripleChance, multimojiChance, }?: EmojifyOptions): string; | ||
export declare function emojify(inputText: string, { replace, replaceChance, tripleCooldown, tripleChance, multimojiChance, allowFlags, }?: EmojifyOptions): string; |
import emojiMapJson from './emojiMap.json'; | ||
const emojiMap = emojiMapJson; | ||
export function emojify(inputText, { replace = false, replaceChance = 1, tripleCooldown = 3, tripleChance = 0.05, multimojiChance = 0.1, } = {}) { | ||
export function emojify(inputText, { replace = false, replaceChance = 1, tripleCooldown = 3, tripleChance = 0.05, multimojiChance = 0.1, allowFlags = true, } = {}) { | ||
const lines = inputText.split(/\n/); | ||
@@ -18,2 +18,5 @@ const outputLines = []; | ||
if (emojis.length > 0) { | ||
if (!allowFlags) { | ||
stripFlags(emojis); | ||
} | ||
const grabEmoji = () => { | ||
@@ -160,5 +163,22 @@ const emojiIndex = Math.floor(Math.random() * emojis.length); | ||
} | ||
/** | ||
* In-place removal of flag emojis from the list. | ||
* | ||
* @param emojis The list of emojis to strip flags from. | ||
*/ | ||
function stripFlags(emojis) { | ||
for (let i = emojis.length - 1; i >= 0; i--) { | ||
if (isFlagEmoji(emojis[i])) { | ||
emojis.splice(i, 1); | ||
} | ||
} | ||
} | ||
// https://stackoverflow.com/questions/53360006/detect-with-regex-if-emoji-is-country-flag | ||
const flagMatcher = /[\uD83C][\uDDE6-\uDDFF][\uD83C][\uDDE6-\uDDFF]/; | ||
function isFlagEmoji(emoji) { | ||
return emoji.length === 4 && emoji.match(flagMatcher) !== null; | ||
} | ||
// Adopted from https://github.com/notwaldorf/emoji-translate/blob/master/emoji-translate.js for dependency reasons | ||
// MIT License, available at https://raw.githubusercontent.com/notwaldorf/emoji-translate/master/LICENSE | ||
const rangeMatcher = [ | ||
const rangeMatcherString = [ | ||
'\uD83C[\uDF00-\uDFFF]', // U+1F300 to U+1F3FF | ||
@@ -168,2 +188,3 @@ '\uD83D[\uDC00-\uDE4F]', // U+1F400 to U+1F64F | ||
].join('|'); | ||
const rangeMatcher = new RegExp(rangeMatcherString); | ||
/** | ||
@@ -170,0 +191,0 @@ * Returns true for something that's already an emoji like 🤖. |
{ | ||
"name": "emojify-lyrics", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "Making the world a :slight_smile: place", | ||
@@ -35,7 +35,7 @@ "module": "dist/index.js", | ||
"husky": "^9.1.7", | ||
"lint-staged": "^15.2.11", | ||
"lint-staged": "^15.3.0", | ||
"pinst": "^3.0.0", | ||
"prettier": "^3.4.2", | ||
"typescript": "^5.7.2", | ||
"typescript-eslint": "^8.18.0", | ||
"typescript-eslint": "^8.19.0", | ||
"unicode-emoji-json": "^0.8.0", | ||
@@ -42,0 +42,0 @@ "vitest": "^2.1.8" |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
355406
1419
0