Skip to content

Commit

Permalink
release v0.0.4 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 authored Aug 31, 2020
1 parent 5cea46d commit 2f32800
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 18 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI
on:
push:
branches: [master]
pull_request:
types: [opened, synchronize]
jobs:
build:
runs-on: ubuntu-16.04
strategy:
matrix:
deno: ["v1.3.2"]
name: Deno ${{ matrix.deno }} sample
steps:
- uses: actions/checkout@v2
- name: Setup Deno
uses: denolib/setup-deno@v2
with:
deno-version: ${{ matrix.deno }}
- name: Check formatted codebase
run: |
deno fmt --check examples/
deno fmt --check index.ts
- name: Run examples/
run: |
deno run examples/simple.ts
deno run examples/custom.ts
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Generate Badges for your CLI.

[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno&labelColor=black)](https://deno.land/x/cli_badges) [![deno version](https://img.shields.io/badge/deno-^1.3.2-lightgrey?logo=deno)](https://github.com/denoland/deno) [![GitHub release](https://img.shields.io/github/release/Delta456/cli_badges.svg)](https://github.com/Delta456/cli_badges/releases)
[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno&labelColor=black)](https://deno.land/x/cli_badges) [![deno version](https://img.shields.io/badge/deno-^1.3.2-lightgrey?logo=deno)](https://github.com/denoland/deno) [![GitHub release](https://img.shields.io/github/release/Delta456/cli_badges.svg)](https://github.com/Delta456/cli_badges/releases) [![GitHub Actions](https://github.com/Delta456/box-cli-maker/workflows/cli%20badges/badge.svg)](https://github.com/Delta456/cli_badges/actions?query=workflow%3ACI)


## Features
Expand All @@ -16,7 +16,7 @@ Generate Badges for your CLI.
## Usage

```ts
import { badges } from "https://deno.land/x/[email protected].3/index.ts";
import { badges } from "https://deno.land/x/[email protected].4/index.ts";

console.log(badges('failed', '2', {msgBg: "red"}))

Expand Down
7 changes: 7 additions & 0 deletions examples/custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { badges } from "https://deno.land/x/[email protected]/index.ts";

console.log(badges("failed", "2", { msgBg: "red" }));

console.log(badges("success", "2", { msgBg: "green" }));

console.log(badges("skipped", "2", { msgBg: "yellow" }));
3 changes: 3 additions & 0 deletions examples/simple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { badges } from "https://deno.land/x/[email protected]/index.ts";

console.log(badges("counter", "5"));
51 changes: 35 additions & 16 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
import * as color from "https://deno.land/[email protected]/fmt/colors.ts";

type ColorType = { [x: string]: (str: string) => string };
type Color =
| "black"
| "red"
| "blue"
| "green"
| "yellow"
| "magenta"
| "cyan"
| "white"
| "brightBlack"
| "brightRed"
| "brightBlue"
| "brightGreen"
| "brightYellow"
| "brightMagenta"
| "brightCyan"
| "brightWhite";
type Format = "italic" | "underline" | "bold" | "inverse" | "dim" | "strike";
type ColorType = { [c in Color]: (str: string) => string };
type FormatType = { [format in Format]: (str: string) => string };

export interface BadgeOptions {
msgBg: string;
labelBg: string;
msgColor: string;
labelColor: string;
msgStyle?: string;
labelStyle?: string;
msgBg: Color;
labelBg: Color;
msgColor: Color;
labelColor: Color;
msgStyle?: Format;
labelStyle?: Format;
msgWidth?: number;
labelWidth?: number;
}
Expand Down Expand Up @@ -51,7 +70,7 @@ const colorTypes: ColorType = {
brightWhite: (str: string) => color.brightWhite(str),
};

const formatters: ColorType = {
const formatters: FormatType = {
bold: (str: string) => color.bold(str),
italic: (str: string) => color.italic(str),
inverse: (str: string) => color.inverse(str),
Expand All @@ -60,7 +79,7 @@ const formatters: ColorType = {
underline: (str: string) => color.underline(str),
};

function padd(str: string, width: number | undefined): string {
function padd(str: string, width?: number): string {
if (!width) width = str.length + 2; // one space on each side

const halfWith = Math.ceil((width - str.length) / 2);
Expand All @@ -70,7 +89,7 @@ function padd(str: string, width: number | undefined): string {
}

function getBgColor(
colr: string | undefined,
colr?: Color,
): (str: string) => string {
if (!colr) {
return color.bgBrightBlack;
Expand All @@ -79,17 +98,17 @@ function getBgColor(
}

function getTextColor(
colr: string | undefined,
colr?: Color,
): (str: string) => string {
if (!colr) {
return color.blue;
return color.white;
}
return colorTypes[colr];
}

function format(
str: string,
formatterName: string | undefined,
formatterName?: Format,
): string {
if (!formatterName) return str;

Expand Down Expand Up @@ -126,12 +145,12 @@ export function badges(
const lblStr = padd(label, labelWidth);
const msgStr = padd(msg, msgWidth);

const lblColored = getTextColor(labelColor)(
getBgColor(labelBg)(lblStr),
);
const msgColored = getTextColor(msgColor)(
getBgColor(msgBg)(msgStr),
);
const lblColored = getTextColor(labelColor)(
getBgColor(labelBg)(lblStr),
);

const labelformat = format(lblColored, labelStyle);
const msgformat = format(msgColored, msgStyle);
Expand Down

0 comments on commit 2f32800

Please sign in to comment.