1.4.1 • Published 4 months ago

varex v1.4.1

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

Install package:

npm i varex
const { varEx } = require("varex");

varEx("Any string you want plus a $[variable] block", objectToResolveFrom);
// Include varEx
const { varEx } = require("varex");

// This is the object we use to resolve variables
const object = {
  var1: "Example",
  var2: "Yet another one",
  var3: "You can even include [] brackets here, even $[variable blocks] doesn't break this",
  varObj: {
    var1: "Supports nesting as well!",
    varArray: ["Need arrays? Have at it!"],
  },
};

// Output the result
console.log(
  varEx(
    "This is an $[var1], and here is $[var2]. $[var3]. $[varObj.var1] $[varObj.varArray[0]]",
    object
  )
);

VarEx only aims to solve the problem of resolving variables you don't yet have access to (but know you will), when writing the template.

This is the table component that spawned the need for this function:

<List
  data={{
    headers: [
      {
        title: "Coffee Type",
        data: " ($[bean_type.product_name.grams_of_coffee] g)",
      },
      {
        title: "Grinding",
        data: "$[grinding_setting]",
      },
      {
        title: "Water",
        data: "$[water_in_liter] l",
      },
    ],
    items: this.state.items,
  }}
  filters={this.state.filters}
/>

The part where VarEx came in handy was in the data part, where we try to resolve the data with a certain format. Sure this doesn't need a function like VarEx to begin with, but having to constantly repeat simple but slightly different table formatting functions each time, eventually taints the codebase. I wanted a reusable function to format each different table with an already defined format config.

data: " ($[grams_of_coffee] g)";

Using VarEx it really was as simple as creating a table component that runs VarEx() on every item displayed. No need to create a custom switch case for displaying water in liters, coffee beans in grams and so on.

1.4.1

4 months ago

1.4.0

8 months ago

1.3.0

8 months ago

1.2.0

1 year ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago