Skip to content

Commit

Permalink
Use jsDelivr instead of MaxCDN
Browse files Browse the repository at this point in the history
  • Loading branch information
Justine De Caires committed Jan 12, 2023
1 parent b8dc232 commit cc4e0ca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,43 @@ A simple library for identifying emoji entities within a string in order to rend
For example, this parser is used within the rendering flow for Tweets and other text on [mobile.twitter.com](https://mobile.twitter.com)

## Setup

Add `twemoji-parser` as a dependency to your project:

```
yarn add twemoji-parser
```

Or, to work directly in this repo, clone it and run `yarn install` from the repo root.

## Usage

The [tests](src/__tests__/index.test.js) are intended to serve as a more exhaustive source of documentation, but the general idea is that the parser takes a string and returns an array of the emoji entities it finds:

```js
import { parse } from 'twemoji-parser';
const entities = parse('I 🧡 Twemoji! 🥳');
/*
entities = [
{
url: 'https://twemoji.maxcdn.com/v/latest/svg/1f9e1.svg',
url: 'https://cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets/svg/1f9e1.svg',
indices: [ 2, 4 ],
text: '🧡',
type: 'emoji'
},
{
url: 'https://twemoji.maxcdn.com/v/latest/svg/1f973.svg',
url: 'https://cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets/svg/1f973.svg',
indices: [ 12, 14 ],
text: '🥳',
type: 'emoji'
}
]
*/
```

## Authors

* Nathan Downs <ndowns [at] twitter [dot] com>
- Nathan Downs <ndowns [at] twitter [dot] com>

Follow [@TwitterOSS](https://twitter.com/twitteross) on Twitter for updates.

Expand All @@ -51,6 +56,7 @@ in all interactions with the community.
Create a [new issue](https://github.com/twitter/twemoji-parser/issues/new) on GitHub.

## Security Issues?

Please report sensitive security issues via Twitter's bug-bounty program (https://hackerone.com/twitter) rather than GitHub.

## License
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,26 @@ describe('parse', () => {
});

describe('URLs', () => {
test('use MaxCDN SVGs by default', () => {
test('use jsDelivr SVGs by default', () => {
expect(parse('I \u2764 emoji!')).toMatchObject([
{
url: 'https://twemoji.maxcdn.com/v/latest/svg/2764.svg'
url: 'https://cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets/svg/2764.svg'
}
]);
});

test('can ask for MaxCDN PNGs', () => {
test('can ask for jsDelivr PNGs', () => {
expect(parse('I \u2764 emoji!', { assetType: 'png' })).toMatchObject([
{
url: 'https://twemoji.maxcdn.com/v/latest/72x72/2764.png'
url: 'https://cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets/72x72/2764.png'
}
]);
});

test('non-png assetType defaults back to SVG', () => {
expect(parse('I \u2764 emoji!', { assetType: 'foobar' })).toMatchObject([
{
url: 'https://twemoji.maxcdn.com/v/latest/svg/2764.svg'
url: 'https://cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets/svg/2764.svg'
}
]);
});
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function parse(text: string, options?: ParsingOptions): Array<EmojiEntity
? options.buildUrl
: (codepoints, assetType) =>
assetType === 'png'
? `https://twemoji.maxcdn.com/v/latest/72x72/${codepoints}.png`
: `https://twemoji.maxcdn.com/v/latest/svg/${codepoints}.svg`;
? `https://cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets/72x72/${codepoints}.png`
: `https://cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets/svg/${codepoints}.svg`;

const entities = [];

Expand Down

0 comments on commit cc4e0ca

Please sign in to comment.