-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from mikemcbride/two-point-oh
2.0
- Loading branch information
Showing
14 changed files
with
19,479 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,42 @@ | ||
#!/usr/bin/env node | ||
'use strict' | ||
const React = require('react') | ||
const importJsx = require('import-jsx') | ||
const {render} = require('ink') | ||
const meow = require('meow') | ||
const rgbHex = require('rgb-hex') | ||
const hexRgb = require('hex-rgb') | ||
const clipboardy = require('clipboardy') | ||
const chalk = require('chalk') | ||
|
||
function isHex(str) { | ||
// optional # at beginning | ||
// matches a-f, A-F, 0-9 exactly 8, 6, or 3 times | ||
let hexRegex = /^#?([0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/ | ||
return hexRegex.test(str) | ||
} | ||
|
||
const ui = importJsx('./ui') | ||
|
||
const cli = meow(` | ||
Examples | ||
# rgb to hex | ||
$ convert-color 255 154 253 | ||
ff9afd | ||
# rgb | ||
$ convert-color 'rgb(40, 42, 54)' | ||
282a36 | ||
# alpha values can be % or decimal | ||
$ convert-color 'rgba(40, 42, 54, 75%)' | ||
282a36bf | ||
$ convert-color 'rgba(40, 42, 54, 0.75)' | ||
282a36bf | ||
# hex to rgb | ||
# hex | ||
$ convert-color ff9afd | ||
rgb(255, 154, 253) | ||
# can have a pound sign at beginning | ||
$ convert-color '#282a36' | ||
rgb(40, 42, 54) | ||
# works with 8 digit hex codes | ||
# works with 8 digit hex codes (opacity) | ||
$ convert-color 282a36bf | ||
rgba(40, 42, 54, 0.75) | ||
# hsl | ||
$ convert-color 'hsl(336, 100%, 50%)' | ||
# alpha values can be % or decimal | ||
$ convert-color 'hsla(336, 100%, 50%, 75%)' | ||
$ convert-color 'hsla(336, 100%, 50%, 0.75)' | ||
# you can also omit a color and input it using the interactive input | ||
$ convert-color | ||
Enter the color you want to convert: | ||
`) | ||
|
||
const val = cli.input.join(' ') | ||
let convertedValue = '' | ||
|
||
if (isHex(val)) { | ||
let { red, green, blue, alpha } = hexRgb(val) | ||
if (alpha !== 1) { | ||
alpha = parseFloat(alpha).toFixed(2) | ||
if (alpha.endsWith(0)) { | ||
alpha = parseFloat(alpha).toFixed(1) | ||
} | ||
|
||
convertedValue =`rgba(${red}, ${green}, ${blue}, ${alpha})` | ||
} else { | ||
convertedValue = `rgb(${red}, ${green}, ${blue})` | ||
} | ||
} else { | ||
convertedValue = rgbHex(val) | ||
} | ||
|
||
clipboardy.writeSync(convertedValue) | ||
|
||
console.log(chalk.green(`${convertedValue} (copied to clipboard)`)) | ||
|
||
const initialColor = cli.input.length === 0 ? null : cli.input.join(' ') | ||
module.exports = render(React.createElement(ui, { color: initialColor })) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const React = require('react') | ||
const { Box, Text } = require('ink') | ||
const { UncontrolledTextInput } = require('ink-text-input') | ||
|
||
const InputColor = (props) => ( | ||
<Box> | ||
<Box marginRight={1}> | ||
<Text>Enter the color you want to convert:</Text> | ||
</Box> | ||
<UncontrolledTextInput onSubmit={props.onInputChange} /> | ||
</Box> | ||
) | ||
|
||
module.exports = InputColor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const React = require('react') | ||
const { Box, Color, Text } = require('ink') | ||
const { default: SelectInput } = require('ink-select-input') | ||
|
||
const SelectFormat = (props) => ( | ||
<Box flexDirection="column"> | ||
<Box marginBottom={1}> | ||
<Text>Convert <Color green>{props.color}</Color> to which format:</Text> | ||
</Box> | ||
|
||
<SelectInput items={props.conversionItems} onSelect={props.onFormatSelect} /> | ||
</Box> | ||
) | ||
|
||
module.exports = SelectFormat |
Oops, something went wrong.