emoji_mixer 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3c984da7efabcafed3c35c42f81f45f4ec4f7de819e840f5a65260fbaf0890bb
4
+ data.tar.gz: 403cda69dd1790753c20f06d0c2640c10087e442788301cb9bab931dbc8bce89
5
+ SHA512:
6
+ metadata.gz: cf26b44aa3f3e4953456d2f981e0f8114d04795bdb427fbcb22601300bb0df2ba3938c33e0dbe8ef860f062365e5b8be457206ee27db562d2c1e1be3ffc6d3bb
7
+ data.tar.gz: bd9715be69ed348b10e981a24b3cd0ca2014356ce43002fe385f918f91171ea2e9fbd8efe89db9d0c350e0d12f36688d948928cc09befa837bd3a1e488cb4070
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MattFor
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,143 @@
1
+ # Emoji Mixer
2
+
3
+ [![CI](https://github.com/MattFor/emoji-mixer/actions/workflows/ci.yml/badge.svg)](https://github.com/MattFor/emoji-mixer/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/emoji-mixer)](https://www.npmjs.com/package/emoji-mixer)
5
+ [![PyPI](https://img.shields.io/pypi/v/emoji-mixer)](https://pypi.org/project/emoji-mixer/)
6
+ [![crates.io](https://img.shields.io/crates/v/emoji-mixer)](https://crates.io/crates/emoji-mixer)
7
+ [![Go Reference](https://pkg.go.dev/badge/github.com/MattFor/emoji-mixer/v2.svg)](https://pkg.go.dev/github.com/MattFor/emoji-mixer/v2)
8
+ [![JSR](https://jsr.io/badges/@mattfor/emoji-mixer)](https://jsr.io/@mattfor/emoji-mixer)
9
+ [![Packagist](https://img.shields.io/packagist/v/mattfor/emoji-mixer)](https://packagist.org/packages/mattfor/emoji-mixer)
10
+ [![Gem](https://img.shields.io/gem/v/emoji_mixer)](https://rubygems.org/gems/emoji_mixer)
11
+ [![NuGet](https://img.shields.io/nuget/v/EmojiMixer)](https://www.nuget.org/packages/EmojiMixer)
12
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
13
+
14
+ Get the URL of a Google Emoji Kitchen image for two emojis.
15
+
16
+ ## Install
17
+
18
+ ```sh
19
+ npm install emoji-mixer # JavaScript / TypeScript, Node.js 20.19+
20
+ pip install emoji-mixer # Python 3.10+
21
+ cargo add emoji-mixer # Rust
22
+ go get github.com/MattFor/emoji-mixer/v2 # Go 1.21+
23
+ deno add jsr:@mattfor/emoji-mixer # Deno, or npx jsr add @mattfor/emoji-mixer
24
+ composer require mattfor/emoji-mixer # PHP 8.2+
25
+ gem install emoji_mixer # Ruby 3.3+
26
+ dotnet add package EmojiMixer # .NET 10+
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```js
32
+ import getEmojiMixUrl from 'emoji-mixer';
33
+ // or: const { default: getEmojiMixUrl } = require("emoji-mixer");
34
+
35
+ getEmojiMixUrl('🔥', '😃');
36
+ // https://www.gstatic.com/android/keyboard/emojikitchen/20201001/u1f603/u1f603_u1f525.png
37
+ ```
38
+
39
+ ```python
40
+ from emoji_mixer import get_emoji_mix_url
41
+
42
+ get_emoji_mix_url("🔥", "😃")
43
+ ```
44
+
45
+ ```rust
46
+ emoji_mixer::get_emoji_mix_url("🔥", "😃"); // Some(url)
47
+ ```
48
+
49
+ ```go
50
+ import emojimixer "github.com/MattFor/emoji-mixer/v2"
51
+
52
+ url, err := emojimixer.EmojiMixURL("🔥", "😃")
53
+ ```
54
+
55
+ ```php
56
+ use MattFor\EmojiMixer\EmojiMixer;
57
+
58
+ EmojiMixer::getEmojiMixUrl('🔥', '😃');
59
+ ```
60
+
61
+ ```ruby
62
+ require "emoji_mixer"
63
+
64
+ EmojiMixer.emoji_mix_url("🔥", "😃")
65
+ ```
66
+
67
+ ```csharp
68
+ using EmojiMixer;
69
+
70
+ EmojiKitchen.GetEmojiMixUrl("🔥", "😃");
71
+ ```
72
+
73
+ Emojis can be passed as characters (`"☕"`) or codepoint strings (`"2615"`, `"1F600"`, `"2764-fe0f"`). The FE0F variation selector is optional.
74
+
75
+ ## Functions
76
+
77
+ - `getEmojiMixUrl(leftEmoji, rightEmoji, detailedErrors = false)` (default export)
78
+ Returns the image URL, or `undefined` if an emoji is unsupported or the pair has no mix. With `detailedErrors`, throws an error explaining why instead.
79
+
80
+ - `toUnicode(input)`
81
+ Returns the codepoint key of one supported emoji, e.g. `"☕"` → `"2615"`, or `undefined`.
82
+
83
+ - `getEmojiCombo(leftEmoji, rightEmoji)`
84
+ Takes two codepoint keys and returns the newest `{ leftEmoji, rightEmoji, date }` combination, or `undefined`. `leftEmoji` and `rightEmoji` are in the order Google hosts the image under, which may differ from the argument order.
85
+
86
+ - `checkSupported(emoji)`
87
+ Returns every combination containing the emoji (on either side), or `null` if it is unsupported.
88
+
89
+ - `googleRequestUrl(combo)` / `googleRequestUrlEmojiPart(emoji)`
90
+ Build the image URL from a combination / format one emoji for the URL.
91
+
92
+ - `getExpandedEmojiCompatibilityData(useCache = false)`
93
+ Returns `{ [emoji]: combination[] }` for every supported emoji.
94
+
95
+ - `supportedEmojis`, `emojiCompatibilityData`, `baseUrl`
96
+ The supported codepoint keys, the compressed database and the image base URL.
97
+
98
+ **Python** has the same API in snake_case (`get_emoji_mix_url`, `to_unicode`, …, `BASE_URL`). It returns `None` instead of `undefined`/`null`, `detailed_errors` raises `ValueError`, and combinations are `EmojiCombo(left_emoji, right_emoji, date)` named tuples.
99
+
100
+ **Rust** has `get_emoji_mix_url`, `to_unicode`, `get_emoji_combo`, `check_supported`, `google_request_url`, `google_request_url_emoji_part`, `supported_emojis()` and `BASE_URL`, returning `Option`s.
101
+
102
+ **Go** has `EmojiMixURL` (an `error` says why there is no URL), `ToUnicode`, `EmojiCombo`, `CheckSupported`,
103
+ `ExpandedEmojiCompatibilityData`, `GoogleRequestURL`, `GoogleRequestURLEmojiPart`, `SupportedEmojis()` and `BaseURL`;
104
+ lookups return `(value, ok)` and combinations are `Combo{LeftEmoji, RightEmoji, Date}`.
105
+
106
+ **JSR** is the same TypeScript as the npm package.
107
+
108
+ **PHP** has the same API as static methods of `MattFor\EmojiMixer\EmojiMixer` (`getEmojiMixUrl`, `toUnicode`, …,
109
+ `BASE_URL`), returning `null`; `$detailedErrors` throws `InvalidArgumentException`, and combinations are `EmojiCombo`
110
+ objects with `leftEmoji`, `rightEmoji` and `date`.
111
+
112
+ **Ruby** has `EmojiMixer.emoji_mix_url(left, right, detailed_errors: false)`, `to_unicode`, `emoji_combo`,
113
+ `check_supported`, `expanded_emoji_compatibility_data`, `google_request_url`, `google_request_url_emoji_part`,
114
+ `supported_emojis` and `BASE_URL`, returning `nil`; `detailed_errors` raises `ArgumentError`, and combinations are
115
+ `EmojiMixer::EmojiCombo` values.
116
+
117
+ **C#** has the same API as static members of `EmojiMixer.EmojiKitchen` (`GetEmojiMixUrl`, `ToUnicode`, …,
118
+ `SupportedEmojis`, `BaseUrl`), returning `null`; `detailedErrors` throws `ArgumentException`, and combinations are
119
+ `EmojiCombo(LeftEmoji, RightEmoji, Date)` records.
120
+
121
+ ## Data format
122
+
123
+ `emojiCompatibilityData` is generated from [emojikitchen.dev](https://emojikitchen.dev/metadata.json) by `converter.ts`:
124
+
125
+ ```js
126
+ {
127
+ "$d": [20201001, 20260128], // unique dates
128
+ "$e": [9749, 9800], // unique emojis: codepoints as integers, sequences as strings
129
+ "2615": [[0, 0], [1, 1]], // [emojiIndex, dateIndex]
130
+ "2648": [[-1, 1]]
131
+ }
132
+ ```
133
+
134
+ A negative `emojiIndex` (`~i`) means the key emoji is the right-hand emoji in Google's URL. Above, both entries `[1, 1]` and `[-1, 1]` describe ☕ (left) + ♈ (right).
135
+
136
+ ## Attributions
137
+
138
+ - Created by MattFor | Discord tag: mattfor | [Github](https://github.com/MattFor)
139
+ - Inspired by [emoji-kitchen](https://github.com/xsalazar/emoji-kitchen) [made by Xavier Salazar a.k.a [xsalazar](https://github.com/xsalazar)]
140
+
141
+ ## License
142
+
143
+ MIT, see [LICENSE](LICENSE). By [MattFor](https://github.com/MattFor).
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module EmojiMixer
6
+ BASE_URL = "https://www.gstatic.com/android/keyboard/emojikitchen"
7
+
8
+ EmojiCombo = Data.define(:left_emoji, :right_emoji, :date)
9
+
10
+ DATA_FILE = File.expand_path("../../../compatibility.json", __dir__)
11
+ private_constant :DATA_FILE
12
+
13
+ class << self
14
+ def supported_emojis
15
+ data[:supported].dup
16
+ end
17
+
18
+ def to_unicode(input)
19
+ return nil unless input.is_a?(String) && input.valid_encoding?
20
+
21
+ codepoints = if input.match?(/\A[0-9a-f]+(-[0-9a-f]+)*\z/i)
22
+ input.downcase
23
+ else
24
+ input.each_char.map { |char| char.ord.to_s(16) }.join("-")
25
+ end
26
+ data[:by_stripped][strip_fe0f(codepoints)]
27
+ end
28
+
29
+ def check_supported(emoji)
30
+ key = to_unicode(emoji)
31
+ key && combos_of(key).map { |entry| expand(key, entry) }
32
+ end
33
+
34
+ def expanded_emoji_compatibility_data
35
+ data[:supported].to_h { |key| [key, check_supported(key)] }
36
+ end
37
+
38
+ def google_request_url_emoji_part(emoji)
39
+ emoji.split("-").map { |part| "u#{part.downcase}" }.join("-")
40
+ end
41
+
42
+ def google_request_url(combo)
43
+ left = google_request_url_emoji_part(combo.left_emoji)
44
+ "#{BASE_URL}/#{combo.date}/#{left}/#{left}_#{google_request_url_emoji_part(combo.right_emoji)}.png"
45
+ end
46
+
47
+ def emoji_combo(left_emoji, right_emoji)
48
+ [[left_emoji, right_emoji], [right_emoji, left_emoji]]
49
+ .flat_map { |anchor, other| combos_of(anchor).select { |index, _| emoji_at(index) == other }.map { |entry| expand(anchor, entry) } }
50
+ .max_by(&:date)
51
+ end
52
+
53
+ def emoji_mix_url(left_emoji, right_emoji, detailed_errors: false)
54
+ left = to_unicode(left_emoji)
55
+ right = to_unicode(right_emoji)
56
+ combo = left && right && emoji_combo(left, right)
57
+
58
+ return google_request_url(combo) if combo
59
+ return nil unless detailed_errors
60
+
61
+ raise ArgumentError, "'#{left_emoji}' [left_emoji] is not a supported emoji." unless left
62
+ raise ArgumentError, "'#{right_emoji}' [right_emoji] is not a supported emoji." unless right
63
+
64
+ compatible = combos_of(right).map { |index, _| emoji_at(index) }.join(", ")
65
+ raise ArgumentError,
66
+ "'#{left}' is not compatible with '#{right}'. Here are all emojis compatible with '#{right}':\n[#{compatible}]"
67
+ end
68
+
69
+ private
70
+
71
+ def data
72
+ @data ||= begin
73
+ raw = JSON.parse(File.read(DATA_FILE))
74
+ combos = raw.reject { |key, _| key.start_with?("$") }
75
+ supported = combos.keys.sort
76
+ {
77
+ emojis: raw["$e"].map { |emoji| emoji.is_a?(Integer) ? emoji.to_s(16) : emoji },
78
+ dates: raw["$d"].map(&:to_s),
79
+ combos: combos,
80
+ supported: supported,
81
+ by_stripped: supported.to_h { |key| [strip_fe0f(key), key] }
82
+ }
83
+ end
84
+ end
85
+
86
+ def strip_fe0f(codepoints)
87
+ codepoints.split("-").reject { |part| part == "fe0f" }.join("-")
88
+ end
89
+
90
+ def combos_of(emoji)
91
+ data[:combos].fetch(emoji, [])
92
+ end
93
+
94
+ def emoji_at(index)
95
+ data[:emojis][index.negative? ? ~index : index]
96
+ end
97
+
98
+ def expand(anchor, (index, date_index))
99
+ other = emoji_at(index)
100
+ date = data[:dates][date_index]
101
+ index.negative? ? EmojiCombo.new(other, anchor, date) : EmojiCombo.new(anchor, other, date)
102
+ end
103
+ end
104
+ end