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

format-fast

v1.0.2

Published

format-fast is a function that allows you to replace certain words to make a text string dynamically, and very easily !

Downloads

810

Readme

format-fast

Hi, I'm Yoni Calsin, I'd love you to give format-fast a chance, to shine inside your project, and to format a text string in a wonderful way, and of course with less code.

Format-fast is a function that allows you to replace certain words to make a string dynamically, and very easily !

🍉 Installation

First we will have to install, in order to use this wonderful package.

# Using npm
npm install --save format-fast

# Using yarn
yarn add format-fast

🌎 Usage

Format-fast use is-all-utils to validate the format of different characteristics !

First we import the function, as follows !

To use format-fast you can use the formatFast or f function, they are practically the same, only f is very short !

// For Typescript
import formatFast from 'format-fast';
// Or
import { f } from 'format-fast';

// Javascript
const formatFast = require('format-fast');
// or
const { f } = require('format-fast');

Individually

If you want to send just one piece of information !

const msg = "Hello, I'm '$0' years old";
f(msg, 20);
//=> Hello, I'm '20' years old

Array

The time has come to use format-parse, using an array

const msg = "The '$0' of user '$1' is not defined within the object '$2";

f(msg, ['name', 20, 'users']);
//=> The 'name' of user '20' is not defined within the object 'users

Object

Soon we will use it with an object !

const msg =
   "The '$property' of the user '$id' is not defined within the object '$data'";

f(msg, {
   property: 'name',
   id: 20,
   data: 'users',
});
//=> The 'name' of the user '20' is not defined within the object 'users'

Iteration function!

Function to modify the value, and the key when each object is iterated !

const msg = "Hi, I'm '$fullname', I'm '$age' years old";

const iterateItem = (value, key) => {
   console.log(value, key);
   // 0: Yoni Calsin, fullname
   // 1: age, age

   if (key == 'age') {
      if (value > 18) {
         value = 40;
      } else {
         value = 5;
      }
   }

   if (key == 'fullname') {
      value = `🎉 ${value}`;
   }

   return value;
};

f(
   msg,
   {
      fullname: 'Yoni Calsin',
      age: 20,
   },
   iterateItem,
);
// => Hi, I'm '🎉 Yoni Calsin', I'm '40' years old

f(
   msg,
   {
      fullname: 'Samuel Calsin',
      age: 10,
   },
   iterateItem,
);
// => Hi, I'm '🎉 Samuel Calsin', I'm '5' years old

Returning the iterateItem function, as an array, if you return an array of two values, you will be replacing the key, and the

const iterateItem = (value, key) => {
   // This will replace the values
   // this works if you return two values
   return [
      // For value
      value,
      // For key
      key,
   ];
};

Brackets

  • %s is the value of the key
const msg = "Hi, I'm '{0}'.";

f(msg, ['Yoni Calsin'], '{%s}');

// => Hi, I'm 'Yoni Calsin'.

Otro ejemplo

const msg = "Hi, I'm '[[0]]'.";

f(msg, ['Yoni Calsin'], '[[%s]]');

// => Hi, I'm 'Yoni Calsin'.
f(msg, replaces, brackets);
// Or
f(msg, replaces, iterateFunction, brackets);

⭐ Support for

format-fast is an open source project licensed by MIT. You can grow thanks to the sponsors and the support of the amazing sponsors. If you want to join them, contact me here.

🎩 Stay in touch

🚀 Contributors

Thanks to the wonderful people who collaborate with me !

📜 License

format-fast under License MIT.