SBG Utility

2.0.11 · active · verified Sun Apr 19

SBG Utility is a collection of helper functions and modules primarily designed to support the `static-blog-generator` ecosystem. It provides functionalities such as file management (reading, writing, checking file stats), date mapping, and logging utilities. The current stable version is `2.0.11`. As a sub-package within a larger monorepo, its release cadence is tied to the main project, though specific updates for `sbg-utility` are less frequent. Key differentiators include its tight integration with the `static-blog-generator`'s internal workings and its CommonJS base with TypeScript type definitions, making it usable in both legacy and modern Node.js environments.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates reading from and writing to files using `sbg-utility`'s file manager functions, along with logging capabilities.

import { read, write, debug } from 'sbg-utility';
import { join } from 'path';
import { existsSync, mkdirSync } from 'fs';

const outputDir = join(__dirname, 'temp_output');
if (!existsSync(outputDir)) {
  mkdirSync(outputDir, { recursive: true });
}

const filePath = join(__dirname, 'example.txt');
const outputPath = join(outputDir, 'output.txt');

async function runUtilityExample() {
  debug('Starting SBG Utility example...');
  try {
    // Create a dummy file for reading
    await write(filePath, 'Hello from sbg-utility!', 'utf8');
    debug(`Written to ${filePath}`);

    const content = await read(filePath, { encoding: 'utf8' });
    debug(`Read content: ${content}`);

    await write(outputPath, `Processed: ${content.toUpperCase()}`, 'utf8');
    debug(`Transformed and written to ${outputPath}`);
  } catch (error) {
    console.error('An error occurred:', error);
    debug('Example failed.', 'error');
  }
  debug('SBG Utility example finished.');
}

runUtilityExample();

view raw JSON →