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 🙏

© 2024 – Pkg Stats / Ryan Hefner

loadee

v3.1.2

Published

A utility for loading and parsing YAML, JSON, and JS files.

Downloads

275

Readme

loadee

A utility to simplify the loading of various types of files, including YAML, JSON, and CommonJS or ES modules. This module provides both synchronous and asynchronous functions for loading data and modules based on file extensions.

Install

You can install loadee using npm or yarn:

npm i loadee
# or
yarn add loadee

Usage

To use loadee, you can import it into your JavaScript or TypeScript project and utilize its various functions for loading files and modules.

Asynchronous Loading

loadFile<T = any>(pathlike: PathLike, cwd?: string, ...args: unknown[]): Promise<T>

Loads data from a file asynchronously based on its file extension.

  • pathlike: The path-like value representing the file.
  • cwd (optional): The current working directory. Defaults to the process's current working directory.
  • ...args (optional): Additional arguments to pass to the loaded module if it's a function.

To load data from a YAML file asynchronously:

import { loadFile } from 'loadee'

try {
  const data = await loadFile('data.yaml')
  console.log('Loaded YAML data:', data)
} catch (error) {
  console.error('Error loading YAML data:', error)
}

To load data from a JSON file asynchronously:

import { loadFile } from 'loadee'

try {
  const data = await loadFile('data.json')
  console.log('Loaded JSON data:', data)
} catch (error) {
  console.error('Error loading JSON data:', error)
}

To load a CommonJS or ES module from a JavaScript file asynchronously:

import { loadFile } from 'loadee'

try {
  const module = await loadFile('module.js')
  console.log('Loaded JavaScript module:', module)
} catch (error) {
  console.error('Error loading JavaScript module:', error)
}

Synchronous Loading

loadFileSync<T = any>(pathlike: PathLike, cwd?: string, ...args: unknown[]): T

Loads data from a file synchronously based on its file extension.

  • pathlike: The path-like value representing the file.
  • cwd (optional): The current working directory. Defaults to the process's current working directory.
  • ...args (optional): Additional arguments to pass to the loaded module if it's a function.

To load data from a YAML file synchronously:

import { loadFileSync } from 'loadee'

try {
  const data = loadFileSync('data.yaml')
  console.log('Loaded YAML data:', data)
} catch (error) {
  console.error('Error loading YAML data:', error)
}

To load data from a JSON file synchronously:

import { loadFileSync } from 'loadee'

try {
  const data = loadFileSync('data.json')
  console.log('Loaded JSON data:', data)
} catch (error) {
  console.error('Error loading JSON data:', error)
}

To load a JavaScript file synchronously:

import { loadFileSync } from 'loadee'

try {
  const module = loadFileSync('module.js')
  console.log('Loaded CommonJS:', module)
} catch (error) {
  console.error('Error loading CommonJS:', error)
}

NOTE: The loadFileSync function cannot be used to load ES module files. When you attempt to load a .js file using this function, it will be treated as a CommonJS module.

Supported File Types

loadee supports loading the following file types:

  • .yaml and .yml files: Loaded asynchronously and synchronously.
  • .json files: Loaded asynchronously and synchronously.
  • .js, .mjs, and .cjs files: Loaded asynchronously and synchronously.

Related

  • rcfy – Finds and loads runtime-configuration file for the current project with precedence.

Contributing

We 💛  issues.

When committing, please conform to the semantic-release commit standards. Please install commitizen and the adapter globally, if you have not already.

npm i -g commitizen cz-conventional-changelog

Now you can use git cz or just cz instead of git commit when committing. You can also use git-cz, which is an alias for cz.

git add . && git cz

License

GitHub

A project by Stilearning © 2021-2024.