@poppinss/colors
Advanced tools
Comparing version 4.1.0-3 to 4.1.0-4
@@ -1,2 +0,12 @@ | ||
import { Colors } from './src/base.js'; | ||
import { C as Colors } from './base-aa6a952e.js'; | ||
/** | ||
* @poppinss/colors | ||
* | ||
* (c) Poppinss | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
declare const useColors: { | ||
@@ -7,2 +17,3 @@ ansi(): Colors; | ||
}; | ||
export default useColors; | ||
export { useColors as default }; |
@@ -1,15 +0,169 @@ | ||
import { Raw } from './src/raw.js'; | ||
import { Kleur } from './src/kleur.js'; | ||
import { Silent } from './src/silent.js'; | ||
const useColors = { | ||
ansi() { | ||
return new Kleur(); | ||
}, | ||
silent() { | ||
return new Silent(); | ||
}, | ||
raw() { | ||
return new Raw(); | ||
}, | ||
// src/base.ts | ||
var Colors = class { | ||
black(text) { | ||
return this.transform("black", text); | ||
} | ||
red(text) { | ||
return this.transform("red", text); | ||
} | ||
green(text) { | ||
return this.transform("green", text); | ||
} | ||
yellow(text) { | ||
return this.transform("yellow", text); | ||
} | ||
blue(text) { | ||
return this.transform("blue", text); | ||
} | ||
magenta(text) { | ||
return this.transform("magenta", text); | ||
} | ||
cyan(text) { | ||
return this.transform("cyan", text); | ||
} | ||
white(text) { | ||
return this.transform("white", text); | ||
} | ||
gray(text) { | ||
return this.transform("gray", text); | ||
} | ||
grey(text) { | ||
return this.transform("grey", text); | ||
} | ||
bgBlack(text) { | ||
return this.transform("bgBlack", text); | ||
} | ||
bgRed(text) { | ||
return this.transform("bgRed", text); | ||
} | ||
bgGreen(text) { | ||
return this.transform("bgGreen", text); | ||
} | ||
bgYellow(text) { | ||
return this.transform("bgYellow", text); | ||
} | ||
bgBlue(text) { | ||
return this.transform("bgBlue", text); | ||
} | ||
bgMagenta(text) { | ||
return this.transform("bgMagenta", text); | ||
} | ||
bgCyan(text) { | ||
return this.transform("bgCyan", text); | ||
} | ||
bgWhite(text) { | ||
return this.transform("bgWhite", text); | ||
} | ||
reset(text) { | ||
return this.transform("reset", text); | ||
} | ||
bold(text) { | ||
return this.transform("bold", text); | ||
} | ||
dim(text) { | ||
return this.transform("dim", text); | ||
} | ||
italic(text) { | ||
return this.transform("italic", text); | ||
} | ||
underline(text) { | ||
return this.transform("underline", text); | ||
} | ||
inverse(text) { | ||
return this.transform("inverse", text); | ||
} | ||
hidden(text) { | ||
return this.transform("hidden", text); | ||
} | ||
strikethrough(text) { | ||
return this.transform("strikethrough", text); | ||
} | ||
}; | ||
export default useColors; | ||
// src/raw.ts | ||
var Raw = class extends Colors { | ||
#transformations = []; | ||
#dispose(value, callback) { | ||
callback(); | ||
return value; | ||
} | ||
transform(transformation, text) { | ||
this.#transformations.push(transformation); | ||
if (text !== void 0) { | ||
const transformations = this.#transformations.concat([text]).join("("); | ||
const closingWrapping = new Array(this.#transformations.length + 1).join(")"); | ||
return this.#dispose(`${transformations}${closingWrapping}`, () => { | ||
this.#transformations = []; | ||
}); | ||
} | ||
return this; | ||
} | ||
}; | ||
// src/kleur.ts | ||
import kleur from "kleur"; | ||
var Kleur = class extends Colors { | ||
#chain; | ||
constructor() { | ||
super(); | ||
kleur.enabled = true; | ||
} | ||
#dispose(value, callback) { | ||
callback(); | ||
return value; | ||
} | ||
transform(transformation, text) { | ||
if (text !== void 0) { | ||
if (this.#chain) { | ||
return this.#dispose(this.#chain[transformation](text), () => { | ||
this.#chain = void 0; | ||
}); | ||
} | ||
return kleur[transformation](text); | ||
} | ||
if (this.#chain) { | ||
this.#chain = this.#chain[transformation](); | ||
} else { | ||
this.#chain = kleur[transformation](); | ||
} | ||
return this; | ||
} | ||
}; | ||
// src/silent.ts | ||
var Silent = class extends Colors { | ||
transform(_, text) { | ||
if (text !== void 0) { | ||
return String(text); | ||
} | ||
return this; | ||
} | ||
}; | ||
// index.ts | ||
var useColors = { | ||
/** | ||
* Kleur implementation | ||
*/ | ||
ansi() { | ||
return new Kleur(); | ||
}, | ||
/** | ||
* Silent implementation. Returns the string | ||
* as it is | ||
*/ | ||
silent() { | ||
return new Silent(); | ||
}, | ||
/** | ||
* Raw implementation. Wraps string with applied | ||
* transformations as plain text. | ||
*/ | ||
raw() { | ||
return new Raw(); | ||
} | ||
}; | ||
var colors_default = useColors; | ||
export { | ||
colors_default as default | ||
}; |
@@ -1,3 +0,14 @@ | ||
import { Colors } from './base.js'; | ||
export type { Colors } from './base.js'; | ||
export type ColorTransformations = keyof Colors; | ||
import { C as Colors } from '../base-aa6a952e.js'; | ||
/** | ||
* @poppinss/colors | ||
* | ||
* (c) Poppinss | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
type ColorTransformations = keyof Colors; | ||
export { ColorTransformations, Colors }; |
{ | ||
"name": "@poppinss/colors", | ||
"version": "4.1.0-3", | ||
"version": "4.1.0-4", | ||
"description": "A wrapper on top of kleur with ability to write test against the color functions", | ||
@@ -8,5 +8,3 @@ "main": "build/index.js", | ||
"files": [ | ||
"build/src", | ||
"build/index.d.ts", | ||
"build/index.js" | ||
"build" | ||
], | ||
@@ -25,3 +23,3 @@ "exports": { | ||
"typecheck": "tsc --noEmit", | ||
"compile": "npm run lint && npm run clean && tsc", | ||
"compile": "npm run lint && npm run clean && tsup-node", | ||
"format": "prettier --write .", | ||
@@ -43,20 +41,21 @@ "build": "npm run compile", | ||
"devDependencies": { | ||
"@adonisjs/eslint-config": "^1.1.6", | ||
"@adonisjs/prettier-config": "^1.1.6", | ||
"@adonisjs/tsconfig": "^1.1.6", | ||
"@commitlint/cli": "^17.6.6", | ||
"@commitlint/config-conventional": "^17.6.6", | ||
"@adonisjs/eslint-config": "^1.1.8", | ||
"@adonisjs/prettier-config": "^1.1.8", | ||
"@adonisjs/tsconfig": "^1.1.8", | ||
"@commitlint/cli": "^17.7.1", | ||
"@commitlint/config-conventional": "^17.7.0", | ||
"@japa/assert": "^2.0.0-1", | ||
"@japa/runner": "^3.0.0-2", | ||
"@swc/core": "^1.3.67", | ||
"@types/node": "^20.3.2", | ||
"c8": "^8.0.0", | ||
"del-cli": "^5.0.0", | ||
"eslint": "^8.43.0", | ||
"@swc/core": "1.3.82", | ||
"@types/node": "^20.6.3", | ||
"c8": "^8.0.1", | ||
"del-cli": "^5.1.0", | ||
"eslint": "^8.50.0", | ||
"github-label-sync": "^2.3.1", | ||
"husky": "^8.0.3", | ||
"np": "^8.0.4", | ||
"prettier": "^2.8.8", | ||
"prettier": "^3.0.3", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.1.6" | ||
"tsup": "^7.2.0", | ||
"typescript": "^5.2.2" | ||
}, | ||
@@ -101,3 +100,14 @@ "dependencies": { | ||
}, | ||
"prettier": "@adonisjs/prettier-config" | ||
"prettier": "@adonisjs/prettier-config", | ||
"tsup": { | ||
"entry": [ | ||
"./index.ts", | ||
"./src/types.ts" | ||
], | ||
"outDir": "./build", | ||
"clean": true, | ||
"format": "esm", | ||
"dts": true, | ||
"target": "esnext" | ||
} | ||
} |
# @poppinss/colors | ||
> Wrapper over [kleur](https://www.npmjs.com/package/kleur) with better support for testing | ||
[![gh-workflow-image]][gh-workflow-url] [![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url] [![synk-image]][synk-url] | ||
[![gh-workflow-image]][gh-workflow-url] [![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url] | ||
## Why this package exists? | ||
This package is a wrapper over [kleur](https://www.npmjs.com/package/kleur) with a couple of other implementations to make testing easier and work seamlessly with terminals/stdout streams that do not support colors. | ||
This package is a wrapper over [kleur](https://www.npmjs.com/package/kleur) with additional implementations to make testing easier and work seamlessly with terminals/stdout streams that do not support colors. | ||
@@ -85,4 +85,4 @@ ## Usage | ||
[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/poppinss/colors/test.yml?style=for-the-badge | ||
[gh-workflow-url]: https://github.com/poppinss/colors/actions/workflows/test.yml "Github action" | ||
[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/poppinss/colors/checks.yml?style=for-the-badge | ||
[gh-workflow-url]: https://github.com/poppinss/colors/actions/workflows/checks.yml "Github action" | ||
@@ -97,4 +97,1 @@ [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript | ||
[license-url]: LICENSE.md 'license' | ||
[synk-image]: https://img.shields.io/snyk/vulnerabilities/github/poppinss/colors?label=Synk%20Vulnerabilities&style=for-the-badge | ||
[synk-url]: https://snyk.io/test/github/poppinss/colors?targetFile=package.json 'synk' |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
260
12752
19
8
96
1