Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Desc: Checks if a deep property exists
- * Exp: checkNested( { a: { b: { c: "d" } } } );
- * Returns: Boolean
- */
- function checkNested( obj ) {
- const args = Array.prototype.slice.call( arguments, 1 );
- for( let i = 0; i < args.length; i++ ) {
- if( !obj || !obj.hasOwnProperty( args[ i ] ) )
- return false;
- obj = obj[ args[ i ] ];
- }
- return true;
- }
- /**
- * Desc: Checks if string is encoded with encodeURIComponent
- * Exp: isEncoded( "~%2F" );
- * Returns: Boolean
- */
- function isEncoded( str ) {
- return typeof str === 'string' && decodeURIComponent( str ) !== str;
- }
- function isString( str ) {
- return str && typeof str === 'string';
- }
- function removeProperties( obj, properties ) {
- for( let i = 0; i < properties.length; i++ )
- delete obj[ properties[ i ] ];
- return obj;
- }
- function isMissingProperty( obj, properties ) {
- let hasOwnProperty = false, i = 0;
- for( ; i < properties.length; i++ )
- if( !obj.hasOwnProperty( properties[ i ] ) )
- hasOwnProperty = properties[ i ];
- return hasOwnProperty;
- }
- function containsProperty( obj, properties ) {
- let hasOwnProperty = false, i = 0;
- for( ; i < properties.length; i++ )
- if( !hasOwnProperty && obj.hasOwnProperty( properties[ i ] ) )
- hasOwnProperty = properties[ i ];
- return hasOwnProperty;
- }
- function payloadSizeMax( obj ) {
- return JSON.stringify( obj ).length >= 1536;
- }
- function uriSizeMax( obj ) {
- let isOk = false;
- Object.keys( obj ).filter( k => isOk = !isOk ? k.length >= 512 ? k : isOk : isOk );
- return isOk;
- }
- function notValidEmail( email ) {
- return !/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test( email );
- }
- function notValidPassword( pass ) {
- return !/^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})/.test( pass );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement