GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - NotNull/VCheck: Key/Value Event Callback helper that checks the passed Value type and based on the type, to launch passed functions.

BranchesTags
Open more actions menu

Latest commit

 

History

17 Commits
17 Commits

Folders and files

NameName
Last commit message
Last commit date
.project
.project
 
 
README.md
README.md
 
 
index.html
index.html
 
 
underscore.js
underscore.js
 
 
vcheck.js
vcheck.js
 
 
vcheck.min.js
vcheck.min.js
 
 

Repository files navigation

VCheck

Key/Value Event Callback helper that checks the passed Value type and based on the type, to launch passed functions.

VCheck is a very light-weight helper function that does only one thing, but does it well.

Requirements: Underscore.js (Used for datatype checking)

PHP Version: https://github.com/NotNull/VCheck-PHP

**** Future Changes ****

  • Introducing chaining calls:
v(unknownVariable).isString(function(){}).isObject(function(){});
  • Introducing more helper functions.
  • Taking away dependency on Underscore, but will wrap around Underscore if present.

Example usage:

var unknownType = "I am a string";

VCheck(unknownType, {
  'function': function(value){
    console.log('I am a function!');
  },
  number: function(value){
    console.log('I am a number!');
  },
  string: function(value){
    console.log('I am a string!');
  }
});
//Output: 'I am a string!'

The datatype that matches the passed variable launches the passed callback if the datatype equals true.

You can also pass extra parameters to launch a callback based on matching or not.

var unknownType = "I am a string";

VCheck(unknownType, {
  'function': function(value){
    console.log('I am a function!');
  },
  number: {
    'true': function(value){
      console.log('I am a number!');
    },
    'false': function(value){
      console.log('I am not a number!');    
    }
  },
  string: function(value){
    console.log('I am a string!');
  }
});
//Output: 'I am not a number!'
//Output: 'I am a string!'

By default, if a datatype returns true, it does not check against any other passed params that come after. But, you can set it to do so.

var unknownType = 9001;

VCheck(unknownType, {
  typeSensitive: false,
  'function': function(value){
    console.log('I am a function!');
  },
  number: function(value){
    if(value > 9000)
      console.log("I'm over 9000!");
      
  }, 
  finite: function(value){
    if(value > 9000)
      console.log("I'm over 9000!");
      
  }, 
  string: function(value){
    console.log('I am a string!');
  }
});
//Output: "I'm over 9000!";
//Output: "I'm over 9000!";

You can also bind Events to a element.

VCheck($('#div')[0], {
	'mouseevent': {
		preventDefault: true,
		contextMenu: false,
		'left': function(){
			alert('You pressed the left mouse button!');
		},
		'middle': function(){
			alert('You pressed the middle mouse button!');
		},
		'right': function(){
			alert('You pressed the right mouse button!');
		}
	},
	'keyup': {
		'f': function(e){
			alert('You hit the F key!');
		}
	}
});

About

Key/Value Event Callback helper that checks the passed Value type and based on the type, to launch passed functions.

Resources

Readme
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.