Skip to content

Commit

Permalink
Update and polish
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkGriffiths committed Feb 14, 2019
1 parent f8b0b1f commit 8e14be5
Show file tree
Hide file tree
Showing 8 changed files with 6,341 additions and 10,293 deletions.
17 changes: 5 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
---
branches:
only:
- master
- develop
- /^greenkeeper/.*$/
- master
- develop
- /^greenkeeper/.*$/
- /^feature/.*$/
language: node_js
node_js:
- stable
= 10
- 9
- 8
sudo: false
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/d0418713e51ac049564a
on_success: always
on_failure: change
on_start: never
env:
global:
- CC_TEST_REPORTER_ID=f017a295c85532d945c74fe17b7f45c516ff72ef478548a99b165927aaa321d7
- secure: k+PXexJeDTne3XBzuDa59S3V7lvZ1hXoivoD3AkSM30WXRFVhqvreCkpcrKcwLWD6DTJA7DYy2eQE26V4Q2NVIPSHo4cMhVKX4v6a4JITN8UCWKqa9oaDE4OuHWymVXcuS1FRDUJQEy59oRb1zM37f+3bfOEoEupgg4IDBErxiaWyLZV3d8f5mVNkZC2nhvXdfla/KNeJxCIBk8bzR9yCPgra8frwzGb0ZQazZfyy31D3JkHYNeJfIp/4ncXLiracUxzLLAevW0sb4RI3oP3KX8UKs//uT0ipjQnSqPQFM1gewDUPelk6XvI/glw6G1+nttqcyxj+LO6mlpJGXtcyNP2qziU86n2UYsxaocEtvcK4U7lKyo5tnrJr/WunZZ1k0H8YHASkHdKsef5m+lhlrKvk9ebMZER96bE1+p7gNSo9ghGNS+JSelVqs9hqNMFAAdiT8Y3Q5li5Yg81BNbLOXTYwFlXt1OKPrC2Ie3kKw/kbcYIhn9bofmsCHI2naULquISoEW94cqycpZzPfRmoWXOVqXM+jyWdQ/w1tEFuthYIiYJG1YIoptuW2ZIR6kIt8bLe6ZKCotkIfUY8fnENIq/VuNhIZWzHt5rtnqeP0XiH2aPGFXmAVGylVbUZLifQa8mS6CQiR9CTD7bOy5/odFtKrqGD1IN/QxpaLoa1I=
before_install:
- '[[ $(node -v) =~ ^v10.*$ ]] || npm install -g npm@latest'
- npm install -g greenkeeper-lockfile
Expand Down
12 changes: 6 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const gulp = require('gulp')
const rename = require('gulp-rename')
const strip = require('gulp-strip-comments')
const rollup = require('gulp-better-rollup')
const resolve = require('rollup-plugin-node-resolve')
const commonjs = require('rollup-plugin-commonjs')
const babel = require('rollup-plugin-babel')

const external = ['assert', 'color-convert']
const external = id => !id.startsWith('.') && !id.startsWith('/') && !id.startsWith('\0')

const babelConfig = {
presets: [
Expand All @@ -15,30 +16,29 @@ const babelConfig = {
}
}]
],
comments: false,
exclude: 'node_modules/**'
}

gulp.task('cjs', () =>
gulp.src('src/index.js')
.pipe(rollup({
external,
plugins: [babel(babelConfig)]
plugins: [resolve(), commonjs(), babel(babelConfig)]
}, {
format: 'cjs'
}))
.pipe(strip())
.pipe(gulp.dest('.'))
)

gulp.task('es6', () =>
gulp.src('src/index.js')
.pipe(rollup({
external,
plugins: [babel(babelConfig)]
plugins: [resolve(), commonjs(), babel(babelConfig)]
}, {
format: 'es'
}))
.pipe(strip())
.pipe(rename('index.mjs'))
.pipe(gulp.dest('.'))
)
Expand Down
16 changes: 0 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const _styles = {
underline: [4, 24],
blink: [5, 25],
invert: [7, 27]

};

function parseColor(color_, depth_, bg_) {
Expand Down Expand Up @@ -67,7 +66,6 @@ function parseColor(color_, depth_, bg_) {
}
})(),
out: bg_ ? _SGRparts.bg[1] : _SGRparts.fg[1]

};
return {
in: `${mode.in}${color}`,
Expand All @@ -76,7 +74,6 @@ function parseColor(color_, depth_, bg_) {
})();
}


