npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kouovo/ph-shared

v0.1.46

Published

A TypeScript library providing shared utilities for generating Pug resources manifests and locale files from directory structures.

Readme

@kouovo/ph-shared

A TypeScript library providing shared utilities for generating Pug resources manifests and locale files from directory structures.

Overview

The @kouovo/ph-shared package provides utilities for automatically generating Pug template files from resource directories and locale JSON files. It's designed to streamline the process of managing static assets and internationalization in Pug-based projects.

Installation

npm install @kouovo/ph-shared
# or
pnpm add @kouovo/ph-shared
# or
yarn add @kouovo/ph-shared

Features

  • Resource Manifest Generation: Automatically scan directories for images and media files and generate Pug variable definitions
  • Locale File Generation: Convert JSON locale files to Pug template files with translation functions
  • TypeScript Support: Fully typed with comprehensive interfaces
  • Error Handling: Comprehensive error handling with detailed error messages
  • Flexible Configuration: Customizable prefix and output paths

API Reference

generatePugResourcesManifest(inputDir, outputPugFile, prefix?)

Scans a directory for supported media files and generates a Pug file with variable definitions.

Parameters

  • inputDir: string - Path to the directory containing resource files
  • outputPugFile: string - Path where the generated Pug file should be written
  • prefix: string - Optional prefix for resource paths (default: "~")

Supported File Types

  • Images: .png, .jpg, .jpeg, .svg
  • Videos: .mp4, .flv

Example

import { generatePugResourcesManifest } from '@kouovo/ph-shared';

await generatePugResourcesManifest(
  './src/assets',
  './src/_resources.pug',
  '~assets/'
);

Generated Output

//- Auto-generated by script. Do not edit manually.
-
  const $ = {
    "logo": "~assets/logo.png",
    "icons_home": "~assets/icons/home.svg",
    "banner_video": "~assets/videos/banner.mp4"
  }

Features

  • Recursive Directory Scanning: Automatically scans subdirectories
  • Path Normalization: Converts file paths to web-compatible format
  • Duplicate Handling: Automatically renames duplicate keys with numeric suffixes
  • Clean Variable Names: Generates clean, camelCase variable names from file paths
  • Directory Structure Preservation: Maintains directory structure in variable names

generatePugLocaleFiles(inputDir, outputDir)

Converts JSON locale files to Pug template files with translation functions.

Parameters

  • inputDir: string - Path to the directory containing JSON locale files
  • outputDir: string - Path where the generated Pug files should be written

Example

import { generatePugLocaleFiles } from '@kouovo/ph-shared';

await generatePugLocaleFiles(
  './locales',
  './src/locales'
);

Input Structure

locales/
├── en.json
├── zh.json
└── ar.json

en.json:

{
  "welcome": "Welcome",
  "goodbye": "Goodbye",
  "navigation": {
    "home": "Home",
    "about": "About"
  }
}

Generated Output

src/locales/en.pug:

//- Auto-generated by script. Do not edit manually.
//- Source: locales/en.json
//- Target: src/locales/en.pug

-
  var _en = {
    "welcome": "Welcome",
    "goodbye": "Goodbye",
    "navigation": {
      "home": "Home",
      "about": "About"
    }
  }

src/locales/t.pug:

//- Auto-generated by script. Do not edit manually.

- var _translations = {}

if __LANG__ == 'en'
  include ./en.pug
  - _translations = _en
else if __LANG__ == 'zh'
  include ./zh.pug
  - _translations = _zh
else if __LANG__ == 'ar'
  include ./ar.pug
  - _translations = _ar
else
  // No language files found or matched, _translations remains {}

//- Translation function
-
  function $t(key) {
    var value = _translations[key];
    if (typeof value === 'undefined') {
      return `Missing translation for key: ${key}`;
    }
    return value;
  }
mixin pp(key)
  p&attributes(attributes)
    - const v = $t(key)
    - if (Array.isArray(v))
      each val in v
        span !{val}
    - else
      span !{v}

Features

  • Automatic Default Creation: Creates default locale files if none exist
  • Parallel Processing: Processes multiple locale files concurrently
  • Translation Function: Generates a $t() function for easy translation access
  • Pug Mixin: Includes pp() mixin for paragraph elements with translation
  • Fallback Handling: Provides fallback messages for missing translations
  • Error Recovery: Continues processing even if individual files fail

Usage in Pug Templates

Using Resource Manifest

include _resources.pug

img(src=$.logo alt="Logo")
video(src=$.banner_video)

Using Locale System

include locales/t.pug

h1= $t('welcome')
+pp('goodbye')
p= $t('navigation.home')

Error Handling

Both functions include comprehensive error handling for:

  • File System Errors: Missing directories, permission issues
  • JSON Parsing Errors: Invalid JSON format in locale files
  • Path Resolution: Invalid input/output paths
  • Duplicate Resources: Automatic renaming with warnings

Default Locale Configuration

When no locale files exist, the system creates default files for:

  • en.json (English)
  • zh.json (Chinese)
  • ar.json (Arabic)

Each with a simple example structure:

{
  "example": "hello world"
}

TypeScript Support

The package is fully typed with interfaces for:

  • TranslationData - Nested translation object structure
  • ImageData - Resource path mappings
  • All function parameters and return types

Performance Features

  • Parallel Processing: Resource scanning and locale processing use parallel execution
  • Efficient File Operations: Uses async/await with proper error handling
  • Memory Optimization: Streams file operations where possible
  • Recursive Directory Scanning: Efficiently handles nested directory structures

License

MIT