Skip to content

Commit

Permalink
feat: consola/utils subpath export (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 27, 2023
1 parent 45ed7f1 commit 9e41614
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 20 deletions.
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 @@ const ansiRegex = [
"(?:(?:\\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"), "");
};
}

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

0 comments on commit 9e41614

Please sign in to comment.