Skip to content
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

feat: consola/utils subpath export #199

Merged
merged 3 commits into from Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -282,6 +282,23 @@ describe("your-consola-mock-test", () => {
}
```

## Console Utils

```ts
// ESM
import {
stripAnsi,
centerAlign,
rightAlign,
leftAlign,
align,
box,
} from "consola/utils";

// CommonJS
const { stripAnsi } = require("consola/utils");
```

## License

MIT
Expand Down
31 changes: 18 additions & 13 deletions package.json
Expand Up @@ -27,34 +27,39 @@
"require": "./lib/index.cjs"
},
"default": {
"types": "./dist/index.browser.d.ts",
"import": "./dist/index.browser.mjs"
"types": "./dist/browser.d.ts",
"import": "./dist/browser.mjs"
}
},
"./browser": {
"types": "./dist/index.browser.d.ts",
"import": "./dist/index.browser.mjs"
"types": "./dist/browser.d.ts",
"import": "./dist/browser.mjs"
},
"./basic": {
"node": {
"types": "./dist/index.basic.d.ts",
"import": "./dist/index.basic.mjs",
"require": "./dist/index.basic.cjs"
"types": "./dist/basic.d.ts",
"import": "./dist/basic.mjs",
"require": "./dist/basic.cjs"
},
"default": {
"types": "./dist/index.browser.d.ts",
"import": "./dist/index.browser.mjs"
"types": "./dist/browser.d.ts",
"import": "./dist/browser.mjs"
}
},
"./core": {
"types": "./dist/index.core.d.ts",
"import": "./dist/index.core.mjs",
"require": "./dist/index.core.cjs"
"types": "./dist/core.d.ts",
"import": "./dist/core.mjs",
"require": "./dist/core.cjs"
},
"./utils": {
"types": "./dist/utils.d.ts",
"import": "./dist/utils.mjs",
"require": "./dist/utils.cjs"
}
},
"main": "./lib/index.cjs",
"module": "./dist/index.mjs",
"browser": "./dist/index.browser.mjs",
"browser": "./dist/browser.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion src/index.basic.ts → src/basic.ts
Expand Up @@ -3,7 +3,7 @@ import type { ConsolaOptions } from "./types";
import { BasicReporter } from "./reporters/basic";
import { ConsolaInstance, createConsola as _createConsola } from "./consola";

export * from "./index.shared";
export * from "./shared";

export function createConsola(
options: Partial<ConsolaOptions & { fancy: boolean }> = {}
Expand Down
2 changes: 1 addition & 1 deletion src/index.browser.ts → src/browser.ts
Expand Up @@ -2,7 +2,7 @@ import { BrowserReporter } from "./reporters/browser";
import { createConsola as _createConsola } from "./consola";
import type { ConsolaOptions } from "./types";

export * from "./index.shared";
export * from "./shared";

export function createConsola(options: Partial<ConsolaOptions> = {}) {
const consola = _createConsola({
Expand Down
2 changes: 1 addition & 1 deletion src/consola.ts
@@ -1,6 +1,6 @@
import { defu } from "defu";
import { LogTypes, LogType, LogLevel } from "./constants";
import { isLogObj } from "./utils/index";
import { isLogObj } from "./utils/log";
import type {
ConsolaReporter,
InputLogObject,
Expand Down
2 changes: 1 addition & 1 deletion src/index.core.ts → src/core.ts
@@ -1,2 +1,2 @@
export { createConsola } from "./consola";
export * from "./index.shared";
export * from "./shared";
2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -5,7 +5,7 @@ import { BasicReporter } from "./reporters/basic";
import { FancyReporter } from "./reporters/fancy";
import { ConsolaInstance, createConsola as _createConsola } from "./consola";

export * from "./index.shared";
export * from "./shared";

export function createConsola(
options: Partial<ConsolaOptions & { fancy: boolean }> = {}
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions src/utils.ts
@@ -0,0 +1,9 @@
export * from "./utils/box";

export {
stripAnsi,
centerAlign,
rightAlign,
leftAlign,
align,
} from "./utils/string";
File renamed without changes.
4 changes: 2 additions & 2 deletions src/utils/string.ts
Expand Up @@ -3,9 +3,9 @@
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
].join("|");

export const stripAnsi = (text: string) => {
export function stripAnsi(text: string) {
return text.replace(new RegExp(ansiRegex, "g"), "");
};
}

Check warning on line 8 in src/utils/string.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/string.ts#L8

Added line #L8 was not covered by tests

export function centerAlign(str: string, len: number, space = " ") {
const free = len - str.length;
Expand Down