Code Monkey home page Code Monkey logo

zimple's Introduction

Zimple Build Status Coverage Status

A lightweight utility belt

Concept

Zimple or Z is an utility belt for JavaScript developers. It is a versatile and simple way to handle small pieces of reusable code (or plugins) in your application.

Z has a beautiful jQuery-like making it simple and easy to use its plugins.

Goal

The goal of this project is to be a good experience for me about JS optimization.
In all honestly I would not recommend using Zimple. Use something like lodash instead.

Plugins

View the list of plugins from here The plugin list is small at the moment, but with any luck its going to grow.

API

  1. #fn('plugin name', pluginFn, [options]) registers Z plugin
    Options are optional. By default they are set as empty object.

Usage

using plugins

There are three designed ways to use Z plugins.

  1. direct call
  2. wrapped call
  3. calling from another plugin
direct call:

Directly calling a plugin from Z. The first parameter of the call is considered to be the context and all additional parameters will be considered as arguments.

    Z.fn('sum', function(context, args) { return context + args });
    Z.sum(1, 2); // 3
    Z.sum(5, 8); // 13
wrapped call:

Wrapping means that the context value will be wrapped in Z. This means that all the function call parameters will be passed in to the plugin after the context parameter.

    Z.fn('sum', function(context, args) { return context + args });
    Z(1).sum(2); // 3
    Z(5).sum(8); // 13
calling from another plugin:

Calling from inside plugins with this keyword means that the original plugin will be directly called. No context prepending will happen in this case.

    Z.fn('sum', function(a, b) { return a + b });
    Z.fn('sumArray', function(arr) { return arr.reduce(this.sum); });
    Z([1,5,6]).sumArray() // 12
    Z.sumArray([1,5,6]) // 12

Creating plugins

Plugin creation is extremely easy with Z. All you need to do is to register your plugin via #fn method. This registers the plugin globally for Z and ca be instantly used.

There are no safety measurements taken to preserve predefined plugins, meaning that its very easy to overwrite previously defined plugins.

    Z.fn('sum', function(a, b) { return a + b });

In case any plugins need extra information about previously registered plugins, then there is also an option to register plugin specific options.

    Z.fn('sum', function(a, b) { return a + b }, { option : 'value' });

Options can be received from Z.prototype.__plugins

Licence

MIT

zimple's People

Contributors

kirstein avatar

Watchers

 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.