Coder Social home page Coder Social logo

key-book's Introduction

Build Status

key-book 🔑

Create string reference look ups from a string array in JavaScript ❄️

Pass key-book an array of strings with an optional prefix/suffix and it will return a frozen object that you can use as a look up.

Mitigate the risk of string typos in your applications where errors aren't likely to be thrown.

Usage

const mirror = require('key-book');

const enums = mirror(["A", "B", "C"]);

enums; // {A: "A", B: "B", C: "C"}

enums.A = "B";

enums; // {A: "A", B: "B", C: "C"}

const prefixedEnums = mirror(["A", "B", "C"], "PREFIX_");

prefixedEnums; // {PREFIX_A: "PREFIX_A", PREFIX_B: "PREFIX_B", PREFIX_C: "PREFIX_C"}

const suffixedEnums = mirror(["A", "B", "C"], undefined, "_SUFFIX");

suffixedEnums; // {A_SUFFIX: "A_SUFFIX", B_SUFFIX: "B_SUFFIX", C_SUFFIX: "C_SUFFIX"}

Background

I wrote about the rationale for using a package like key-book in this article.


@jh3y 2019 MIT

key-book's People

Contributors

jh3y avatar

Stargazers

Alexander avatar Gav avatar Ian Read avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

alexrogalskiy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.