Comparing version 1.1.0 to 2.0.0
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,7 +6,25 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.shortnameRegex = exports.emojiRegex = exports.emojiCollection = exports.render = exports.renderShortname = exports.unicodeToShortnames = exports.shortnamesToUnicode = exports.isSingleEmoji = undefined; | ||
Object.defineProperty(exports, "emojiCollection", { | ||
enumerable: true, | ||
get: function get() { | ||
return _emojis.collection; | ||
} | ||
}); | ||
Object.defineProperty(exports, "emojiRegex", { | ||
enumerable: true, | ||
get: function get() { | ||
return _emojis.emojiRegex; | ||
} | ||
}); | ||
Object.defineProperty(exports, "shortnameRegex", { | ||
enumerable: true, | ||
get: function get() { | ||
return _emojis.shortnameRegex; | ||
} | ||
}); | ||
exports.render = exports.renderShortname = exports.unicodeToShortnames = exports.shortnamesToUnicode = exports.isSingleEmoji = void 0; | ||
var _emojis = require('../vendor/emojis'); | ||
var _emojis = require("../vendor/emojis"); | ||
var _utils = require('./utils'); | ||
var _utils = require("./utils"); | ||
@@ -16,5 +34,5 @@ // If strange bugs appear, create new regex in each function | ||
var regexUnicode = new RegExp(_emojis.emojiRegex, 'g'); | ||
var regexAny = new RegExp('^(' + _emojis.shortnameRegex + '|' + _emojis.emojiRegex + ')$'); | ||
var regexAny = new RegExp("^(".concat(_emojis.shortnameRegex, "|").concat(_emojis.emojiRegex, ")$")); | ||
var isSingleEmoji = exports.isSingleEmoji = function isSingleEmoji(string) { | ||
var isSingleEmoji = function isSingleEmoji(string) { | ||
if (typeof string !== 'string' || !string) return false; | ||
@@ -24,7 +42,12 @@ return regexAny.test(string.trim()); | ||
var shortnamesToUnicode = exports.shortnamesToUnicode = function shortnamesToUnicode(string) { | ||
exports.isSingleEmoji = isSingleEmoji; | ||
var shortnamesToUnicode = function shortnamesToUnicode(string) { | ||
if (typeof string !== 'string') return null; | ||
return string.replace(regexShortname, _utils.shortnameToUnicode); | ||
}; | ||
var unicodeToShortnames = exports.unicodeToShortnames = function unicodeToShortnames(string) { | ||
exports.shortnamesToUnicode = shortnamesToUnicode; | ||
var unicodeToShortnames = function unicodeToShortnames(string) { | ||
if (typeof string !== 'string') return null; | ||
@@ -34,3 +57,5 @@ return string.replace(regexUnicode, _utils.unicodeToShortname); | ||
var renderShortname = exports.renderShortname = function renderShortname(string, settings) { | ||
exports.unicodeToShortnames = unicodeToShortnames; | ||
var renderShortname = function renderShortname(string, settings) { | ||
if (typeof string !== 'string') return null; | ||
@@ -40,9 +65,9 @@ var options = (0, _utils.getOptions)(settings); | ||
var compile = function compile(shortname) { | ||
var emoji = (0, _utils.shortnameToEmoji)(shortname); | ||
// do nothing if shortcode is not recognized | ||
var emoji = (0, _utils.shortnameToEmoji)(shortname); // do nothing if shortcode is not recognized | ||
if (!emoji) return shortname; | ||
return (0, _utils.hexToImage)(emoji.hex, options); | ||
}; | ||
}; // Trust string in "single character" mode | ||
// Trust string in "single character" mode | ||
if (options.single) return compile(string); | ||
@@ -52,3 +77,5 @@ return (0, _utils.sanitize)(string, options).replace(regexShortname, compile); | ||
var render = exports.render = function render(string, settings) { | ||
exports.renderShortname = renderShortname; | ||
var render = function render(string, settings) { | ||
if (typeof string !== 'string') return null; | ||
@@ -58,9 +85,9 @@ var options = (0, _utils.getOptions)(settings); | ||
var compile = function compile(unicode) { | ||
var emoji = (0, _utils.unicodeToEmoji)(unicode); | ||
// do nothing if unicode is not recognized | ||
var emoji = (0, _utils.unicodeToEmoji)(unicode); // do nothing if unicode is not recognized | ||
if (!emoji) return unicode; | ||
return (0, _utils.hexToImage)(emoji.hex, options); | ||
}; | ||
}; // Trust string in "single character" mode | ||
// Trust string in "single character" mode | ||
if (options.single) return compile(string); | ||
@@ -70,4 +97,2 @@ return (0, _utils.sanitize)(string, options).replace(regexUnicode, compile); | ||
exports.emojiCollection = _emojis.collection; | ||
exports.emojiRegex = _emojis.emojiRegex; | ||
exports.shortnameRegex = _emojis.shortnameRegex; | ||
exports.render = render; |
119
lib/utils.js
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,18 +6,15 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.hexToImage = exports.getImageSrc = exports.getOptions = exports.sanitize = exports.unicodeToShortname = exports.shortnameToUnicode = exports.shortnameToEmoji = exports.unicodeToEmoji = exports.codePointToUnicode = exports.fromCodePoint = exports.unicodeToCodePoint = exports.shortnamesHash = exports.codepointsHash = exports.hexToId = undefined; | ||
exports.hexToImage = exports.getImageSrc = exports.getOptions = exports.sanitize = exports.unicodeToShortname = exports.shortnameToUnicode = exports.shortnameToEmoji = exports.unicodeToEmoji = exports.codePointToUnicode = exports.fromCodePoint = exports.unicodeToCodePoint = exports.shortnamesHash = exports.codepointsHash = exports.hexToId = void 0; | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _escapeHtml = _interopRequireDefault(require("escape-html")); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _emojis = require("../vendor/emojis"); | ||
var _escapeHtml = require('escape-html'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _escapeHtml2 = _interopRequireDefault(_escapeHtml); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
var _emojis = require('../vendor/emojis'); | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* eslint no-bitwise: "off" */ | ||
var imagePath = '/images/emojis-v3.1.1'; | ||
var imagePath = '/images/emojis-v4.0.0'; | ||
var AVAILABLE_SIZES = { | ||
@@ -28,5 +25,3 @@ 32: true, | ||
}; | ||
var regexServiceChar = /(-fe0f|-fe0e|-200d)/g; | ||
var defaultOptions = { | ||
@@ -41,25 +36,31 @@ size: 64, | ||
if (string.length >= 4) return string; | ||
return ('000' + string).slice(-4); | ||
return "000".concat(string).slice(-4); | ||
}; | ||
var hexToId = exports.hexToId = function hexToId(hex) { | ||
var hexToId = function hexToId(hex) { | ||
return hex.replace(regexServiceChar, ''); | ||
}; | ||
var codepointsHash = exports.codepointsHash = _emojis.collection.reduce(function (acc, item) { | ||
exports.hexToId = hexToId; | ||
var codepointsHash = _emojis.collection.reduce(function (acc, item) { | ||
acc[hexToId(item.hex)] = item; | ||
return acc; | ||
}, {}); | ||
var shortnamesHash = exports.shortnamesHash = _emojis.collection.reduce(function (acc, item) { | ||
exports.codepointsHash = codepointsHash; | ||
var shortnamesHash = _emojis.collection.reduce(function (acc, item) { | ||
acc[item.shortname] = item; | ||
return acc; | ||
}, {}); | ||
// Converts unicode to a hex string. | ||
}, {}); // Converts unicode to a hex string. | ||
// A combination of fixed charCodeAt and converting number to base 16 | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt | ||
// https://github.com/twitter/twemoji/blob/gh-pages/twemoji-generator.js#L849 | ||
var unicodeToCodePoint = exports.unicodeToCodePoint = function unicodeToCodePoint(unicode) { | ||
exports.shortnamesHash = shortnamesHash; | ||
var unicodeToCodePoint = function unicodeToCodePoint(unicode) { | ||
var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '-'; | ||
var result = []; | ||
@@ -82,11 +83,12 @@ var pair = 0; | ||
return result.map(padLeft).join(separator); | ||
}; | ||
// Converts codepoint string to a unicode character | ||
}; // Converts codepoint string to a unicode character | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint | ||
// https://github.com/twitter/twemoji/blob/gh-pages/twemoji-generator.js#L807 | ||
var fromCodePoint = exports.fromCodePoint = function fromCodePoint(codepoint) { | ||
exports.unicodeToCodePoint = unicodeToCodePoint; | ||
var fromCodePoint = function fromCodePoint(codepoint) { | ||
var code = parseInt(codepoint, 16); | ||
if (code < 0x10000) return String.fromCharCode(code); | ||
var base = code - 0x10000; | ||
@@ -96,3 +98,5 @@ return String.fromCharCode(0xD800 + (base >> 10), 0xDC00 + (base & 0x3FF)); | ||
var codePointToUnicode = exports.codePointToUnicode = function codePointToUnicode(hex) { | ||
exports.fromCodePoint = fromCodePoint; | ||
var codePointToUnicode = function codePointToUnicode(hex) { | ||
return hex.split('-').map(function (point) { | ||
@@ -103,13 +107,19 @@ return fromCodePoint(point); | ||
var unicodeToEmoji = exports.unicodeToEmoji = function unicodeToEmoji(unicode) { | ||
exports.codePointToUnicode = codePointToUnicode; | ||
var unicodeToEmoji = function unicodeToEmoji(unicode) { | ||
return codepointsHash[hexToId(unicodeToCodePoint(unicode))]; | ||
}; | ||
var shortnameToEmoji = exports.shortnameToEmoji = function shortnameToEmoji(shortname) { | ||
exports.unicodeToEmoji = unicodeToEmoji; | ||
var shortnameToEmoji = function shortnameToEmoji(shortname) { | ||
return shortnamesHash[shortname]; | ||
}; | ||
var shortnameToUnicode = exports.shortnameToUnicode = function shortnameToUnicode(shortname) { | ||
var emoji = shortnamesHash[shortname]; | ||
exports.shortnameToEmoji = shortnameToEmoji; | ||
// do nothing if shortcode is not recognized | ||
var shortnameToUnicode = function shortnameToUnicode(shortname) { | ||
var emoji = shortnamesHash[shortname]; // do nothing if shortcode is not recognized | ||
if (!emoji) return shortname; | ||
@@ -119,6 +129,7 @@ return codePointToUnicode(emoji.hex); | ||
var unicodeToShortname = exports.unicodeToShortname = function unicodeToShortname(unicode) { | ||
var emoji = unicodeToEmoji(unicode); | ||
exports.shortnameToUnicode = shortnameToUnicode; | ||
// do nothing if unicode is not recognized | ||
var unicodeToShortname = function unicodeToShortname(unicode) { | ||
var emoji = unicodeToEmoji(unicode); // do nothing if unicode is not recognized | ||
if (!emoji) return unicode; | ||
@@ -128,10 +139,17 @@ return emoji.shortname; | ||
var sanitize = exports.sanitize = function sanitize(string, options) { | ||
return options && options.unsafe ? string : (0, _escapeHtml2.default)(string); | ||
exports.unicodeToShortname = unicodeToShortname; | ||
var sanitize = function sanitize(string, options) { | ||
return options && options.unsafe ? string : (0, _escapeHtml.default)(string); | ||
}; | ||
var getOptions = exports.getOptions = function getOptions(options) { | ||
return (0, _extends3.default)({}, defaultOptions, options); | ||
exports.sanitize = sanitize; | ||
var getOptions = function getOptions(options) { | ||
return _objectSpread({}, defaultOptions, options); | ||
}; | ||
var getImageSrc = exports.getImageSrc = function getImageSrc(icon, prefix) { | ||
exports.getOptions = getOptions; | ||
var getImageSrc = function getImageSrc(icon, prefix) { | ||
var cdn = prefix; | ||
@@ -141,9 +159,11 @@ | ||
var imageSize = AVAILABLE_SIZES[prefix] ? prefix : 64; | ||
cdn = imagePath + '/' + imageSize; | ||
cdn = "".concat(imagePath, "/").concat(imageSize); | ||
} | ||
return cdn + '/' + icon + '.png'; | ||
return "".concat(cdn, "/").concat(icon, ".png"); | ||
}; | ||
var hexToImage = exports.hexToImage = function hexToImage(hex) { | ||
exports.getImageSrc = getImageSrc; | ||
var hexToImage = function hexToImage(hex) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -153,10 +173,9 @@ var size = options.size, | ||
cdn = options.cdn; | ||
var src = getImageSrc(hexToId(hex), cdn || size); | ||
var alt = codePointToUnicode(hex); | ||
var propsString = "src=\"".concat(src, "\" alt=\"").concat(alt, "\" draggable=\"false\""); | ||
if (className) propsString += " class=\"".concat(className, "\""); | ||
return "<img ".concat(propsString, " />"); | ||
}; | ||
var propsString = 'src="' + src + '" alt="' + alt + '" draggable="false"'; | ||
if (className) propsString += ' class="' + className + '"'; | ||
return '<img ' + propsString + ' />'; | ||
}; | ||
exports.hexToImage = hexToImage; |
@@ -9,3 +9,3 @@ { | ||
"bugs": "https://github.com/good-hood-gmbh/emojitsu/issues", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"keywords": [ | ||
@@ -24,3 +24,4 @@ "emoji", | ||
"prepublishOnly": "npm run clean && npm run build:babel", | ||
"generate": "npm run build:babel && node run.js generate > ./vendor/emojis.json && echo 'Done!'", | ||
"generate": "npm run build:babel && node run.js generate", | ||
"start": "npm run build:babel && node preview.js", | ||
"lint": "eslint ./", | ||
@@ -32,18 +33,18 @@ "lint:tofile": "eslint --no-color -o ./eslint-report.log ./", | ||
"devDependencies": { | ||
"emojione-assets": "^3.1.1", | ||
"regexgen": "1.3.0", | ||
"lodash.uniq": "4.5.0", | ||
"superagent": "3.8.1", | ||
"babel-cli": "6.26.0", | ||
"babel-register": "6.26.0", | ||
"babel-preset-env": "1.6.1", | ||
"babel-preset-stage-3": "6.24.1", | ||
"babel-plugin-transform-runtime": "6.23.0", | ||
"babel-plugin-transform-node-env-inline": "0.2.0", | ||
"chalk": "2.3.0", | ||
"eslint": "4.12.1", | ||
"eslint-plugin-import": "2.8.0", | ||
"eslint-config-airbnb-base": "12.1.0", | ||
"mocha": "4.0.1", | ||
"chai": "4.1.2" | ||
"@babel/cli": "^7.1.0", | ||
"@babel/core": "^7.1.0", | ||
"@babel/plugin-proposal-json-strings": "^7.0.0", | ||
"@babel/plugin-transform-strict-mode": "^7.0.0", | ||
"@babel/preset-env": "^7.1.0", | ||
"chai": "^4.1.2", | ||
"chalk": "^2.4.1", | ||
"emojione-assets": "4.0.0", | ||
"eslint": "^5.6.0", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"express": "^4.16.3", | ||
"lodash.uniq": "^4.5.0", | ||
"mocha": "^5.2.0", | ||
"regexgen": "^1.3.0", | ||
"request": "^2.88.0" | ||
}, | ||
@@ -50,0 +51,0 @@ "dependencies": { |
@@ -6,2 +6,6 @@ Emojitsu | ||
## Unicode version | ||
Currently supported Unicode version: `11.0`. Minimum supported `emojione-assets` version: `4.0.0`. | ||
## Usage: | ||
@@ -59,2 +63,2 @@ | ||
By default the path to emoji images is constructed like this: `/images/emojis-v${version}/${size}`. `version` is the https://github.com/emojione/emojione-assets version used to generate the emojis.json file and `size` is the asset size (32/64/128). Example output: `/images/emojis-v3.1.1/64/1f603.png`. When `cdn` option is specified, it will be used instead. When just a `size` is specified, default path will be used with `size` being replaced by the one provided in options. | ||
By default the path to emoji images is constructed like this: `/images/emojis-v${version}/${size}`. `version` is the https://github.com/emojione/emojione-assets version used to generate the emojis.json file and `size` is the asset size (32/64/128). Example output: `/images/emojis-v4.0.0/64/1f603.png`. When `cdn` option is specified, it will be used instead. When just a `size` is specified, default path will be used with `size` being replaced by the one provided in options. |
Sorry, the diff of this file is too big to display
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
400565
17217
63
1