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

@fluentfixture/format

v1.0.6

Published

A flexible string format library that is a part of @fluentfixture project.

Downloads

55

Readme

Philosophy

In Informatics, dummy data is benign information that does not contain any useful data, but serves to reserve space where real data is nominally present. Dummy data can be used as a placeholder for both testing and operational purposes. For testing, dummy data can also be used as stubs or pad to avoid software testing issues by ensuring that all variables and data fields are occupied. (↪wiki)

Generating dummy data is crucial in software development. The quality of test data directly impacts development quality and velocity. There are many dummy data generators in the JavaScript ecosystem. However, creating complex objects and responding to real-world use cases can be challenging.

The @fluentfixture aims to provide a fluent interface and an extensible architecture for generating dummy data.

The @fluentfixture doesn't provide predefined data like FakerJS but offers multiple adapters for integration with external libraries.

Documentation

Visit https://docs.fluentfixture.com to view the full documentation.

Introduction

Core (@fluentfixture/core)

The @fluentfixture/core provides various data generators for different use cases. All generators offer a fluent interface for manipulating data, including sorting, creating conditional values, and more.

Installation

$ npm install @fluentfixture/core

Example

Let us consider the following requirements. We need;

  • One hundred products that are ordered by their prices,
  • Each product has a price that ends with .95,
  • Each product has a code field with the "id-color" format calculated using generated values,
  • Each product has the same parent category with random id and name but the same type.
  • Half of them have stock.
import { alphabetic, bool, hex, int, obj, pick } from '@fluentfixture/core';

// Defines a price generator with amount and the currency fields.
const price = obj({
  amount: int(100, 1000).add(0.95),
  currency: pick(['USD', 'EUR', 'GBP', 'TRY']),
});

// Defines a color generator. (hex + pad + uppercase)
const color = hex(6).padStart(7, '#').upperCase();

// Defines a category with constant id.
const category = obj({
  id: int(1, 100),
  name: alphabetic().headerCase(),
  type: alphabetic(4, 8).memo()
})

// Defines a product generator.
const product = obj({
  id: int(1, 999),
  name: alphabetic(10, 20).capitalCase(),
  category: category,
  description: alphabetic(20, 40).optional(),
  hasStock: bool(0.5),
  color: color,
  price: price,
});

// 1) Adds 'code' field using generated values.
// 2) Iterates the model.
// 3) Sorts the generated models by their prices.
const products = product
  .lazy('code', (p) => `${p.id}-${p.color}`)
  .array(10)
  .sort((a, b) => a.price.amount - b.price.amount);

// Print all products
console.log(products.single());

// Print details of the first product.
console.log(product.format('[${id}] ${name:titleCase()} => ${price.amount}'));

Format (@fluentfixture/format)

The @fluentfixture/format is a flexible string format library that provides formatting functionality with extensible formatting capability.

Installation

$ npm install @fluentfixture/format

Example

import { format } from '@fluentfixture/format';

const source = {
  name: 'john',
  surname: 'doe',
  email: '[email protected]',
  birthdate: new Date(1_617_258_460_000),
  balance: {
    amount: 120,
    currency: 'USD',
  },
  memberships: ['regular user', 'pro user'],
};

console.log(
  format('${surname}, ${name} <${balance.amount} ${balance.currency}>', source),
);

console.log(
  format('${surname:upperCase()}, ${name:capitalCase()} <${balance.amount} ${balance.currency}>', source),
);

console.log(
  format('${surname:upperCase()}, ${name:capitalCase()} BIRTH_DATE=${birthdate:date("MM-DD-YYYY")}', source),
);

console.log(
  format('${name}.${surname} > MEMBERSHIP=${memberships.0:dotCase()|upperCase()}', source),
);

console.log(
  format('NICKNAME=${name:padStart(7, "#")|padEnd(10,"#")}', source),
);

License

@fluentfixture is MIT licensed.