| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3bdc955 commit 2000cac
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,7 @@ const { | |||
| 32 | 32 | ObjectDefineProperties, | |
| 33 | 33 | ObjectDefineProperty, | |
| 34 | 34 | ObjectGetOwnPropertyDescriptors, | |
| 35 | + ObjectGetOwnPropertyNames, | ||
| 35 | 36 | ObjectKeys, | |
| 36 | 37 | ObjectSetPrototypeOf, | |
| 37 | 38 | ObjectValues, | |
@@ -115,7 +116,7 @@ function getStyleCache() { | |||
| 115 | 116 | if (styleCache === undefined) { | |
| 116 | 117 | styleCache = { __proto__: null }; | |
| 117 | 118 | const colors = inspect.colors; | |
| 118 | - for (const key of ObjectKeys(colors)) { | ||
| 119 | + for (const key of ObjectGetOwnPropertyNames(colors)) { | ||
| 119 | 120 | const codes = colors[key]; | |
| 120 | 121 | if (codes) { | |
| 121 | 122 | const openNum = codes[0]; | |
@@ -206,7 +207,7 @@ function styleText(format, text, options) { | |||
| 206 | 207 | if (key === 'none') continue; | |
| 207 | 208 | const style = cache[key]; | |
| 208 | 209 | if (style === undefined) { | |
| 209 | - validateOneOf(key, 'format', ObjectKeys(inspect.colors)); | ||
| 210 | + validateOneOf(key, 'format', ObjectGetOwnPropertyNames(inspect.colors)); | ||
| 210 | 211 | } | |
| 211 | 212 | openCodes += style.openSeq; | |
| 212 | 213 | closeCodes = style.closeSeq + closeCodes; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,6 +41,16 @@ assert.strictEqual( | |||
| 41 | 41 | '\u001b[31mtest\u001b[39m', | |
| 42 | 42 | ); | |
| 43 | 43 | ||
| 44 | + assert.strictEqual( | ||
| 45 | + util.styleText('gray', 'test', { validateStream: false }), | ||
| 46 | + '\u001b[90mtest\u001b[39m', | ||
| 47 | + ); | ||
| 48 | + | ||
| 49 | + assert.strictEqual( | ||
| 50 | + util.styleText('grey', 'test', { validateStream: false }), | ||
| 51 | + '\u001b[90mtest\u001b[39m', | ||
| 52 | + ); | ||
| 53 | + | ||
| 44 | 54 | assert.strictEqual( | |
| 45 | 55 | util.styleText(['bold', 'red'], 'test', { validateStream: false }), | |
| 46 | 56 | '\u001b[1m\u001b[31mtest\u001b[39m\u001b[22m', | |
@@ -144,6 +154,29 @@ assert.throws(() => { | |||
| 144 | 154 | code: 'ERR_INVALID_ARG_TYPE', | |
| 145 | 155 | }); | |
| 146 | 156 | ||
| 157 | + // Color aliases should be accepted (e.g. 'grey' is an alias for 'gray') | ||
| 158 | + // See https://github.com/nodejs/node/issues/62177 | ||
| 159 | + assert.strictEqual( | ||
| 160 | + util.styleText('grey', 'test', { validateStream: false }), | ||
| 161 | + util.styleText('gray', 'test', { validateStream: false }), | ||
| 162 | + ); | ||
| 163 | + assert.strictEqual( | ||
| 164 | + util.styleText('bgGrey', 'test', { validateStream: false }), | ||
| 165 | + util.styleText('bgGray', 'test', { validateStream: false }), | ||
| 166 | + ); | ||
| 167 | + assert.strictEqual( | ||
| 168 | + util.styleText('blackBright', 'test', { validateStream: false }), | ||
| 169 | + util.styleText('gray', 'test', { validateStream: false }), | ||
| 170 | + ); | ||
| 171 | + assert.strictEqual( | ||
| 172 | + util.styleText('faint', 'test', { validateStream: false }), | ||
| 173 | + util.styleText('dim', 'test', { validateStream: false }), | ||
| 174 | + ); | ||
| 175 | + assert.strictEqual( | ||
| 176 | + util.styleText(['grey', 'bold'], 'test', { validateStream: false }), | ||
| 177 | + util.styleText(['gray', 'bold'], 'test', { validateStream: false }), | ||
| 178 | + ); | ||
| 179 | + | ||
| 147 | 180 | // does not throw | |
| 148 | 181 | util.styleText('red', 'text', { stream: {}, validateStream: false }); | |
| 149 | 182 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments