Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

interweave-emoji

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interweave-emoji - npm Package Compare versions

Comparing version 2.0.0-0 to 2.0.0-1

14

lib/Emoji.d.ts

@@ -0,1 +1,5 @@

/**
* @copyright 2016-2018, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
import React from 'react';

@@ -6,11 +10,21 @@ import PropTypes from 'prop-types';

export interface EmojiProps {
/** Size of the emoji when it's enlarged. */
emojiLargeSize?: Size;
/** Path to an SVG/PNG. Accepts a string or a callback that is passed the hexcode. */
emojiPath?: Path;
/** Size of the emoji. Defaults to 1em. */
emojiSize?: Size;
/** Datasource metadata. */
emojiSource: Source;
/** Emoticon to reference emoji from. */
emoticon?: Emoticon;
/** Enlarge emoji increasing it's size. */
enlargeEmoji?: boolean;
/** Hexcode to reference emoji from. */
hexcode?: Hexcode;
/** Render literal unicode character instead of an SVG/PNG. */
renderUnicode?: boolean;
/** Shortcode to reference emoji from. */
shortcode?: Shortcode;
/** Unicode character to reference emoji from. */
unicode?: Unicode;

@@ -17,0 +31,0 @@ }

15

lib/Emoji.js
"use strict";
/**
* @copyright 2016-2018, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
var __extends = (this && this.__extends) || (function () {

@@ -16,2 +20,3 @@ var extendStatics = Object.setPrototypeOf ||

Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable complexity, react/no-unused-prop-types */
var react_1 = __importDefault(require("react"));

@@ -21,3 +26,3 @@ var prop_types_1 = __importDefault(require("prop-types"));

