Skip to content

Commit 8e14be5

Browse files
committed
Update and polish
1 parent f8b0b1f commit 8e14be5

File tree

8 files changed

+6341
-10293
lines changed

8 files changed

+6341
-10293
lines changed

.travis.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
---
22
branches:
33
only:
4-
- master
5-
- develop
6-
- /^greenkeeper/.*$/
4+
- master
5+
- develop
6+
- /^greenkeeper/.*$/
7+
- /^feature/.*$/
78
language: node_js
89
node_js:
910
- stable
11+
= 10
1012
- 9
1113
- 8
12-
sudo: false
13-
notifications:
14-
webhooks:
15-
urls:
16-
- https://webhooks.gitter.im/e/d0418713e51ac049564a
17-
on_success: always
18-
on_failure: change
19-
on_start: never
2014
env:
2115
global:
2216
- CC_TEST_REPORTER_ID=f017a295c85532d945c74fe17b7f45c516ff72ef478548a99b165927aaa321d7
23-
- secure: k+PXexJeDTne3XBzuDa59S3V7lvZ1hXoivoD3AkSM30WXRFVhqvreCkpcrKcwLWD6DTJA7DYy2eQE26V4Q2NVIPSHo4cMhVKX4v6a4JITN8UCWKqa9oaDE4OuHWymVXcuS1FRDUJQEy59oRb1zM37f+3bfOEoEupgg4IDBErxiaWyLZV3d8f5mVNkZC2nhvXdfla/KNeJxCIBk8bzR9yCPgra8frwzGb0ZQazZfyy31D3JkHYNeJfIp/4ncXLiracUxzLLAevW0sb4RI3oP3KX8UKs//uT0ipjQnSqPQFM1gewDUPelk6XvI/glw6G1+nttqcyxj+LO6mlpJGXtcyNP2qziU86n2UYsxaocEtvcK4U7lKyo5tnrJr/WunZZ1k0H8YHASkHdKsef5m+lhlrKvk9ebMZER96bE1+p7gNSo9ghGNS+JSelVqs9hqNMFAAdiT8Y3Q5li5Yg81BNbLOXTYwFlXt1OKPrC2Ie3kKw/kbcYIhn9bofmsCHI2naULquISoEW94cqycpZzPfRmoWXOVqXM+jyWdQ/w1tEFuthYIiYJG1YIoptuW2ZIR6kIt8bLe6ZKCotkIfUY8fnENIq/VuNhIZWzHt5rtnqeP0XiH2aPGFXmAVGylVbUZLifQa8mS6CQiR9CTD7bOy5/odFtKrqGD1IN/QxpaLoa1I=
2417
before_install:
2518
- '[[ $(node -v) =~ ^v10.*$ ]] || npm install -g npm@latest'
2619
- npm install -g greenkeeper-lockfile

gulpfile.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const gulp = require('gulp')
22
const rename = require('gulp-rename')
3-
const strip = require('gulp-strip-comments')
43
const rollup = require('gulp-better-rollup')
4+
const resolve = require('rollup-plugin-node-resolve')
5+
const commonjs = require('rollup-plugin-commonjs')
56
const babel = require('rollup-plugin-babel')
67

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

910
const babelConfig = {
1011
presets: [
@@ -15,30 +16,29 @@ const babelConfig = {
1516
}
1617
}]
1718
],
19+
comments: false,
1820
exclude: 'node_modules/**'
1921
}
2022

2123
gulp.task('cjs', () =>
2224
gulp.src('src/index.js')
2325
.pipe(rollup({
2426
external,
25-
plugins: [babel(babelConfig)]
27+
plugins: [resolve(), commonjs(), babel(babelConfig)]
2628
}, {
2729
format: 'cjs'
2830
}))
29-
.pipe(strip())
3031
.pipe(gulp.dest('.'))
3132
)
3233

3334
gulp.task('es6', () =>
3435
gulp.src('src/index.js')
3536
.pipe(rollup({
3637
external,
37-
plugins: [babel(babelConfig)]
38+
plugins: [resolve(), commonjs(), babel(babelConfig)]
3839
}, {
3940
format: 'es'
4041
}))
41-
.pipe(strip())
4242
.pipe(rename('index.mjs'))
4343
.pipe(gulp.dest('.'))
4444
)

index.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const _styles = {
2222
underline: [4, 24],
2323
blink: [5, 25],
2424
invert: [7, 27]
25-
2625
};
2726

2827
function parseColor(color_, depth_, bg_) {
@@ -67,7 +66,6 @@ function parseColor(color_, depth_, bg_) {
6766
}
6867
})(),
6968
out: bg_ ? _SGRparts.bg[1] : _SGRparts.fg[1]
70-
7169
};
7270
return {
7371
in: `${mode.in}${color}`,
@@ -76,7 +74,6 @@ function parseColor(color_, depth_, bg_) {
7674
})();
7775
}
7876

