Skip to content

Commit

Permalink
Export platform-specific symbol sets (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richienb authored Feb 16, 2020
1 parent 293a4e5 commit f1ad9fe
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 33 deletions.
56 changes: 33 additions & 23 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
declare const figures: {
/**
Replace unicode symbols depending on the OS.
@param string - String where the Unicode symbols will be replaced with fallback symbols depending on the OS.
@returns The input with replaced fallback Unicode symbols on Windows.
@example
```
import figures = require('figures');
console.log(figures('✔︎ check'));
// On real OSes: ✔︎ check
// On Windows: √ check
console.log(figures.tick);
// On real OSes: ✔︎
// On Windows: √
```
*/
(string: string): string;

declare const figureSet: {
readonly tick: string;
readonly cross: string;
readonly star: string;
Expand Down Expand Up @@ -77,6 +56,37 @@ declare const figures: {
readonly fiveSixths: string;
readonly fiveEighths: string;
readonly sevenEighth: string;
};
}

type FigureSet = typeof figureSet

declare const figures: {
/**
Replace unicode symbols depending on the OS.
@param string - String where the Unicode symbols will be replaced with fallback symbols depending on the OS.
@returns The input with replaced fallback Unicode symbols on Windows.
@example
```
import figures = require('figures');
console.log(figures('✔︎ check'));
// On real OSes: ✔︎ check
// On Windows: √ check
console.log(figures.tick);
// On real OSes: ✔︎
// On Windows: √
```
*/
(string: string): string;

/** Figures to use when not running on Windows. */
readonly main: FigureSet;

/** Figures to use when running on Windows. */
readonly windows: FigureSet;
} & FigureSet;

export = figures;
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,5 @@ const fn = string => {
};

module.exports = Object.assign(fn, figures);
module.exports.main = main;
module.exports.windows = windows;
10 changes: 1 addition & 9 deletions makefile.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const importFresh = require('import-fresh');
const table = require('markdown-table');

const load = value => {
Object.defineProperty(process, 'platform', {value});
return importFresh('.');
};

const darwin = load('darwin');
const win32 = load('win32');
const {main: darwin, windows: win32} = require('.');

const data = Object.entries(darwin).map(([name, figure]) => [name, figure, win32[name]]);

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
},
"devDependencies": {
"ava": "^1.4.1",
"import-fresh": "^3.0.0",
"markdown-table": "^1.1.2",
"tsd": "^0.7.2",
"xo": "^0.24.0"
Expand Down
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ console.log(figures('✔︎ check'));
console.log(figures.tick);
// On real OSes: ✔︎
// On Windows: √

console.log(figures.main.tick);
// On all OSes: ✔︎

console.log(figures.windows.tick);
// On all OSes: √
```


Expand All @@ -48,6 +54,16 @@ Type: `string`
String where the Unicode symbols will be replaced with fallback symbols depending on the OS.


### figures.main

Figures to use when not running on Windows.


### figures.windows

Figures to use when running on Windows.


## Figures

| Name | Real OSes | Windows |
Expand Down
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ test('fallbacks', t => {
t.is(figures('✔ ✖\n★ ▇'), result('✔ ✖\n★ ▇', '√ ×\n* █'));
t.is(figures('✔ ✖ ★ ▇'), result('✔ ✖ ★ ▇', '√ × * █'));
});

test('exported sets', t => {
t.is(figures.main.tick, '✔');
t.is(figures.windows.tick, '√');
});

0 comments on commit f1ad9fe

Please sign in to comment.