Skip to content

Instantly share code, notes, and snippets.

View rjoydip-zz's full-sized avatar
💭
👨‍💻

Joydip Roy rjoydip-zz

💭
👨‍💻
View GitHub Profile
@rjoydip-zz
rjoydip-zz / arrayDimensionJqueryLikeModulePattern.js
Last active February 24, 2017 05:10
This is a simple array dimension library example which is build on like jquery (another kind of modular pattern example)
var fn = (function(){
/*
** This function is deciding whether array is either
** 2D or 1D or array is fully proper array or not.
** @params args taking arguments
** @params arg[0] : Array
** @params arg[1] : callback function
*/
function arrayDimention(){
@rjoydip-zz
rjoydip-zz / arrayDimensionConstractorPattern.js
Last active February 24, 2017 04:54
This is a simple array dimension plugin using constructor pattern
function RjLib(){
/*
** returning public function for the api
** this public function is accessable to user
*/
return {
arrayDimention : RjLib.prototype.arrayDimention
}
@rjoydip-zz
rjoydip-zz / arrayDimensionModularPattern.js
Created February 24, 2017 05:08
This is a simple array dimension plugin using modular pattern (not like jquery like pattern)
var arrayDimentionObject = {
arrayDimention : arrayDimentionFn,
f1 : f1
};
/*
** This function is deciding whether array is either
** 2D or 1D or array is fully proper array or not.
** @params args taking arguments
** @params arg[0] : Array
@rjoydip-zz
rjoydip-zz / RjLibBasic.js
Last active February 24, 2017 05:40
This is the basic library structure (it is following modular pattern)
var RjLib = (function RjLib() {
var _helloText = 'Hello world';
/*
** This constructor can be annoynomus
** or it can have function name
*/
// Return the constructor
return function(){
var _this = this; // Cache the `this` keyword
@rjoydip-zz
rjoydip-zz / RjLib.js
Last active February 26, 2017 05:58
This is my own library which has some helper function
(function (root, factory) {
if(typeof define === "function" && define.amd) {
// Now we're wrapping the factory and assigning the return
// value to the root (window) and returning it as well to
// the AMD loader.
define([""], function(postal){
return (root.RjLib = factory(postal));
});
} else if(typeof module === "object" && module.exports) {
// I've not encountered a need for this yet, since I haven't
@rjoydip-zz
rjoydip-zz / isNestedObjectLayerOne.js
Last active February 24, 2017 07:09
This work on object layer one
function traversObj(){
var args = Array.prototype.slice.call(arguments);
(args.length > 0) ? (typeof args[0] == 'object' && typeof args[1] == 'function') ? traverseObjFn(args[0],args[1]) : 'Arguments are incorrect' : 'Incorrect function arguments';
}
function isObject(obj){
return (typeof obj === 'object') ? true : false;
}
@rjoydip-zz
rjoydip-zz / isNestedObject.js
Created February 24, 2017 07:10
This function traverse the hole object and checking whether the object value of each layer has a nested object or not
function isObject(obj){
return (typeof obj === 'object') ? true : false;
}
function traverse (json, callback) {
JSON.parse(json, function (key, value) {
if (key !== '') {
callback.call(this, key, isObject(value))
}
return value
@rjoydip-zz
rjoydip-zz / isNestedObjectMyVersion.js
Last active February 24, 2017 08:26
This is my own object traversal function and returning whether a object has a nested object or not (using recursion)
function traverse (obj, callback) {
Object.keys(obj).forEach(function(value){
if (typeof obj[value] == 'object') {
traverse(obj[value],callback);
callback(value,true);
}
else {
callback(value,false)
}
});
@rjoydip-zz
rjoydip-zz / RjLib.min.js
Last active February 25, 2017 08:29
This is the minified version of my library
!function(n,r){"function"==typeof define&&define.amd?define([""],function(e){return n.RjLib=r(e)}):"object"==typeof module&&module.exports?module.exports=n.RjLib=r(require("")):n.RjLib=r(n.postal)}(this,function(){function n(n){return"object"==typeof n}function r(n){return"number"==typeof n}function e(n){return"string"==typeof n}function t(n){return Array.isArray(n)}function u(n){return 0>n}function o(r,e){var t=r;Object.keys(t).forEach(function(r,u){""!==t[r]&&void 0!==t[r]?e(null,r,n(t[r])):e(r+" has no values",null,null)})}function i(r,e){Object.keys(r).forEach(function(t){n(r[t])?(i(r[t],e),e(null,t,!0)):e(null,t,!1)})}function c(r,e){Object.keys(r).forEach(function(t){n(r[t])?c(r[t],e):e(null,t,r[t])})}function f(){var n=Array.prototype.slice.call(arguments);return 0===n[0].length?n[1]("Array is empty"):n[1](l(n[0]))}function l(n){var r=[];for(var e in n)r.push(Array.isArray(n[e]));return r.indexOf(!0)>-1?r.indexOf(!1)>-1?"Please check your array":"2D":"1D"}function a(n){return r(n)&&u(n)?!0:!1}function
@rjoydip-zz
rjoydip-zz / customSchemaToJsonSchemaExample.js
Last active February 26, 2017 13:57
This example is for converting a custom (my own) schema to JSON schema.
var countryJson = [
{"name":"Israel","dial_code":"+972","code":"IL"},
{"name":"Afghanistan","dial_code":"+93","code":"AF"},
{"name":"Albania","dial_code":"+355","code":"AL"},
{"name":"Algeria","dial_code":"+213","code":"DZ"},
{"name":"AmericanSamoa","dial_code":"+1 684","code":"AS"},
{"name":"Andorra","dial_code":"+376","code":"AD"},
{"name":"Angola","dial_code":"+244","code":"AO"},
{"name":"Anguilla","dial_code":"+1 264","code":"AI"},
{"name":"Antigua and Barbuda","dial_code":"+1268","code":"AG"},