Giter Club home page Giter Club logo

ylib.js's Introduction

ylib.js

YLib is a small js library containing several useful features for developers. It consists of several code modules and can be built with different configurations. By default available configurations are "core" (minimal), "default" (usually needed features) and "full" (all modules).

See release folder to download production ready uncompressed or minified versions of YLib.

Modules

YLib.Class

YLib.Class allows to build and inherit/extend javascript classes.

var MyClass = YLib.Class.extend({
  className: 'MyClass', // useful for debugging, will be shown when logging MyClass / new MyClass().
  statics: {}, // props defined here will be available at MyClass.propName
  includes: ["Events"], // array of string names. Used for loading Mixins from YLib.Mixins[name].
  initialize: function(arg1,arg2) {}, // will be called when executing new MyClass(arg1,arg2).
  
  someNewProp: "My new property",
  someNewMethod: myMethod() {},
});
var MyChildClass = MyClass.extend({
  className: 'MyChildClass',
  includes: ["Hooks"], // Child Class has Events and Hooks now
  initialize: function(arg1,arg2) {
    MyClass.prototype.initialize.call(this,arg1,arg2);
  }, 
  someNewProp: "My new child property", // overrides someNewProp of MyClass
});
var theInstance = new MyChildClass('test1','test2');

YLib.Mixin

Mixins can be used to "mix in" additional functionality to YLib.Classes where needed.

Events

Events mixin adds possibility to listen to and fire events on the Class. When mixed in following methods are available:

  • addEventListener(eventType,listenerFunction,[functionContext],[justOnce])
  • hasEventListeners(eventType)
  • removeEventListener(eventType,listenerFunction,[functionContext]
  • clearAllEventListeners()
  • fireEvent(eventType,additionalData) (listeners will receive an argument like {eventType:'X',target:theClass,...additionalData}. )

There are shorthand aliases available for these functions: on(), off(), once(), fire().

Hooks

Hooks are similar to Events. But instead of Events the listeners are not passive. Instead they may modify/add data actively.

  • addHookSubscriber(eventType,listenerFunction,[functionContext],[justOnce])
  • hasHookSubscriber(eventType)
  • removeHookSubscriber(eventType,listenerFunction,[functionContext]
  • removeAllHookSubscribers()
  • callHook(eventType,theData)

Shorthand methods: addHook, removeHook

obj.addHook('myhook',function(hook,data) { data.modified = true }
var data = { stuff:true };
obj.callHook('myhook',data);
// data is { stuff:true, modified:true } now.

YLib.Tools

Requires jQuery. Currently only provides a simple implementation of tabs.

YLib.Util

Contains several useful misc functions.

  • YLib.Util.extend(obj,...) - merges all argument objects into obj. (shallow, replaces arrays and objects.)
  • YLib.Util.extendConcat(obj,...) - merges all argument objects into obj. (shallow, merges arrays)
  • YLib.Util.extendDeep(obj,...) - merges all argument objects into obj. (recursively)
  • YLib.Util.bind(fct,context) - returns a fct bound to new context
  • YLib.Util.invokeEach(obj,method,context) - calls method for all properties of obj.
  • YLib.Util.limitExecByInterval(fct,interval,context) - returns a new function which will block calls of fct when called more frequently than interval (ms).
  • YLib.Util.formatNum(number,digits) - ??
  • YLib.Util.trim(str) - removes spaces at the start and end of string.
  • YLib.Util.splitWords(str) - splits string into an array of words.
  • YLib.Util.template - ??
  • YLib.Util.isArray(theVar) - returns true if theVar is an array
  • YLib.Util.isObject(theVar) - returns true if theVar is a object
  • YLib.Util.htmlSpecialChars(str) - implementation of phps htmlSpecialChars
  • YLib.Util.formatBytes(bytes) - returns formatted number (KB/MB/GB)
  • YLib.Util.template - ??
  • YLib.Util.template - ??

YLib.Util.objPath

Allows to set/get deep variables by string:

YLib.Util.get(obj,'config.global.url'); // returns obj.config.global.url
YLib.Util.set(obj,'config.global.contents.2.name','newName'); // sets obj.config.global.contents[2].name = 'newName'

YLib.Util.sprintf

Implementation of PHP's sprintf

YLib.Util.url

get URL Parameters by calling YLib.Util.getURLParams(url)

YLib.Util.uuid

Generate UUIDs by calling YLib.Util.uuid()

building

git clone https://github.com/jbjhjm/ylib.js.git

Change to development directory and run npm install.

use grunt build:[configuration_id] to create a package. See configurations folder to add custom build targets.

ylib.js's People

Contributors

jbjhjm avatar

Stargazers

YOOlabs avatar

Watchers

James Cloos 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.