Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fizzy-ui-utils

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fizzy-ui-utils - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

test/index.html

10

bower.json
{
"name": "fizzy-ui-utils",
"version": "1.0.1",
"version": "2.0.0",
"authors": [

@@ -10,4 +10,3 @@ "David DeSandro"

"dependencies": {
"doc-ready": "~1.0.4",
"matches-selector": "~1.0.2"
"matches-selector": "~2.0.0"
},

@@ -31,3 +30,6 @@ "moduleType": [

"package.json"
]
],
"devDependencies": {
"qunit": "~1.20.0"
}
}
{
"name": "fizzy-ui-utils",
"version": "1.0.1",
"version": "2.0.0",
"description": "UI utilities",
"main": "utils.js",
"dependencies": {
"doc-ready": "~1.0.3",
"desandro-matches-selector": "~1.0.2"
"desandro-matches-selector": "~2.0.0"
},

@@ -10,0 +9,0 @@ "scripts": {

17

README.md

@@ -27,20 +27,8 @@ # Fizzy UI utils

utils.isArray( obj )
// check if object is Array
utils.makeArray( obj )
// make array from object
utils.indexOf( ary, obj )
// get index of object in array
utils.removeFrom( ary, obj )
// remove object from array
utils.isElement( obj )
// check if object is an element
utils.setText( elem, text )
// set text of an element
utils.getParent( elem, selector )

@@ -61,2 +49,5 @@ // get parent element of an element, given a selector string

utils.docReady( callback )
// trigger callback on document ready
utils.toDashed( str )

@@ -73,4 +64,4 @@ // 'camelCaseString' -> 'camel-case-string'

MIT license. Have at it.
[MIT license](http://desandro.mit-license.org/). Have at it.
By [Metafizzy](http://metafizzy.co)
/**
* Fizzy UI utils v1.0.1
* Fizzy UI utils v2.0.0
* MIT license

@@ -16,12 +16,10 @@ */

define( [
'doc-ready/doc-ready',
'matches-selector/matches-selector'
], function( docReady, matchesSelector ) {
return factory( window, docReady, matchesSelector );
], function( matchesSelector ) {
return factory( window, matchesSelector );
});
} else if ( typeof exports == 'object' ) {
} else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory(
window,
require('doc-ready'),
require('desandro-matches-selector')

@@ -33,3 +31,2 @@ );

window,
window.docReady,
window.matchesSelector

@@ -39,3 +36,3 @@ );

}( window, function factory( window, docReady, matchesSelector ) {
}( window, function factory( window, matchesSelector ) {

@@ -62,9 +59,2 @@ 'use strict';

// ----- isArray ----- //
var objToString = Object.prototype.toString;
utils.isArray = function( obj ) {
return objToString.call( obj ) == '[object Array]';
};
// ----- makeArray ----- //

@@ -75,3 +65,3 @@

var ary = [];
if ( utils.isArray( obj ) ) {
if ( Array.isArray( obj ) ) {
// use object if already an array

@@ -81,3 +71,3 @@ ary = obj;

// convert nodeList to array
for ( var i=0, len = obj.length; i < len; i++ ) {
for ( var i=0; i < obj.length; i++ ) {
ary.push( obj[i] );

@@ -92,20 +82,6 @@ }

// ----- indexOf ----- //
// index of helper cause IE8
utils.indexOf = Array.prototype.indexOf ? function( ary, obj ) {
return ary.indexOf( obj );
} : function( ary, obj ) {
for ( var i=0, len = ary.length; i < len; i++ ) {
if ( ary[i] === obj ) {
return i;
}
}
return -1;
};
// ----- removeFrom ----- //
utils.removeFrom = function( ary, obj ) {
var index = utils.indexOf( ary, obj );
var index = ary.indexOf( obj );
if ( index != -1 ) {

@@ -116,26 +92,2 @@ ary.splice( index, 1 );

// ----- isElement ----- //
// http://stackoverflow.com/a/384380/182183
utils.isElement = ( typeof HTMLElement == 'function' || typeof HTMLElement == 'object' ) ?
function isElementDOM2( obj ) {
return obj instanceof HTMLElement;
} :
function isElementQuirky( obj ) {
return obj && typeof obj == 'object' &&
obj.nodeType == 1 && typeof obj.nodeName == 'string';
};
// ----- setText ----- //
utils.setText = ( function() {
var setTextProperty;
function setText( elem, text ) {
// only check setTextProperty once
setTextProperty = setTextProperty || ( document.documentElement.textContent !== undefined ? 'textContent' : 'innerText' );
elem[ setTextProperty ] = text;
}
return setText;
})();
// ----- getParent ----- //

@@ -179,24 +131,24 @@

for ( var i=0, len = elems.length; i < len; i++ ) {
var elem = elems[i];
elems.forEach( function( elem ) {
// check that elem is an actual element
if ( !utils.isElement( elem ) ) {
continue;
if ( !( elem instanceof HTMLElement ) ) {
return;
}
// add elem if no selector
if ( !selector ) {
ffElems.push( elem );
return;
}
// filter & find items if we have a selector
if ( selector ) {
// filter siblings
if ( matchesSelector( elem, selector ) ) {
ffElems.push( elem );
}
// find children
var childElems = elem.querySelectorAll( selector );
// concat childElems to filterFound array
for ( var j=0, jLen = childElems.length; j < jLen; j++ ) {
ffElems.push( childElems[j] );
}
} else {
// filter
if ( matchesSelector( elem, selector ) ) {
ffElems.push( elem );
}
}
// find children
var childElems = elem.querySelectorAll( selector );
// concat childElems to filterFound array
for ( var i=0; i < childElems.length; i++ ) {
ffElems.push( childElems[i] );
}
});

@@ -228,2 +180,12 @@ return ffElems;

// ----- docReady ----- //
utils.docReady = function( callback ) {
if ( document.readyState == 'complete' ) {
callback();
} else {
document.addEventListener( 'DOMContentLoaded', callback );
}
};
// ----- htmlInit ----- //

@@ -240,15 +202,20 @@

/**
* allow user to initialize classes via .js-namespace class
* allow user to initialize classes via [data-namespace] or .js-namespace class
* htmlInit( Widget, 'widgetName' )
* options are parsed from data-namespace-option attribute
* options are parsed from data-namespace-options
*/
utils.htmlInit = function( WidgetClass, namespace ) {
docReady( function() {
utils.docReady( function() {
var dashedNamespace = utils.toDashed( namespace );
var elems = document.querySelectorAll( '.js-' + dashedNamespace );
var dataAttr = 'data-' + dashedNamespace + '-options';
var dataAttr = 'data-' + dashedNamespace;
var dataAttrElems = document.querySelectorAll( '[' + dataAttr + ']' );
var jsDashElems = document.querySelectorAll( '.js-' + dashedNamespace );
var elems = utils.makeArray( dataAttrElems )
.concat( utils.makeArray( jsDashElems ) );
var dataOptionsAttr = dataAttr + '-options';
var jQuery = window.jQuery;
for ( var i=0, len = elems.length; i < len; i++ ) {
var elem = elems[i];
var attr = elem.getAttribute( dataAttr );
elems.forEach( function( elem ) {
var attr = elem.getAttribute( dataAttr ) ||
elem.getAttribute( dataOptionsAttr );
var options;

@@ -260,7 +227,6 @@ try {

if ( console ) {
console.error( 'Error parsing ' + dataAttr + ' on ' +
elem.nodeName.toLowerCase() + ( elem.id ? '#' + elem.id : '' ) + ': ' +
error );
console.error( 'Error parsing ' + dataAttr + ' on ' + elem.className +
': ' + error );
}
continue;
return;
}

@@ -270,7 +236,7 @@ // initialize

// make available via $().data('layoutname')
var jQuery = window.jQuery;
if ( jQuery ) {
jQuery.data( elem, namespace, instance );
}
}
});
});

@@ -277,0 +243,0 @@ };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc