🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@01.works/console

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@01.works/console - npm Package Compare versions

Comparing version
0.1.0
to
0.1.1
+25
-9
dist/branding.d.ts

@@ -0,7 +1,18 @@

/** Options accepted by every branding printer invocation. */
export type BrandingOptions = {
console?: Pick<Console, "group" | "groupEnd" | "info">;
/**
* Console-compatible target. Banner printers use `info`; group branding uses
* all three methods.
*/
console?: BrandingConsole;
};
/** Console surface accepted by branding printers. */
export type BrandingConsole = Pick<Console, "group" | "groupEnd" | "info">;
/** A once-guarded function that prints branding to the chosen console target. */
export type BrandingPrinter = (options?: BrandingOptions) => void;
/** A single labeled link group shown in the console. */
export type BrandingGroup = {
/** Caption shown before the link, for example "Website by". */
label: string;
/** Link printed in the console. */
link: string;

@@ -11,2 +22,3 @@ };

export type BrandingConfig = {
/** Groups to print. These fully replace the default preset. */
groups: BrandingGroup[];

@@ -19,11 +31,15 @@ };

*/
export declare function createBranding(config?: BrandingConfig): (options?: BrandingOptions) => void;
export declare function createBranding(config?: BrandingConfig): BrandingPrinter;
export type BrandingBannerConfig = {
/** Also print the 01.software banner after the default 01.works banner. */
includeSoftware?: boolean;
};
/**
* Create the default 01.works branding printer. For each brand it prints a
* single `console.info` log: the caption, the ASCII-art wordmark (figlet
* "Standard"), and then the URL right-aligned beneath the art. Uses a monospace
* `%c` style (no color) so the right-aligned URL stays flush, and no console
* groups. Shows at most once per instance and is SSR-safe (no `window` access,
* no import-time side effects).
* Create the default 01.works branding printer. It prints one `console.info`
* log: the caption, the ASCII-art wordmark (figlet "Standard"), and then the
* URL right-aligned beneath the art. Pass `{ includeSoftware: true }` to also
* print the 01.software banner. Uses a monospace `%c` style (no color) so the
* right-aligned URL stays flush, and no console groups. Shows at most once per
* instance and is SSR-safe (no `window` access, no import-time side effects).
*/
export declare function createBrandingBanner(): (options?: BrandingOptions) => void;
export declare function createBrandingBanner(config?: BrandingBannerConfig): BrandingPrinter;
const DEFAULT_CONFIG = {
groups: [
{ label: "Website by", link: "https://01.works" },
{ label: "Powered by", link: "https://01.software" },
],
groups: [{ label: "Website by", link: "https://01.works" }],
};

