{"id":11983,"library":"sbg-utility","title":"SBG Utility","description":"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.","status":"active","version":"2.0.11","language":"javascript","source_language":"en","source_url":"https://github.com/dimaslanjaka/static-blog-generator","tags":["javascript","static-blog-generator","utility","typescript"],"install":[{"cmd":"npm install sbg-utility","lang":"bash","label":"npm"},{"cmd":"yarn add sbg-utility","lang":"bash","label":"yarn"},{"cmd":"pnpm add sbg-utility","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Many utility functions like logging are re-exported directly from the root module for convenience, despite their internal file structure. The package is fundamentally CommonJS but provides TypeScript types, allowing for modern ESM import syntax.","wrong":"const debug = require('sbg-utility').log.debug;","symbol":"debug","correct":"import { debug } from 'sbg-utility';"},{"note":"File management functions `read` and `write` are directly available as named exports from the top-level package, simplifying their usage compared to accessing them via nested module properties.","wrong":"const { read, write } = require('sbg-utility').filemanager;","symbol":"read, write","correct":"import { read, write } from 'sbg-utility';"},{"note":"The package ships with TypeScript definitions. Always use `import type` for importing types to ensure they are stripped from the JavaScript output, preventing potential runtime errors or unnecessary bundle size.","wrong":"import { ReadOptions } from 'sbg-utility';","symbol":"ReadOptions (Type)","correct":"import type { ReadOptions } from 'sbg-utility';"}],"quickstart":{"code":"import { read, write, debug } from 'sbg-utility';\nimport { join } from 'path';\nimport { existsSync, mkdirSync } from 'fs';\n\nconst outputDir = join(__dirname, 'temp_output');\nif (!existsSync(outputDir)) {\n  mkdirSync(outputDir, { recursive: true });\n}\n\nconst filePath = join(__dirname, 'example.txt');\nconst outputPath = join(outputDir, 'output.txt');\n\nasync function runUtilityExample() {\n  debug('Starting SBG Utility example...');\n  try {\n    // Create a dummy file for reading\n    await write(filePath, 'Hello from sbg-utility!', 'utf8');\n    debug(`Written to ${filePath}`);\n\n    const content = await read(filePath, { encoding: 'utf8' });\n    debug(`Read content: ${content}`);\n\n    await write(outputPath, `Processed: ${content.toUpperCase()}`, 'utf8');\n    debug(`Transformed and written to ${outputPath}`);\n  } catch (error) {\n    console.error('An error occurred:', error);\n    debug('Example failed.', 'error');\n  }\n  debug('SBG Utility example finished.');\n}\n\nrunUtilityExample();","lang":"typescript","description":"Demonstrates reading from and writing to files using `sbg-utility`'s file manager functions, along with logging capabilities."},"warnings":[{"fix":"For CommonJS environments, explicitly use `const { func } = require('sbg-utility');`. For modern TypeScript/ESM projects, ensure your `tsconfig.json` and build tools (like Webpack, Rollup, esbuild) are configured to correctly handle CommonJS dependencies.","message":"While the package provides TypeScript types and supports ESM `import` syntax, it is fundamentally a CommonJS module. In environments where strict ESM loading is enforced (e.g., Node.js with `type: module` and no bundler), you might encounter issues. Prefer standard `require()` in pure CJS contexts or ensure your build system handles CJS interop for ESM imports.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Review the GitHub repository and source code for the `static-blog-generator` project to understand the full context and intended usage of these utilities, especially for advanced or less documented features.","message":"This `sbg-utility` package is part of a larger `static-blog-generator` monorepo. While usable standalone, its API and design choices are often influenced by its parent project's needs. Expect some functionalities to be tailored specifically for the static blog generator workflow.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are using correct named imports for ESM (`import { someFunction } from 'sbg-utility';`) or proper destructuring for CommonJS (`const { someFunction } = require('sbg-utility');`). This package does not have a default export.","cause":"Attempting to use a named export as a default import or incorrect destructuring in a CommonJS context.","error":"TypeError: (0, _sbg_utility.someFunction) is not a function"},{"fix":"Ensure that the module causing the error is loaded via `import` if it's an ES module. For `sbg-utility`, stick to `import` in TypeScript/ESM contexts or `require` in CJS contexts, respecting its underlying module type.","cause":"This error is unlikely for `sbg-utility` itself (as it's CJS), but if you're trying to `require()` an ES module that *depends* on `sbg-utility` in a mixed environment, or incorrectly configure your build, it might surface.","error":"ERR_REQUIRE_ESM: Must use import to load ES Module: ..."}],"ecosystem":"npm"}