Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyao27 committed May 17, 2024
0 parents commit 2fb74d7
Show file tree
Hide file tree
Showing 24 changed files with 762 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .commitlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@commitlint/config-conventional"]
}
3 changes: 3 additions & 0 deletions .czrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "cz-conventional-changelog"
}
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [xinyao27]
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Lint

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install bun
uses: oven-sh/setup-bun@v1

- name: Install
run: bun install

- name: Lint
run: bun run lint
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false

steps:
- uses: actions/checkout@v4

- name: Install bun
uses: oven-sh/setup-bun@v1

- name: Install
run: bun install

- name: Build
run: bun run build

- name: Test
run: bun run test
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# compiled output
dist
node_modules

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
coverage
/.nyc_output

# IDEs and editors
.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# config
.env
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
6 changes: 6 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"*.{js?(x),ts?(x),vue,html,md,json,yml}": [
"eslint --fix",
"git add"
]
}
11 changes: 11 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"git": {
"commitMessage": "chore: release v${version}"
},
"plugins": {
"@release-it/conventional-changelog": {
"preset": "angular",
"infile": "CHANGELOG.md"
}
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 xinyao27 <https://github.com/xinyao27>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
111 changes: 111 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# xycolors 🌈

[![NPM version](https://img.shields.io/npm/v/xycolors?color=a1b858&label=)](https://www.npmjs.com/package/xycolors)

> A tiny and fast package for adding colors to your terminal output.
>
> Based on [yoctocolors](https://github.com/sindresorhus/yoctocolors)
## Highlights

- Tiny
- Fast
- Handles nested colors
- Tree-shakeable
- No dependencies
- Actively maintained

## Install

```sh
npm install xycolors
```

## Usage

```js
import * as c from 'xycolors'

console.log(c.red('Yo!'))

console.log(c.blue(`Welcome to the ${colors.magenta('xycolors')} package!`))
```

_This package supports [basic color detection](https://nodejs.org/api/tty.html#writestreamhascolorscount-env). Colors can be forcefully enabled by setting the `FORCE_COLOR` environment variable to `1` and can be forcefully disabled by setting `NO_COLOR` or `NODE_DISABLE_COLORS` to any value. [More info.](https://nodejs.org/api/tty.html#writestreamgetcolordepthenv)_

## Styles

### Modifiers

- `reset` - Reset the current style.
- `bold` - Make the text bold.
- `dim` - Make the text have lower opacity.
- `italic` - Make the text italic. _(Not widely supported)_
- `underline` - Put a horizontal line above the text. _(Not widely supported)_
- `overline` - Put a horizontal line below the text. _(Not widely supported)_
- `inverse`- Invert background and foreground colors.
- `hidden` - Print the text but make it invisible.
- `strikethrough` - Put a horizontal line through the center of the text. _(Not widely supported)_

### Colors

- `black`
- `red`
- `green`
- `yellow`
- `blue`
- `magenta`
- `cyan`
- `white`
- `gray`
- `redBright`
- `greenBright`
- `yellowBright`
- `blueBright`
- `magentaBright`
- `cyanBright`
- `whiteBright`

### Background colors

- `bgBlack`
- `bgRed`
- `bgGreen`
- `bgYellow`
- `bgBlue`
- `bgMagenta`
- `bgCyan`
- `bgWhite`
- `bgGray`
- `bgRedBright`
- `bgGreenBright`
- `bgYellowBright`
- `bgBlueBright`
- `bgMagentaBright`
- `bgCyanBright`
- `bgWhiteBright`

## Benchmark

```sh
$ ./benchmark.js
┌─────────┬────────────────┬─────────────┐
│ (index) │ library │ ops/sec │
├─────────┼────────────────┼─────────────┤
│ 0 │ 'xycolors''8,000,000'
│ 1 │ 'picocolors''8,000,000'
│ 2 │ 'colorette''6,024,096'
│ 3 │ 'kleur/colors''4,807,692'
│ 4 │ 'nanocolors''4,807,692'
│ 5 │ 'chalk''4,000,000'
│ 6 │ 'kleur''4,000,000'
│ 7 │ 'ansi-colors''1,848,429'
│ 8 │ 'cli-color''585,480'
└─────────┴────────────────┴─────────────┘
```

_See [benchmark.js](benchmark.js)._

## License

[MIT](./LICENSE) License © 2024 [xinyao27](https://github.com/xinyao27)
82 changes: 82 additions & 0 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env node
import { Suite } from '@jonahsnider/benchmark'
import ansi from 'ansi-colors'
import chalk from 'chalk'
import cliColor from 'cli-color'
import * as colorette from 'colorette'
import kleur from 'kleur'
import * as kleurColors from 'kleur/colors'
import * as nanocolors from 'nanocolors'
import picocolors from 'picocolors'
import * as xycolors from './dist/index.mjs'

const suite = new Suite('simple', {
warmup: { trials: 10_000_000 },
run: { trials: 1_000_000 },
})

// eslint-disable-next-line no-unused-vars
let out

suite
.addTest('xycolors', () => {
out = xycolors.red('Add plugin to use time limit')
out = xycolors.green('Add plugin to use time limit')
out = xycolors.blue(`Add plugin to ${xycolors.cyan('use')} time limit`)
})
.addTest('cli-color', () => {
out = cliColor.red('Add plugin to use time limit')
out = cliColor.green('Add plugin to use time limit')
out = cliColor.blue(`Add plugin to ${cliColor.cyan('use')} time limit`)
})
.addTest('ansi-colors', () => {
out = ansi.red('Add plugin to use time limit')
out = ansi.green('Add plugin to use time limit')
out = ansi.blue(`Add plugin to ${ansi.cyan('use')} time limit`)
})
.addTest('chalk', () => {
out = chalk.red('Add plugin to use time limit')
out = chalk.green('Add plugin to use time limit')
out = chalk.blue(`Add plugin to ${chalk.cyan('use')} time limit`)
})
.addTest('kleur', () => {
out = kleur.red('Add plugin to use time limit')
out = kleur.green('Add plugin to use time limit')
out = kleur.blue(`Add plugin to ${kleur.cyan('use')} time limit`)
})
.addTest('kleur/colors', () => {
out = kleurColors.red('Add plugin to use time limit')
out = kleurColors.green('Add plugin to use time limit')
out = kleurColors.blue(`Add plugin to ${kleurColors.cyan('use')} time limit`)
})
.addTest('colorette', () => {
out = colorette.red('Add plugin to use time limit')
out = colorette.green('Add plugin to use time limit')
out = colorette.blue(`Add plugin to ${colorette.cyan('use')} time limit`)
})
.addTest('nanocolors', () => {
out = nanocolors.red('Add plugin to use time limit')
out = nanocolors.green('Add plugin to use time limit')
out = nanocolors.blue(`Add plugin to ${nanocolors.cyan('use')} time limit`)
})
.addTest('picocolors', () => {
out = picocolors.red('Add plugin to use time limit')
out = picocolors.green('Add plugin to use time limit')
out = picocolors.blue(`Add plugin to ${picocolors.cyan('use')} time limit`)
})

const results = await suite.run()

const table = [...results]
// Convert median execution time to mean ops/sec
.map(([library, histogram]) => [library, Math.round(1e9 / histogram.percentile(50))])
// Sort fastest to slowest
.sort(([, a], [, b]) => b - a)
// Convert to object for console.table
.map(([library, opsPerSec]) => ({
library,
'ops/sec': opsPerSec.toLocaleString(),
}))

// eslint-disable-next-line no-console
console.table(table)
17 changes: 17 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defineBuildConfig } from 'unbuild'
import pkg from './package.json'

export default defineBuildConfig({
entries: ['src/index'],
declaration: true,
clean: true,
rollup: {
emitCJS: true,
esbuild: {
minify: true,
},
},
replace: {
'process.env.VERSION': JSON.stringify(pkg.version),
},
})
Binary file added bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { all } from '@xystack/style-guide/eslint'

export default all
Loading

0 comments on commit 2fb74d7

Please sign in to comment.