Coder Social home page Coder Social logo

detry322 / callbaxx Goto Github PK

View Code? Open in Web Editor NEW

This project forked from paulogdm/callbaxx

1.0 3.0 0.0 27 KB

🔥 JS utility library to bring classic callback style programming to synchronous code — Make JavaScript JavaScript Again!

License: MIT License

JavaScript 100.00%

callbaxx's Introduction

⭐️⭐️⭐️

🔥 Callbaxx 🔥

⭐️⭐️⭐️

GitHub issues npm bundle size (minified) GitHub stars

In recent years, a vocal portion of the JS community has forced the usage of "ES6" (essentially an entirely new language) onto the rest of the JS community. Proponents of this new language (known as "sixers") have been given free reign to make changes nobody asked for: a broken and incompatible module system, new language syntax like promises, async/await, rest/spread operators, "functional" features, and so on.

JavaScript is now virtually unrecognizable. In fact, many people new to the language aren't even familiar with callbacks.

This utility library aims to bring back classic JavaScript to the masses, with plenty of callbacks.

Who is it for 🤔

Whether you're a classic JS developer who understands the beauty of real JavaScript — which still works just fine by the way — or a new developer wary of current trends and looking for a timeless way to code for the web, this library is for you.

If you want to spend weeks playing around with webpacks and babble scripts and trying to keep up with new changes to the language, then this is not for you.

This library is for real programmers who aren't afraid to get their hands a little dirty with real code.

Roadmap 🚘

Callbaxx is a brand new NPM package and is still under development. Please submit PRs to add your own functions!

And feel free to suggest other ideas for how we can Make JavaScript JavaScript Again! Callbaxx is just part of what will hopefully be a wider movement.

Install 🖥

npm install callbaxx
var callbaxx = require('callbaxx');

All functions are error first. This means the first argument of the callback is an error (hopefully null), and the second argument is the result of the function.

Docs

Arrays

isArray()

Check if a value is an array

var isArray = require('callbaxx').isArray;

var myArr = [1, 2, 3];

isArray(myArr, function(err, res) {
  if (res) {
    console.log('Wow what an array! It has ' + myArr.length + ' items.');
  } else {
    console.log('Hmm that does not look like an array...');
  }
});

// Output: Wow what an array! It has 3 items.

map()

Returns a new array with a provided function called on each item of the provided array

var map = require('callbaxx').map;

map([1, 4, 9, 16, 25], Math.sqrt, function(err, res) {
  console.log(res);
});

// Output: [1, 2, 3, 4, 5]

reduce()

Smoosh a given array into a single value

var reduce = require('callbaxx').map;

reduce([1, 2, 3], function (a, b) { return a + b }, 0, function(err, res) {
    console.log(res);
});

// Output: 6

Booleans

isTrue()

Check if a value is equal to true

var isTrue = require('callbaxx').isTrue;

isTrue(true, function(err, res) {
  if (res) {
    console.log('It is true!');
  }
});

// Output: It is true!

isFalse()

Check if a value is equal to false

var isFalse = require('callbaxx').isFalse;

isFalse(123, function(err, res) {
  if (res) {
    console.log('It is false!');
  } else {
    console.log('It is NOT false!');
  }
});

// Output: It is NOT false!

Numbers

add()

Add two numbers together

var add = require('callbaxx').add;

add(40, 2, function(err, res) {
  console.log('The result is ' + res + '!');
});

// Output: The result is 42!

divide()

Divides the first number by the second number

var divide = require('callbaxx').divide;

divide(25, 5, function(err, res) {
  console.log(res);
});

// Output: 5

multiply()

Multiplies two numbers together

var multiply = require('callbaxx').multiply;

multiply(6, 7, function(err, res) {
  console.log(res);
});

// Output: 42

subtract()

Subtracts the second number from the first number

var subtract = require('callbaxx').subtract;

subtract(50, 8, function(err, res) {
  console.log('The result is ' + res + '!');
});

// Output: The result is 42!

isNumber()

Check if a value is a number

var isNumber = require('callbaxx').isNumber;

isNumber(123, function(err, res) {
  if (res) {
    console.log('Yes, that is a number');
  } else {
    console.log('No, that is not a number, sorry');
  }
});

// Output: Yes, that is a number

isNumber('string', function(err, res) {
  if (res) {
    console.log('Yes, that is a number');
  } else {
    console.log('No, that is not a number, sorry');
  }
});

// Output: No, that is not a number, sorry

isOdd()

Check if a number is odd

var isOdd = require('callbaxx').isOdd;

isOdd(11, function(err, res) {
  if (res) {
    console.log('Odd number detected!');
  }
});

// Output: Odd number detected!

isEven()

Check if a number is even

var isEven = require('callbaxx').isEven;

isEven(8, function(err, res) {
  if (res) {
    console.log('Even number detected!');
  }
});

// Output: Even number detected!

Objects

isObject()

Check if a value is an object

var isObject = require('callbaxx').isObject;
var isTrue = require('callbaxx').isTrue;

var myObj = { abc: 123 };

isObject(myObj, function(err1, objRes) {
  isTrue(objRes, function(err2, res) {
    if (res) {
      console.log('This is an object!');
    }
  });
});

// Output: This is an object!

Strings

toLowerCase()

Converts a string to lower case

var toLowerCase = require('callbaxx').toLowerCase;

toLowerCase('FoO BaR!', function(err, res) {
  console.log(res);
});

// Output: foo bar!

toUpperCase()

Converts a string to upper case

var toUpperCase = require('callbaxx').toUpperCase;

toUpperCase('hello world', function(err, res) {
  console.log(res);
});

// Output: HELLO WORLD

License

Callbaxx is MIT licensed.

callbaxx's People

Contributors

paulogdm avatar scf4 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.