function parseStyles(styles_) {
const styles = {
background: false,
Expand Down Expand Up @@ -108,7 +105,6 @@ function parseStyles(styles_) {
}
}


function setStyles(styles, excluded_) {
const excluded = excluded_ === undefined ? {} : excluded_;
const sgrIn = [];
Expand All @@ -130,7 +126,6 @@ function setStyles(styles, excluded_) {
};
}


class SGRcomposer {
constructor(targetDepth, styles) {
this._depth = (depth_ => {
Expand All @@ -156,37 +151,30 @@ class SGRcomposer {
this.style = styles;
}


get depth() {
return this._depth;
}


get color() {
return this._color;
}


get hex() {
return converter.rgb.hex(this._color);
}


get red() {
return this._color[0];
}


get green() {
return this._color[1];
}


get blue() {
return this._color[2];
}


get style() {
let styles = '';
Object.keys(this.styles).forEach(key_ => {
Expand All @@ -198,28 +186,24 @@ class SGRcomposer {
return styles === '' ? undefined : styles;
}


set style(styles) {
this.styles = parseStyles(styles);
this.colorSGR = 'color' in this.styles ? parseColor(this.styles.color, this._depth, this.styles.background) : this.colorSGR;
this.styleSGR = setStyles(this.styles);
this._color = 'color' in this.styles ? this.styles.color : this._color;
}


get styleArray() {
const styles = [];
Object.keys(this.styles).forEach(key_ => this.styles[key_] === true && styles.push(key_));
return styles;
}


set color(color) {
this.colorSGR = parseColor(color, this._depth, false);
this._color = color;
}


sgr(exclusions) {
const styleSGRtemp = exclusions === undefined ? this.styleSGR : setStyles(this.styles, parseStyles(exclusions));
const inJoin = this.colorSGR.in !== '' && styleSGRtemp.in !== '' ? ';' : '';
Expand Down
16 changes: 0 additions & 16 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const _styles = {
underline: [4, 24],
blink: [5, 25],
invert: [7, 27]

};

function parseColor(color_, depth_, bg_) {
Expand Down Expand Up @@ -63,7 +62,6 @@ function parseColor(color_, depth_, bg_) {
}
})(),
out: bg_ ? _SGRparts.bg[1] : _SGRparts.fg[1]

};
return {
in: `${mode.in}${color}`,
Expand All @@ -72,7 +70,6 @@ function parseColor(color_, depth_, bg_) {
})();
}


function parseStyles(styles_) {
const styles = {
background: false,
Expand Down Expand Up @@ -104,7 +101,6 @@ function parseStyles(styles_) {
}
}


function setStyles(styles, excluded_) {
const excluded = excluded_ === undefined ? {} : excluded_;
const sgrIn = [];
Expand All @@ -126,7 +122,6 @@ function setStyles(styles, excluded_) {
};
}


class SGRcomposer {
constructor(targetDepth, styles) {
this._depth = (depth_ => {
Expand All @@ -152,37 +147,30 @@ class SGRcomposer {
this.style = styles;
}


get depth() {
return this._depth;
}


get color() {
return this._color;
}


get hex() {
return converter.rgb.hex(this._color);
}


get red() {
return this._color[0];
}


get green() {
return this._color[1];
}


get blue() {
return this._color[2];
}


get style() {
let styles = '';
Object.keys(this.styles).forEach(key_ => {
Expand All @@ -194,28 +182,24 @@ class SGRcomposer {
return styles === '' ? undefined : styles;
}


set style(styles) {
this.styles = parseStyles(styles);
this.colorSGR = 'color' in this.styles ? parseColor(this.styles.color, this._depth, this.styles.background) : this.colorSGR;
this.styleSGR = setStyles(this.styles);
this._color = 'color' in this.styles ? this.styles.color : this._color;
}


get styleArray() {
const styles = [];
Object.keys(this.styles).forEach(key_ => this.styles[key_] === true && styles.push(key_));
return styles;
}


set color(color) {
this.colorSGR = parseColor(color, this._depth, false);
this._color = color;
}


sgr(exclusions) {
const styleSGRtemp = exclusions === undefined ? this.styleSGR : setStyles(this.styles, parseStyles(exclusions));
const inJoin = this.colorSGR.in !== '' && styleSGRtemp.in !== '' ? ';' : '';
Expand Down
Loading

0 comments on commit 8e14be5

Please sign in to comment.