Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. /**
  2. * Desc: Checks if a deep property exists
  3. * Exp: checkNested( { a: { b: { c: "d" } } } );
  4. * Returns: Boolean
  5. */
  6. function checkNested( obj ) {
  7. const args = Array.prototype.slice.call( arguments, 1 );
  8. for( let i = 0; i < args.length; i++ ) {
  9. if( !obj || !obj.hasOwnProperty( args[ i ] ) )
  10. return false;
  11. obj = obj[ args[ i ] ];
  12. }
  13. return true;
  14. }
  15.  
  16. /**
  17. * Desc: Checks if string is encoded with encodeURIComponent
  18. * Exp: isEncoded( "~%2F" );
  19. * Returns: Boolean
  20. */
  21. function isEncoded( str ) {
  22. return typeof str === 'string' && decodeURIComponent( str ) !== str;
  23. }
  24.  
  25. function isString( str ) {
  26. return str && typeof str === 'string';
  27. }
  28.  
  29. function removeProperties( obj, properties ) {
  30. for( let i = 0; i < properties.length; i++ )
  31. delete obj[ properties[ i ] ];
  32. return obj;
  33. }
  34.  
  35. function isMissingProperty( obj, properties ) {
  36. let hasOwnProperty = false, i = 0;
  37. for( ; i < properties.length; i++ )
  38. if( !obj.hasOwnProperty( properties[ i ] ) )
  39. hasOwnProperty = properties[ i ];
  40. return hasOwnProperty;
  41. }
  42.  
  43. function containsProperty( obj, properties ) {
  44. let hasOwnProperty = false, i = 0;
  45. for( ; i < properties.length; i++ )
  46. if( !hasOwnProperty && obj.hasOwnProperty( properties[ i ] ) )
  47. hasOwnProperty = properties[ i ];
  48. return hasOwnProperty;
  49. }
  50.  
  51. function payloadSizeMax( obj ) {
  52. return JSON.stringify( obj ).length >= 1536;
  53. }
  54.  
  55. function uriSizeMax( obj ) {
  56. let isOk = false;
  57. Object.keys( obj ).filter( k => isOk = !isOk ? k.length >= 512 ? k : isOk : isOk );
  58. return isOk;
  59. }
  60.  
  61. function notValidEmail( email ) {
  62. 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 );
  63. }
  64.  
  65. function notValidPassword( pass ) {
  66. return !/^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})/.test( pass );
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement