Skip to content

Commit

Permalink
Make it tree-shakeable (#35)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
ryoppippi and sindresorhus authored Aug 17, 2024
1 parent ab7ca3d commit 1eeaa5a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 29 deletions.
4 changes: 4 additions & 0 deletions browser-symbols.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const info = 'ℹ️';
export const success = '✅';
export const warning = '⚠️';
export const error = '❌️';
9 changes: 1 addition & 8 deletions browser.js
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
const logSymbols = {
info: 'ℹ️',
success: '✅',
warning: '⚠️',
error: '❌️',
};

export default logSymbols;
export * as default from './browser-symbols.js';
21 changes: 1 addition & 20 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
import {blue, green, yellow, red} from 'yoctocolors';
import isUnicodeSupported from 'is-unicode-supported';

const main = {
info: blue('ℹ'),
success: green('✔'),
warning: yellow('⚠'),
error: red('✖'),
};

const fallback = {
info: blue('i'),
success: green('√'),
warning: yellow('‼'),
error: red('×'),
};

const logSymbols = isUnicodeSupported() ? main : fallback;

export default logSymbols;
export * as default from './symbols.js';
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"files": [
"index.js",
"index.d.ts",
"browser.js"
"browser.js",
"symbols.js",
"browser-symbols.js"
],
"keywords": [
"unicode",
Expand Down
9 changes: 9 additions & 0 deletions symbols.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {blue, green, yellow, red} from 'yoctocolors';
import isUnicodeSupported from 'is-unicode-supported';

const _isUnicodeSupported = isUnicodeSupported();

export const info = blue(_isUnicodeSupported ? 'ℹ' : 'i');
export const success = green(_isUnicodeSupported ? '✔' : '√');
export const warning = yellow(_isUnicodeSupported ? '⚠' : '‼');
export const error = red(_isUnicodeSupported ? '✖️' : '×');

0 comments on commit 1eeaa5a

Please sign in to comment.