79-
8077
function parseStyles(styles_) {
8178
const styles = {
8279
background: false,
@@ -108,7 +105,6 @@ function parseStyles(styles_) {
108105
}
109106
}
110107

111-
112108
function setStyles(styles, excluded_) {
113109
const excluded = excluded_ === undefined ? {} : excluded_;
114110
const sgrIn = [];
@@ -130,7 +126,6 @@ function setStyles(styles, excluded_) {
130126
};
131127
}
132128

133-
134129
class SGRcomposer {
135130
constructor(targetDepth, styles) {
136131
this._depth = (depth_ => {
@@ -156,37 +151,30 @@ class SGRcomposer {
156151
this.style = styles;
157152
}
158153

159-
160154
get depth() {
161155
return this._depth;
162156
}
163157

164-
165158
get color() {
166159
return this._color;
167160
}
168161

169-
170162
get hex() {
171163
return converter.rgb.hex(this._color);
172164
}
173165

174-
175166
get red() {
176167
return this._color[0];
177168
}
178169

179-
180170
get green() {
181171
return this._color[1];
182172
}
183173

184-
185174
get blue() {
186175
return this._color[2];
187176
}
188177

189-
190178
get style() {
191179
let styles = '';
192180
Object.keys(this.styles).forEach(key_ => {
@@ -198,28 +186,24 @@ class SGRcomposer {
198186
return styles === '' ? undefined : styles;
199187
}
200188

201-
202189
set style(styles) {
203190
this.styles = parseStyles(styles);
204191
this.colorSGR = 'color' in this.styles ? parseColor(this.styles.color, this._depth, this.styles.background) : this.colorSGR;
205192
this.styleSGR = setStyles(this.styles);
206193
this._color = 'color' in this.styles ? this.styles.color : this._color;
207194
}
208195

209-
210196
get styleArray() {
211197
const styles = [];
212198
Object.keys(this.styles).forEach(key_ => this.styles[key_] === true && styles.push(key_));
213199
return styles;
214200
}
215201

216-
217202
set color(color) {
218203
this.colorSGR = parseColor(color, this._depth, false);
219204
this._color = color;
220205
}
221206

222-
223207
sgr(exclusions) {
224208
const styleSGRtemp = exclusions === undefined ? this.styleSGR : setStyles(this.styles, parseStyles(exclusions));
225209
const inJoin = this.colorSGR.in !== '' && styleSGRtemp.in !== '' ? ';' : '';

index.mjs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const _styles = {
1818
underline: [4, 24],
1919
blink: [5, 25],
2020
invert: [7, 27]
21-
2221
};
2322

2423
function parseColor(color_, depth_, bg_) {
@@ -63,7 +62,6 @@ function parseColor(color_, depth_, bg_) {
6362
}
6463
})(),
6564
out: bg_ ? _SGRparts.bg[1] : _SGRparts.fg[1]
66-
6765
};
6866
return {
6967
in: `${mode.in}${color}`,
@@ -72,7 +70,6 @@ function parseColor(color_, depth_, bg_) {
7270
})();
7371
}
7472

75-
7673
function parseStyles(styles_) {
7774
const styles = {
7875
background: false,
@@ -104,7 +101,6 @@ function parseStyles(styles_) {
104101
}
105102
}
106103

107-
108104
function setStyles(styles, excluded_) {
109105
const excluded = excluded_ === undefined ? {} : excluded_;
110106
const sgrIn = [];
@@ -126,7 +122,6 @@ function setStyles(styles, excluded_) {
126122
};
127123
}
128124

129-
130125
class SGRcomposer {
131126
constructor(targetDepth, styles) {
132127
this._depth = (depth_ => {
@@ -152,37 +147,30 @@ class SGRcomposer {
152147
this.style = styles;
153148
}
154149

155-
156150
get depth() {
157151
return this._depth;
158152
}
159153

160-
161154
get color() {
162155
return this._color;
163156
}
164157

165-
166158
get hex() {
167159
return converter.rgb.hex(this._color);
168160
}
169161

170-
171162
get red() {
172163
return this._color[0];
173164
}
174165

175-
176166
get green() {
177167
return this._color[1];
178168
}
179169

180-
181170
get blue() {
182171
return this._color[2];
183172
}
184173

185-
186174
get style() {
187175
let styles = '';
188176
Object.keys(this.styles).forEach(key_ => {
@@ -194,28 +182,24 @@ class SGRcomposer {
194182
return styles === '' ? undefined : styles;
195183
}
196184

197-
198185
set style(styles) {
199186
this.styles = parseStyles(styles);
200187
this.colorSGR = 'color' in this.styles ? parseColor(this.styles.color, this._depth, this.styles.background) : this.colorSGR;
201188
this.styleSGR = setStyles(this.styles);
202189
this._color = 'color' in this.styles ? this.styles.color : this._color;
203190
}
204191

205-
206192
get styleArray() {
207193
const styles = [];
208194
Object.keys(this.styles).forEach(key_ => this.styles[key_] === true && styles.push(key_));
209195
return styles;
210196
}
211197

212-
213198
set color(color) {
214199
this.colorSGR = parseColor(color, this._depth, false);
215200
this._color = color;
216201
}
217202

218-
219203
sgr(exclusions) {
220204
const styleSGRtemp = exclusions === undefined ? this.styleSGR : setStyles(this.styles, parseStyles(exclusions));
221205
const inJoin = this.colorSGR.in !== '' && styleSGRtemp.in !== '' ? ';' : '';

0 commit comments

Comments
 (0)