-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The world is not ready for esm yet #26
Conversation
picocolors.d.ts
Outdated
bgMagenta: (input: string) => string, | ||
bgCyan: (input: string) => string, | ||
bgWhite: (input: string) => string, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need createColors
type too.
@ai, I made another attempt to do |
@alexeyraspopov export type Formatter = (input: string | number | null | undefined) => string;
export interface Colors {
isColorSupported: boolean;
reset: Formatter;
bold: Formatter;
dim: Formatter;
italic: Formatter;
underline: Formatter;
inverse: Formatter;
hidden: Formatter;
strikethrough: Formatter;
black: Formatter;
red: Formatter;
green: Formatter;
yellow: Formatter;
blue: Formatter;
magenta: Formatter;
cyan: Formatter;
white: Formatter;
gray: Formatter;
bgBlack: Formatter;
bgRed: Formatter;
bgGreen: Formatter;
bgYellow: Formatter;
bgBlue: Formatter;
bgMagenta: Formatter;
bgCyan: Formatter;
bgWhite: Formatter;
}
export = Colors & { createColors: (enabled: boolean) => Colors }; Also, it is useful for some TS projects to be able to re--use |
@@ -5,20 +5,19 @@ | |||
A tinier and faster alternative to [nanocolors](https://github.com/ai/nanocolors). Andrey, are you even trying? | |||
|
|||
```javascript | |||
import { green, italic } from "picocolors"; | |||
import pc from "picocolors"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explicit commonjs exports allows to use named imports in node
exports.red = red;
// usage
import { red } from 'picocolors';
0.2.0 broke ESM compatibility and no longer works in this project. See alexeyraspopov/picocolors#26 for the odd reasoning for this change. Maybe consider moving to another small colour library that isn't stuck in the ancient land of CJS
Rationale
With this PR we break any possible compatibility with nanocolors and colorette for the sake of larger ecosystem support, smaller package size, and the ability to enforce color (via custom API).
Additionaly, I decided to make another change here, while I'm at it: using tabs instead of spaces. Because I like tabs with size 2 and it also reduces package size. The PR includes
.editorconfig
so everyone who's using the plugin should be fine. Also, GitHub properly supports it on the website.Preliminary checking the package size (via
clean-publish
andnpm publish --dry-run
) shows following stats:That's a win-win
Closes #4
Closes #13
Closes #22
Closes #25