diff --git a/README.md b/README.md index eac7250..ef24248 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ console.log(skinTone("πŸ§‘πŸΏβ€πŸ€β€πŸ§‘πŸΏ", "light")); // πŸ§‘πŸ»β€πŸ€ ### Browser ```js -// https://unpkg.com/@qit.tools/skin-tone@0.6.0/dist/browser/latest.min.js +// https://unpkg.com/@qit.tools/skin-tone@0.6.1/dist/browser/latest.min.js document.addEventListener("DOMContentLoaded", () => { console.log(skinTone("πŸ§‘πŸ»β€πŸ€β€πŸ§‘πŸ»", "dark")); diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..b9325a7 Binary files /dev/null and b/bun.lockb differ diff --git a/dist/browser/latest.min.js b/dist/browser/latest.min.js index 5cdd7da..86424c7 100644 --- a/dist/browser/latest.min.js +++ b/dist/browser/latest.min.js @@ -5,7 +5,7 @@ var skinTone=function(){"use strict"; * * πŸͺ„ Qit.tools * @name @qit.tools/skin-tone - * @version 0.6.0 + * @version 0.6.1 * @license MIT * @copyright Copyright (c) 2024 Qit.tools. * @see https://github.com/Qit-tools/skin-tone @@ -15,7 +15,7 @@ var skinTone=function(){"use strict"; * RGI Emoji Modifier Sequence. * * @param {string} emoji - The original emoji string. - * @param {SkinTone} [tone] - The skin tone to apply. If undefined, returns the original emoji. + * @param {SkinTone} tone - The skin tone to apply. If empty, returns the original emoji. * @returns {string} The emoji string with skin tones applied where applicable. - */return function(n,i){var e={"":"",none:"",light:"🏻",mediumLight:"🏼",medium:"🏽",mediumDark:"🏾",dark:"🏿"};if(!i||!(i in e))return n;var r=n.includes("β€πŸ€β€")?"β€πŸ€β€":"‍";return n.split(r).map((function(n){var r=n.replace(/[\u{1F3FB}-\u{1F3FF}]/gu,"");return"none"===i?r:/\p{Emoji_Modifier_Base}/u.test(r)?r+e[i]:n})).join(r)}}(); + */return function(i,e){if(!e)return i;var r={none:"",light:"🏻",mediumLight:"🏼",medium:"🏽",mediumDark:"🏾",dark:"🏿"},n="‍";return i.includes("β€πŸ€β€")&&(n="β€πŸ€β€"),i.split(n).map((function(i){var n=i.replace(/\p{Emoji_Modifier}/gu,"");return/\p{Emoji_Modifier_Base}/u.test(n)?n.replace(/(\p{Extended_Pictographic}+)(\uFE0F?)/u,"$1".concat(r[e])):i})).join(n)}}(); //# sourceMappingURL=latest.min.js.map diff --git a/dist/browser/latest.min.js.map b/dist/browser/latest.min.js.map index 419a18e..3429d7c 100644 --- a/dist/browser/latest.min.js.map +++ b/dist/browser/latest.min.js.map @@ -1 +1 @@ -{"version":3,"file":"latest.min.js","sources":["../../src/index.ts"],"sourcesContent":[null],"names":["emoji","tone","skinToneMap","none","light","mediumLight","medium","mediumDark","dark","zwj","includes","split","map","part","basePart","replace","test","join"],"mappings":";;;;;;;;;;;;;;;;;;;cAqBc,SAAmBA,EAAeC,GAC9C,IAAMC,EAAwC,CAC5C,GAAI,GACJC,KAAM,GACNC,MAAO,KACPC,YAAa,KACbC,OAAQ,KACRC,WAAY,KACZC,KAAM,MAIR,IAAKP,KAAUA,KAAQC,GACrB,OAAOF,EAGT,IAAMS,EAAMT,EAAMU,SAAS,QAA8B,OAA6B,IAmBtF,OAjBcV,EAAMW,MAAMF,GACEG,KAAI,SAACC,GAE/B,IAAMC,EAAWD,EAAKE,QAAQ,0BAA2B,IAGzD,MAAa,SAATd,EACKa,EAIL,2BAA2BE,KAAKF,GAC3BA,EAAWZ,EAAYD,GAEzBY,CACT,IAEqBI,KAAKR,EAC5B"} \ No newline at end of file +{"version":3,"file":"latest.min.js","sources":["../../src/index.ts"],"sourcesContent":[null],"names":["emoji","tone","skinTonMap","none","light","mediumLight","medium","mediumDark","dark","zwj","includes","split","map","part","basePart","replace","test","concat","join"],"mappings":";;;;;;;;;;;;;;;;;;;cAqBc,SAAmBA,EAAeC,GAC9C,IAAKA,EACH,OAAOD,EAET,IAAME,EAAa,CACjBC,KAAM,GACNC,MAAO,KACPC,YAAa,KACbC,OAAQ,KACRC,WAAY,KACZC,KAAM,MAGJC,EAAM,IAiBV,OAdIT,EAAMU,SAAS,UACjBD,EAAM,QAGMT,EAAMW,MAAMF,GACEG,KAAI,SAACC,GAC/B,IAAMC,EAAWD,EAAKE,QAAQ,uBAAwB,IAEtD,MAAI,2BAA2BC,KAAKF,GAC3BA,EAASC,QAAQ,yCAA0C,KAAKE,OAAAf,EAAWD,KAE7EY,CACT,IAEqBK,KAAKT,EAC5B"} \ No newline at end of file diff --git a/dist/esnext/index.d.ts b/dist/esnext/index.d.ts index 7987fed..8adf7fc 100644 --- a/dist/esnext/index.d.ts +++ b/dist/esnext/index.d.ts @@ -5,7 +5,7 @@ export type SkinTone = '' | 'none' | 'light' | 'mediumLight' | 'medium' | 'mediu * * πŸͺ„ Qit.tools * @name @qit.tools/skin-tone - * @version 0.6.0 + * @version 0.6.1 * @license MIT * @copyright Copyright (c) 2024 Qit.tools. * @see https://github.com/Qit-tools/skin-tone @@ -15,7 +15,7 @@ export type SkinTone = '' | 'none' | 'light' | 'mediumLight' | 'medium' | 'mediu * RGI Emoji Modifier Sequence. * * @param {string} emoji - The original emoji string. - * @param {SkinTone} [tone] - The skin tone to apply. If undefined, returns the original emoji. + * @param {SkinTone} tone - The skin tone to apply. If empty, returns the original emoji. * @returns {string} The emoji string with skin tones applied where applicable. */ export default function skinTone(emoji: string, tone?: SkinTone): string; diff --git a/dist/esnext/index.js b/dist/esnext/index.js index 56d6bce..ae4e1fc 100644 --- a/dist/esnext/index.js +++ b/dist/esnext/index.js @@ -4,7 +4,7 @@ * * πŸͺ„ Qit.tools * @name @qit.tools/skin-tone - * @version 0.6.0 + * @version 0.6.1 * @license MIT * @copyright Copyright (c) 2024 Qit.tools. * @see https://github.com/Qit-tools/skin-tone @@ -14,12 +14,14 @@ * RGI Emoji Modifier Sequence. * * @param {string} emoji - The original emoji string. - * @param {SkinTone} [tone] - The skin tone to apply. If undefined, returns the original emoji. + * @param {SkinTone} tone - The skin tone to apply. If empty, returns the original emoji. * @returns {string} The emoji string with skin tones applied where applicable. */ function skinTone(emoji, tone) { - const skinToneMap = { - '': '', + if (!tone) { + return emoji; + } + const skinTonMap = { none: '', light: '\u{1F3FB}', mediumLight: '\u{1F3FC}', @@ -27,22 +29,16 @@ function skinTone(emoji, tone) { mediumDark: '\u{1F3FE}', dark: '\u{1F3FF}', }; - // If no tone or invalid tone is provided, return the original emoji - if (!tone || !(tone in skinToneMap)) { - return emoji; + let zwj = '\u200D'; + // Hand Shake πŸ§‘β€πŸ€β€πŸ§‘ + if (emoji.includes('\u200d\ud83e\udd1d\u200d')) { + zwj = '\u200d\ud83e\udd1d\u200d'; } - const zwj = emoji.includes('\u200D\ud83E\udd1D\u200D') ? '\u200D\ud83E\udd1D\u200D' : '\u200D'; const parts = emoji.split(zwj); const modifiedParts = parts.map((part) => { - // Remove existing skin tone modifiers - const basePart = part.replace(/[\u{1F3FB}-\u{1F3FF}]/gu, ''); - // If tone is 'none', return the base part without modifiers - if (tone === 'none') { - return basePart; - } - // Check if the base part is an Emoji Modifier Base + const basePart = part.replace(/\p{Emoji_Modifier}/gu, ''); if (/\p{Emoji_Modifier_Base}/u.test(basePart)) { - return basePart + skinToneMap[tone]; + return basePart.replace(/(\p{Extended_Pictographic}+)(\uFE0F?)/u, `$1${skinTonMap[tone]}`); } return part; }); diff --git a/dist/esnext/index.js.map b/dist/esnext/index.js.map index ef5ea06..20d21fd 100644 --- a/dist/esnext/index.js.map +++ b/dist/esnext/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sources":["../../../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;AAkBG;AACW,SAAU,QAAQ,CAAC,KAAa,EAAE,IAAe,EAAA;AAC7D,IAAA,MAAM,WAAW,GAA6B;AAC5C,QAAA,EAAE,EAAE,EAAE;AACN,QAAA,IAAI,EAAE,EAAE;AACR,QAAA,KAAK,EAAE,WAAW;AAClB,QAAA,WAAW,EAAE,WAAW;AACxB,QAAA,MAAM,EAAE,WAAW;AACnB,QAAA,U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IAAI,EAAE,WAAW;KAClB,CAAC;IAEF,IAAI,GAAG,GAAG,QAAQ,CAAC;;AAGnB,IAAA,IAAI,KAAK,CAAC,QAAQ,CAAC,0BAA0B,CAAC,EAAE;QAC9C,GAAG,GAAG,0BAA0B,CAAC;KAClC;IAED,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,aAAa,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,KAAI;QACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC;AAE1D,QAAA,IAAI,0BAA0B,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;AAC7C,YAAA,OAAO,QAAQ,CAAC,OAAO,CAAC,wCAAwC,EAAE,CAAK,EAAA,EAAA,UAAU,CAAC,IAAI,CAAC,CAAA,CAAE,CAAC,CAAC;SAC5F;AACD,QAAA,OAAO,IAAI,CAAC;AACd,KAAC,CAAC,CAAC;AAEH,IAAA,OAAO,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACjC;;;;"} \ No newline at end of file diff --git a/package.json b/package.json index 1fe15ce..a3a8b7d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@qit.tools/skin-tone", - "version": "0.6.0", + "version": "0.6.1", "description": "Change emoji skin tones effortlessly. πŸ§›πŸ§›πŸ»πŸ§›πŸΌπŸ§›πŸ½πŸ§›πŸΎπŸ§›πŸΏ", "types": "./dist/esnext/index.d.ts", "exports": { diff --git a/src/index.ts b/src/index.ts index ce8586d..02d3ad7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,4 +50,4 @@ export default function skinTone(emoji: string, tone?: SkinTone): string { }); return modifiedParts.join(zwj); -} \ No newline at end of file +}