var shapes_1 = require("./shapes");
var Emoji = (function (_super) {
var Emoji = /** @class */ (function (_super) {
__extends(Emoji, _super);

@@ -36,2 +41,3 @@ function Emoji() {

}
// Retrieve applicable unicode character
if (!hexcode && shortcode) {

@@ -46,2 +52,3 @@ hexcode = data.SHORTCODE_TO_HEXCODE[shortcode];

}
// Return the invalid value instead of erroring
if (!hexcode || !data.EMOJIS[hexcode]) {

@@ -58,5 +65,7 @@ return react_1.default.createElement("span", null, unicode || emoticon || shortcode || hexcode);

};
// Handle large styles
if (enlargeEmoji && emojiLargeSize) {
styles.width = emojiLargeSize;
styles.height = emojiLargeSize;
// Only apply styles if a size is defined
}

@@ -67,2 +76,3 @@ else if (emojiSize) {

}
// Determine the path
var path = emojiPath || '{{hexcode}}';

@@ -75,2 +85,5 @@ if (typeof path === 'function') {

}
// http://git.emojione.com/demos/latest/sprites-png.html
// http://git.emojione.com/demos/latest/sprites-svg.html
// https://css-tricks.com/using-svg/
return (react_1.default.createElement("img", { src: path, alt: emoji.unicode, title: emoji.annotation || '', style: styles, "aria-label": emoji.annotation || '', "data-emoticon": emoji.emoticon || '', "data-unicode": emoji.unicode, "data-hexcode": emoji.hexcode, "data-shortcodes": emoji.canonical_shortcodes.join(', ') }));

@@ -77,0 +90,0 @@ };

@@ -0,1 +1,5 @@

/**
* @copyright 2016-2018, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
import { Emoji, Hexcode } from 'emojibase';

@@ -20,7 +24,23 @@ import { CanonicalEmoji } from './types';

constructor(locale?: string);
/**
* Return or create a singleton instance per locale.
*/
static getInstance(locale?: string): EmojiDataManager;
/**
* Return dataset as a list.
*/
getData(): CanonicalEmoji[];
/**
* Return dataset as a flattened list.
*/
getFlatData(): CanonicalEmoji[];
/**
* Package the emoji object with additional data,
* while also extracting and partitioning relevant information.
*/
packageEmoji(baseEmoji: Emoji): CanonicalEmoji;
/**
* Parse and generate emoji datasets.
*/
parseEmojiData(data: Emoji[]): CanonicalEmoji[];
}
"use strict";
/**
* @copyright 2016-2018, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
var __assign = (this && this.__assign) || Object.assign || function(t) {

@@ -13,3 +17,3 @@ for (var s, i = 1, n = arguments.length; i < n; i++) {

var instances = {};
var EmojiDataManager = (function () {
var EmojiDataManager = /** @class */ (function () {
function EmojiDataManager(locale) {

@@ -26,2 +30,5 @@ if (locale === void 0) { locale = 'en'; }

}
/**
* Return or create a singleton instance per locale.
*/
EmojiDataManager.getInstance = function (locale) {

@@ -34,8 +41,18 @@ if (locale === void 0) { locale = 'en'; }

};
/**
* Return dataset as a list.
*/
EmojiDataManager.prototype.getData = function () {
return this.data;
};
/**
* Return dataset as a flattened list.
*/
EmojiDataManager.prototype.getFlatData = function () {
return this.flatData;
};
/**
* Package the emoji object with additional data,
* while also extracting and partitioning relevant information.
*/
EmojiDataManager.prototype.packageEmoji = function (baseEmoji) {

@@ -45,10 +62,14 @@ var _this = this;

var emoji = __assign({}, baseEmoji, { canonical_shortcodes: [], primary_shortcode: '', skins: baseEmoji.skins });
// Make our lives easier
if (!emoji.unicode) {
emoji.unicode = emoji.text && emoji.type === emojibase_1.TEXT ? emoji.text : emoji.emoji;
}
// Canonicalize the shortcodes for easy reuse
emoji.canonical_shortcodes = shortcodes.map(function (code) { return ":" + code + ":"; });
emoji.primary_shortcode = emoji.canonical_shortcodes[0];
emoji.primary_shortcode = emoji.canonical_shortcodes[0]; // eslint-disable-line
// Support all shortcodes
emoji.canonical_shortcodes.forEach(function (shortcode) {
_this.SHORTCODE_TO_HEXCODE[shortcode] = hexcode;
});
// Support all emoticons
if (emoticon) {

@@ -59,2 +80,3 @@ emojibase_1.generateEmoticonPermutations(emoticon, emojibase_1.EMOTICON_OPTIONS[emoticon]).forEach(function (emo) {

}
// Support all presentations (even no variation selectors)
this.UNICODE_TO_HEXCODE[emojibase_1.fromCodepointToUnicode(emojibase_1.fromHexcodeToCodepoint(hexcode))] = hexcode;

@@ -67,5 +89,9 @@ if (emoji.emoji) {

}
// Map each emoji
this.EMOJIS[hexcode] = emoji;
return emoji;
};
/**
* Parse and generate emoji datasets.
*/
EmojiDataManager.prototype.parseEmojiData = function (data) {

@@ -77,2 +103,3 @@ var _this = this;

_this.flatData.push(packagedEmoji);
// Flatten and package skins as well
if (packagedEmoji.skins) {

@@ -79,0 +106,0 @@ packagedEmoji.skins.forEach(function (skin) {

@@ -0,1 +1,5 @@

/**
* @copyright 2016-2018, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
import React from 'react';

@@ -23,4 +27,10 @@ import { Matcher, MatcherFactory, MatchResponse, Props } from 'interweave';

matchUnicode(string: string): MatchResponse | null;
/**
* Load emoji data before matching.
*/
onBeforeParse(content: string, props: Props): string;
/**
* When a single `Emoji` is the only content, enlarge it!
*/
onAfterParse(content: React.ReactNode[], props: Props): React.ReactNode[];
}
"use strict";
/**
* @copyright 2016-2018, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
var __extends = (this && this.__extends) || (function () {

@@ -31,4 +35,6 @@ var extendStatics = Object.setPrototypeOf ||

var EmojiDataManager_1 = __importDefault(require("./EmojiDataManager"));
var EMOTICON_BOUNDARY_REGEX = new RegExp("(^|\\\b|\\s)(" + emoticon_1.default.source + ")(?=\\s|\\\b|$)");
var EmojiMatcher = (function (_super) {
var EMOTICON_BOUNDARY_REGEX = new RegExp(
// eslint-disable-next-line no-useless-escape
"(^|\\\b|\\s)(" + emoticon_1.default.source + ")(?=\\s|\\\b|$)");
var EmojiMatcher = /** @class */ (function (_super) {
__extends(EmojiMatcher, _super);

@@ -54,8 +60,11 @@ function EmojiMatcher(name, options, factory) {

var response = null;
// Should we convert emoticons to unicode?
if (this.options.convertEmoticon) {
matchers.push(this.matchEmoticon);
}
// Should we convert shortcodes to unicode?
if (this.options.convertShortcode) {
matchers.push(this.matchShortcode);
}
// Should we convert unicode to SVG/PNG?
if (this.options.convertUnicode) {

@@ -79,3 +88,3 @@ matchers.push(this.matchUnicode);

response.hexcode = this.data.EMOTICON_TO_HEXCODE[response.emoticon];
response.match = response.emoticon;
response.match = response.emoticon; // Remove padding
return response;

@@ -111,2 +120,5 @@ }

};
/**
* Load emoji data before matching.
*/
EmojiMatcher.prototype.onBeforeParse = function (content, props) {

@@ -121,2 +133,5 @@ if (props.emojiSource) {

};
/**
* When a single `Emoji` is the only content, enlarge it!
*/
EmojiMatcher.prototype.onAfterParse = function (content, props) {

@@ -129,5 +144,7 @@ if (content.length === 0) {

var count = 0;
// Use a for-loop, as it's much cleaner than some()
for (var i = 0, item = null; i < content.length; i += 1) {
item = content[i];
if (typeof item === 'string') {
// Allow whitespace but disallow strings
if (!item.match(/^\s+$/)) {

@@ -139,2 +156,4 @@ valid = false;

else if (react_1.default.isValidElement(item)) {
// Only count towards emojis
// @ts-ignore
if (item && item.type === Emoji_1.default) {

@@ -147,2 +166,3 @@ count += 1;

}
// Abort early for non-emoji components
}

@@ -149,0 +169,0 @@ else {

8

lib/index.d.ts

@@ -0,8 +1,12 @@

/**
* @copyright 2016-2018, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
import Emoji, { EmojiProps } from './Emoji';
import EmojiDataManager from './EmojiDataManager';
import EmojiMatcher, { EmojiMatcherOptions } from './EmojiMatcher';
import withEmojiData, { EmojiDataInternalProps, EmojiDataProps } from './withEmojiData';
export { EmojiProps, EmojiMatcher, EmojiMatcherOptions, EmojiDataManager, EmojiDataInternalProps, EmojiDataProps, withEmojiData, };
import withEmojiData, { EmojiDataWrapperProps, EmojiDataProps } from './withEmojiData';
export { EmojiProps, EmojiMatcher, EmojiMatcherOptions, EmojiDataManager, EmojiDataWrapperProps, EmojiDataProps, withEmojiData, };
export * from './shapes';
export * from './types';
export default Emoji;
"use strict";
/**
* @copyright 2016-2018, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
function __export(m) {

@@ -3,0 +7,0 @@ for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];

@@ -0,1 +1,5 @@

/**
* @copyright 2016-2018, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
import PropTypes from 'prop-types';

@@ -2,0 +6,0 @@ export declare const EmojiShape: PropTypes.Requireable<any>;

"use strict";
/**
* @copyright 2016-2018, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -3,0 +7,0 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

@@ -0,1 +1,5 @@

/**
* @copyright 2016-2018, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
import { Emoji, Hexcode, Shortcode } from 'emojibase';

@@ -2,0 +6,0 @@ export interface CanonicalEmoji extends Emoji {

"use strict";
/**
* @copyright 2016-2018, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
Object.defineProperty(exports, "__esModule", { value: true });

@@ -0,1 +1,5 @@

/**
* @copyright 2016-2018, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
import React from 'react';

@@ -6,11 +10,18 @@ import PropTypes from 'prop-types';

import { CanonicalEmoji, Source } from './types';
export interface EmojiDataInternalProps {
export interface EmojiDataWrapperProps {
/** Load compact dataset instead of full dataset. */
compact?: boolean;
/** List of emojis to manually use. */
emojis?: Emoji[];
/** Locale to load emoji annotations in. */
locale?: string;
/** Emojibase version to load. */
version?: string;
}
export interface EmojiDataProps {
/** List of loaded emojis provided by `withEmojiData`. */
emojis: CanonicalEmoji[];
/** Data manager and loader instance provided by `withEmojiData`. */
emojiData: EmojiDataManager;
/** Datasource metadata provided by `withEmojiData`. */
emojiSource: Source;

@@ -24,3 +35,3 @@ }

export default function withEmojiData<T extends {}>(Component: React.ComponentType<T & EmojiDataProps>): {
new (props: T & EmojiDataInternalProps, context?: any): {
new (props: T & EmojiDataWrapperProps, context?: any): {
state: {

@@ -35,12 +46,25 @@ emojis: never[];

componentDidMount(): void;
componentDidUpdate(prevProps: EmojiDataInternalProps): void;
componentDidUpdate(prevProps: EmojiDataWrapperProps): void;
/**
* Create or return the data instance.
*/
getDataInstance(): EmojiDataManager;
/**
* Set a list of emojis. If a list of custom emoji data has been passed,
* use it instead of the parsed data.
*/
setEmojis(emojis?: Emoji[]): void;
/**
* Load and parse emoji data from the CDN or use the provided dataset.
*/
loadEmojis(): void;
/**
* Clone the element so that it re-renders itself.
*/
render(): JSX.Element | null;
setState<K extends "source" | "emojis">(state: EmojiDataState | ((prevState: Readonly<EmojiDataState>, props: T & EmojiDataInternalProps) => EmojiDataState | Pick<EmojiDataState, K> | null) | Pick<EmojiDataState, K> | null, callback?: (() => void) | undefined): void;
setState<K extends "source" | "emojis">(state: EmojiDataState | ((prevState: Readonly<EmojiDataState>, props: T & EmojiDataWrapperProps) => EmojiDataState | Pick<EmojiDataState, K> | null) | Pick<EmojiDataState, K> | null, callback?: (() => void) | undefined): void;
forceUpdate(callBack?: (() => void) | undefined): void;
props: Readonly<{
children?: React.ReactNode;
}> & Readonly<T & EmojiDataInternalProps>;
}> & Readonly<T & EmojiDataWrapperProps>;
context: any;

@@ -47,0 +71,0 @@ refs: {

"use strict";
/**
* @copyright 2016-2018, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
var __extends = (this && this.__extends) || (function () {

@@ -33,2 +37,3 @@ var extendStatics = Object.setPrototypeOf ||

Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable promise/always-return */
var react_1 = __importDefault(require("react"));

@@ -40,2 +45,3 @@ var prop_types_1 = __importDefault(require("prop-types"));

var shapes_1 = require("./shapes");
// Share between all instances
var loaded = {};

@@ -52,3 +58,3 @@ var promise = {};

var _a;
return _a = (function (_super) {
return _a = /** @class */ (function (_super) {
__extends(EmojiData, _super);

@@ -79,5 +85,12 @@ function EmojiData() {

};
/**
* Create or return the data instance.
*/
EmojiData.prototype.getDataInstance = function () {
return EmojiDataManager_1.default.getInstance(this.props.locale);
};
/**
* Set a list of emojis. If a list of custom emoji data has been passed,
* use it instead of the parsed data.
*/
EmojiData.prototype.setEmojis = function (emojis) {

@@ -95,7 +108,12 @@ if (emojis === void 0) { emojis = []; }

};
/**
* Load and parse emoji data from the CDN or use the provided dataset.
*/
EmojiData.prototype.loadEmojis = function () {
var _this = this;
var _a = this.props, compact = _a.compact, emojis = _a.emojis, locale = _a.locale, version = _a.version;
// Abort as we've already loaded data
if (loaded[locale]) {
this.setEmojis(emojis);
// Or hook into the promise if we're loading
}

@@ -110,2 +128,3 @@ else if (promise[locale]) {

});
// Otherwise, start loading emoji data from the CDN
}

@@ -116,2 +135,4 @@ else {

loaded[locale] = true;
// Parse the data and make it available through our data layer.
// We should do this first so that the custom emojis can hook into it.
_this.getDataInstance().parseEmojiData(response);

@@ -126,3 +147,7 @@ _this.setEmojis(emojis);

};
/**
* Clone the element so that it re-renders itself.
*/
EmojiData.prototype.render = function () {
// @ts-ignore
var _a = this.props, compact = _a.compact, emojis = _a.emojis, locale = _a.locale, version = _a.version, props = __rest(_a, ["compact", "emojis", "locale", "version"]);

@@ -129,0 +154,0 @@ if (this.state.emojis.length === 0) {

{
"name": "interweave-emoji",
"version": "2.0.0-0",
"version": "2.0.0-1",
"description": "Emoji support for Interweave.",

@@ -30,5 +30,5 @@ "keywords": [

"emojibase": "^1.7.1",
"interweave": "^9.0.0-0",
"interweave": "^9.0.0-1",
"react": "^16.4.0"
}
}

@@ -15,3 +15,3 @@ {

"pretty": true,
"removeComments": true,
"removeComments": false,
"sourceMap": false,

@@ -18,0 +18,0 @@ "strict": true,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc