Skip to content

A versatile variable handling library for JavaScript and TypeScript.

Notifications You must be signed in to change notification settings

zakyyudha/varcraft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VarCraft

A versatile variable handling library for JavaScript and TypeScript.

npm version GitHub issues GitHub stars License

Table of Contents

Installation

npm install @zakyyudha/varcraft

Usage

Basic Example

import VarCraft from '@zakyyudha/varcraft';

VarCraft.set('x', 42);
console.log(VarCraft.get('x')); // Output: 42

Advanced Usage

VarCraft is designed to handle complex scenarios involving variable management and manipulation. Here are some advanced use cases:

Dynamic Variable Creation

You can dynamically create variables based on certain conditions or user input:

import VarCraft from '@zakyyudha/varcraft';

function createDynamicVariable(name: string, condition: boolean, valueIfTrue: any, valueIfFalse: any): void {
  const value = condition ? valueIfTrue : valueIfFalse;
  VarCraft.set(name, value);
}

createDynamicVariable('isProduction', process.env.NODE_ENV === 'production', true, false);
console.log(VarCraft.get('isProduction')); // Output: true or false

Variable Transformation

VarCraft allows you to transform variables using custom functions:

import VarCraft from '@zakyyudha/varcraft';

function transformVariable(name: string, transformationFunction: (value: any) => any): void {
  const originalValue = VarCraft.get(name);
  const transformedValue = transformationFunction(originalValue);
  myVarCraft.set(name, transformedValue);
}

// Example: Convert a string to uppercase
VarCraft.set('message', 'hello');
transformVariable('message', (value) => value.toUpperCase());
console.log(VarCraft.get('message')); // Output: 'HELLO'

Variable Dependencies

Manage variables that depend on each other by updating them accordingly:

import VarCraft from '@zakyyudha/varcraft';

VarCraft.set('x', 5);

function updateDependentVariable(): void {
  const x = VarCraft.get('x');
  VarCraft.set('y', x * 2);
}

updateDependentVariable();
console.log(VarCraft.get('y')); // Output: 10

About

A versatile variable handling library for JavaScript and TypeScript.

Resources

Stars

Watchers

Forks

Packages

No packages published