@@ -37,6 +34,12 @@ /**

const MONO_STYLE = "font-family: monospace";
const DEFAULT_BANNERS = [
{ caption: "Website by", art: WORKS_ART, link: "https://01.works" },
{ caption: "Powered by", art: SOFTWARE_ART, link: "https://01.software" },
];
const WORKS_BANNER = {
caption: "Website by",
art: WORKS_ART,
link: "https://01.works",
};
const SOFTWARE_BANNER = {
caption: "Powered by",
art: SOFTWARE_ART,
link: "https://01.software",
};
/**

@@ -54,11 +57,14 @@ * Build the combined log for one brand: the caption on its own line, then the

/**
* Create the default 01.works branding printer. For each brand it prints a
* single `console.info` log: the caption, the ASCII-art wordmark (figlet
* "Standard"), and then the URL right-aligned beneath the art. Uses a monospace
* `%c` style (no color) so the right-aligned URL stays flush, and no console
* groups. Shows at most once per instance and is SSR-safe (no `window` access,
* no import-time side effects).
* Create the default 01.works branding printer. It prints one `console.info`
* log: the caption, the ASCII-art wordmark (figlet "Standard"), and then the
* URL right-aligned beneath the art. Pass `{ includeSoftware: true }` to also
* print the 01.software banner. Uses a monospace `%c` style (no color) so the
* right-aligned URL stays flush, and no console groups. Shows at most once per
* instance and is SSR-safe (no `window` access, no import-time side effects).
*/
export function createBrandingBanner() {
export function createBrandingBanner(config = {}) {
let hasShown = false;
const banners = config.includeSoftware
? [WORKS_BANNER, SOFTWARE_BANNER]
: [WORKS_BANNER];
return function show(options = {}) {

@@ -70,3 +76,3 @@ if (hasShown) {

const consoleTarget = options.console ?? globalThis.console;
for (const banner of DEFAULT_BANNERS) {
for (const banner of banners) {
consoleTarget.info(`%c${formatBanner(banner)}`, MONO_STYLE);

@@ -73,0 +79,0 @@ }

@@ -5,2 +5,2 @@ export * from "./core.js";

/** Show the default 01.works developer-console branding (once per instance). */
export declare const showBranding: (options?: import("./branding.js").BrandingOptions) => void;
export declare const showBranding: import("./branding.js").BrandingPrinter;

@@ -1,21 +0,28 @@

import { type BrandingConfig, type BrandingGroup, type BrandingOptions } from "./index.js";
import { type BrandingGroup, type BrandingOptions, type BrandingPrinter } from "./index.js";
/**
* Props for {@link Branding} and {@link useBranding}. A superset of
* {@link BrandingOptions} that also accepts the branding `groups` from
* {@link BrandingConfig}, so custom branding can be configured via props.
* Props for {@link Branding} and {@link useBranding}. With no props, the
* default 01.works banner is shown once app-wide.
*/
export type BrandingProps = Partial<BrandingConfig> & BrandingOptions;
export type BrandingProps = BrandingOptions & {
/** Custom group branding. When supplied, this fully replaces the default preset. */
groups?: BrandingGroup[];
/** Also show the 01.software banner. Ignored when `groups` is supplied. */
includeSoftware?: boolean;
};
/**
* Pick the branding printer for the given props. Returns the shared
* `showBranding` singleton when no `groups` are supplied (default 01.works,
* shown once app-wide), or a fresh `createBranding({ groups })` instance for a
* custom configuration. Exported for testing — prefer `<Branding>`.
* `showBranding` singleton when no `groups` or `includeSoftware` are supplied
* (default 01.works, shown once app-wide). With `includeSoftware`, returns a
* fresh banner instance that prints 01.works and 01.software. With `groups`,
* returns a fresh `createBranding({ groups })` instance and ignores
* `includeSoftware`. Exported for testing — prefer `<Branding>`.
*/
export declare function resolveBrandingShow(groups?: BrandingGroup[]): (options?: BrandingOptions) => void;
export declare function resolveBrandingShow(groups?: BrandingGroup[], includeSoftware?: boolean): BrandingPrinter;
/**
* React hook that shows developer-console branding once, after the component
* mounts. With no `groups`, it shows the default 01.works branding via the
* shared singleton (once app-wide). With `groups`, it builds a per-component
* branding instance — held in a ref so it survives React StrictMode's dev
* double-invoke — and shows it once per mount.
* shared singleton (once app-wide), or a per-component 01.works + 01.software
* banner instance when `includeSoftware` is true. With `groups`, it builds a
* per-component custom branding instance — held in a ref so it survives React
* StrictMode's dev double-invoke — and shows it once per mount.
*

@@ -22,0 +29,0 @@ * SSR-safe: the effect only runs on the client, so server rendering produces no

"use client";
import { useEffect, useRef } from "react";
import { createBranding, showBranding, } from "./index.js";
import { createBranding, createBrandingBanner, showBranding, } from "./index.js";
/**
* Pick the branding printer for the given props. Returns the shared
* `showBranding` singleton when no `groups` are supplied (default 01.works,
* shown once app-wide), or a fresh `createBranding({ groups })` instance for a
* custom configuration. Exported for testing — prefer `<Branding>`.
* `showBranding` singleton when no `groups` or `includeSoftware` are supplied
* (default 01.works, shown once app-wide). With `includeSoftware`, returns a
* fresh banner instance that prints 01.works and 01.software. With `groups`,
* returns a fresh `createBranding({ groups })` instance and ignores
* `includeSoftware`. Exported for testing — prefer `<Branding>`.
*/
export function resolveBrandingShow(groups) {
return groups ? createBranding({ groups }) : showBranding;
export function resolveBrandingShow(groups, includeSoftware = false) {
if (groups) {
return createBranding({ groups });
}
return includeSoftware
? createBrandingBanner({ includeSoftware })
: showBranding;
}

@@ -16,5 +23,6 @@ /**

* mounts. With no `groups`, it shows the default 01.works branding via the
* shared singleton (once app-wide). With `groups`, it builds a per-component
* branding instance — held in a ref so it survives React StrictMode's dev
* double-invoke — and shows it once per mount.
* shared singleton (once app-wide), or a per-component 01.works + 01.software
* banner instance when `includeSoftware` is true. With `groups`, it builds a
* per-component custom branding instance — held in a ref so it survives React
* StrictMode's dev double-invoke — and shows it once per mount.
*

@@ -26,6 +34,6 @@ * SSR-safe: the effect only runs on the client, so server rendering produces no

export function useBranding(props = {}) {
const { console: consoleTarget, groups } = props;
const { console: consoleTarget, groups, includeSoftware } = props;
const showRef = useRef(null);
if (showRef.current === null) {
showRef.current = resolveBrandingShow(groups);
showRef.current = resolveBrandingShow(groups, includeSoftware);
}

@@ -32,0 +40,0 @@ useEffect(() => {

{
"name": "@01.works/console",
"version": "0.1.0",
"version": "0.1.1",
"description": "Shared console utilities for 01.works",

@@ -5,0 +5,0 @@ "type": "module",

+70
-16

@@ -8,8 +8,11 @@ # @01.works/console

```sh
pnpm add @01.works/console
```
For a GitHub install before or outside npm publishing:
```sh
pnpm add github:01-office/console
```
After the package is published to npm, install it with
`pnpm add @01.works/console`.
## Usage

@@ -34,7 +37,6 @@

Logs the 01.works branding with `console.info`: one log per brand — the caption,
an ASCII-art wordmark for `01.works` / `01.software`, then the URL right-aligned
on the line below the art. Rendered in monospace (via `%c`, no color) so the
right-aligned URL stays flush; the bare URL is auto-linked by the browser
console. No console groups are used.
Logs the 01.works branding with `console.info`: the caption, an ASCII-art
wordmark for `01.works`, then the URL right-aligned on the line below the art.
Rendered in monospace (via `%c`, no color) so the right-aligned URL stays flush;
the bare URL is auto-linked by the browser console. No console groups are used.

@@ -49,6 +51,25 @@ Pass a console-compatible target when the message should use a specific logger:

type BrandingOptions = {
console?: Pick<Console, "group" | "groupEnd" | "info">;
console?: BrandingConsole;
};
type BrandingConsole = Pick<Console, "group" | "groupEnd" | "info">;
type BrandingPrinter = (options?: BrandingOptions) => void;
```
To include the 01.software banner from the core API, create an opt-in banner
printer:
```ts
import { createBrandingBanner } from "@01.works/console";
const show = createBrandingBanner({ includeSoftware: true });
show({ console: customConsole });
```
```ts
type BrandingBannerConfig = {
includeSoftware?: boolean;
};
```
## Console styling

@@ -94,8 +115,20 @@

});
show();
show({ console: customConsole });
```
`createBranding(config)` returns a once-guarded, SSR-safe `show()` function.
`showBranding()` is the default 01.works instance.
`showBranding()` is the default 01.works instance. Custom `groups` fully replace
the default preset.
```ts
type BrandingGroup = {
label: string;
link: string;
};
type BrandingConfig = {
groups: BrandingGroup[];
};
```
## React

@@ -135,7 +168,28 @@

Pass `includeSoftware` to include the 01.software banner alongside the default
01.works banner:
```tsx
<Branding includeSoftware />
```
All React variants accept a console-compatible target:
```tsx
<Branding includeSoftware console={customConsole} />
```
Both `Branding` and `useBranding` accept `BrandingProps` — the branding
`groups` plus an optional `console` target. With no `groups`, the default
01.works branding is shown once for the whole app; with `groups`, each mounted
component shows its configured branding once.
`groups`, optional `includeSoftware`, plus an optional `console` target. With no
`groups`, the default 01.works branding is shown once for the whole app; with
`includeSoftware`, 01.software is also shown. With `groups`, each mounted
component shows its configured branding once and `includeSoftware` is ignored.
```ts
type BrandingProps = BrandingOptions & {
groups?: BrandingGroup[];
includeSoftware?: boolean;
};
```
Prefer a hook? `useBranding()` does the same thing from inside your own client

@@ -154,4 +208,4 @@ component:

Both accept the same `BrandingProps` (branding `groups` plus an optional
`console` target).
Both accept the same `BrandingProps` (branding `groups`, optional
`includeSoftware`, plus an optional `console` target).

@@ -158,0 +212,0 @@ ## Development