simply-simple

1.2.0 • Public • Published

simply-simple

simply is an npm package that allows you to generate random values and replace them within a string. It provides placeholders that can be used in a template and replaced with random strings, numbers, booleans, or hexadecimal colors.

Installation

Install Simply using npm:

npm install simply-simple

Usage

Import Simply into your project:

const simply = require('simply-simple');

Placeholder Patterns

Simply uses specific placeholder patterns to identify the placeholders in your template:

{random_string}: Replaced with a random string.
{random_number(min, max)}: Replaced with a random number within the specified range.
{random_bool}: Replaced with a random boolean value.
{random_hex}: Replaced with a random hexadecimal color.
Example
const template = 'Hello, {random_string}! Your lucky number is {random_number(1, 100)}. Are you happy? {random_bool}. Your favorite color is {random_hex}.';
const result = simply(template);
console.log(result);
Output:
Hello, kgDz9RJ0! Your lucky number is 42. Are you happy? true. Your favorite color is #3A7BFF.

In the above example, the placeholders in the template are replaced with random values using the simply function.

Why?

By encapsulating the functionality in a package, you can easily reuse the random value generation and placeholder replacement logic across multiple projects or modules. This promotes code reusability and avoids duplication of code.

// Without Simply package
const generateRandomNumber = (min, max) => {
  // Custom implementation for generating a random number
};

const generateRandomString = (length) => {
  // Custom implementation for generating a random string
};

const template = 'Hello, {random_string}! Your lucky number is {random_number(1, 100)}.';
// Manually implement placeholder replacement logic using generateRandomString and generateRandomNumber functions

// With Simply package
const simply = require('simply-simple');

const template = 'Hello, {random_string}! Your lucky number is {random_number(1, 100)}.';
const result = simply(template);

Readme

Keywords

none

Package Sidebar

Install

npm i simply-simple

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

3.96 kB

Total Files

3

Last publish

Collaborators

  • sceptor