Skip to content

joncody/gg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 

Repository files navigation

gg

A JavaScript and DOM utility library.

API

For the sake of time and brevity:

  • DOM Elements, Nodes = Node
  • DOM NodeLists, HTMLCollections, Array-like objects = ArrayLike, Array-like
  • gg factory objects = GObject
  • contents of iterables = item, element

Table Of Contents

gg(selector, supplanter) -> {GObject}

Return a collection of matched nodes found in the DOM.

Parameters
Name Type Description
selector String, Node, ArrayLike, GObject The value containing a string, selector expression, a Node, an Array-like, or a gobject.
supplanter Object (optional) The value to supplant into the selector.

Methods

typeOf(value) -> {String}

Determines the type of its argument.

Parameters
Name Type Description
value Any The value to be tested.

arrSlice(value, start, end) -> {Array}

Shorthand for Array.prototype.slice.call.

Parameters
Name Type Description
value Any The "this" value for Array.prototype.slice.
start Number (optional) An integer that specifies where to start the selection (The first element has an index of 0). Use negative numbers to select from the end of an array. If omitted, it acts like 0.
end Number (optional) An integer that specifies where to end the selection. If omitted, all elements from the start position and to the end of the array will be selected. Use negative numbers to select from the end of an array.

isArray(value) -> {Boolean}

Determines if its argument is an array.

Parameters
Name Type Description
value Any The value to be tested.

isBoolean(value) -> {Boolean}

Determines if its argument is a boolean.

Parameters
Name Type Description
value Any The value to be tested.

isFunction(value) -> {Boolean}

Determines if its argument is a function.

Parameters
Name Type Description
value Any The value to be tested.

isNull(value) -> {Boolean}

Determines if its argument is null.

Parameters
Name Type Description
value Any The value to be tested.

isNumber(value) -> {Boolean}

Determines if its argument is a number.

Parameters
Name Type Description
value Any The value to be tested.

isObject(value) -> {Boolean}

Determines if its argument is an object.

Parameters
Name Type Description
value Any The value to be tested.

isString(value) -> {Boolean}

Determines if its argument is a string.

Parameters
Name Type Description
value Any The value to be tested.

isUndefined(value) -> {Boolean}

Determines if its argument is undefined.

Parameters
Name Type Description
value Any The value to be tested.

isArrayLike(value) -> {Boolean}

Determines if its argument is array-like.

Parameters
Name Type Description
value Any The value to be tested.

isBuffer(value) -> {Boolean}

Determines if its argument is an arraybuffer.

Parameters
Name Type Description
value Any The value to be tested.

isEmpty(value) -> {Boolean}

Determines if its argument is an object with no enumerable properties.

Parameters
Name Type Description
value Any The value to be tested.

isGG(value) -> {Boolean}

Determines if its argument is a gobject.

Parameters
Name Type Description
value Any The value to be tested.

isNan(value) -> {Boolean}

Determines if its argument is NaN.

Parameters
Name Type Description
value Any The value to be tested.

isNode(value) -> {Boolean}

Determines if its argument is a node.

Parameters
Name Type Description
value Any The value to be tested.

isTypedArray(value) -> {Boolean}

Determines if its argument is a TypedArray.

Parameters
Name Type Description
value Any The value to be tested.

toArray(value) -> {Array}

Converts its argument to an Array.

Parameters
Name Type Description
value Any The value to be converted.

toCamelCase(value) -> {Boolean|String}

Converts a hyphenated string to camel case. Returns false if its argument is not a string.

Parameters
Name Type Description
value String The value to be converted.

toCodesFromString(value) -> {Array}

Converts a string to an array of Unicodes. Its argument is first passed through toArray.

Parameters
Name Type Description
value String The value to be converted.

toFloat(value, decimals) -> {Number|String}

Converts a value to a floating point number with an optional number of decimals. Removes commas before conversion and returns 0 if its result is NaN.

Parameters
Name Type Description
value String, Number The value to be converted.
decimals Number (optional) The number of decimals.

toHyphenated(value) -> {Boolean|String}

Converts a camel case string to a hyphenated one. Returns false if its argument is not a string.

Parameters
Name Type Description
value String The value to be converted.

toInt(value, radix) -> {Number}

Converts a value to an integer using the specified radix. Removes commas before conversion and returns 0 if its result is NaN.

Parameters
Name Type Description
value String, Number The value to be converted.
radix Number (optional, default: 10) The radix to use.

toUint8(value) -> {Uint8Array}

Converts its argument to an uint8array. If its argument is a number, it returns an uint8array with an equal length.

Parameters
Name Type Description
value Any The value to be converted.

toBuffer(value) -> {ArrayBuffer}

Converts its argument to an arraybuffer by passing it through toUint8 and getting its buffer property. If its argument is a number, it returns an arraybuffer with an equal length.

Parameters
Name Type Description
value Any The value to be converted.

toStringFromCodes(value) -> {String}

Converts an array of Unicodes to a string. Its argument is first passed through toArray.

Parameters
Name Type Description
value Array The value to be converted.

betterview(value, offset, length) -> {Better}

An upgraded DataView.

Parameters
Name Type Description
value Any The value passed through toBuffer before storing.
offset Number (optional) The offset, in bytes, to the first byte in the specified buffer for the new view to reference. If not specified, the view of the buffer will start with the first byte.
length Number (optional) The number of elements in the byte array. If unspecified, length of the view will match the buffer's length.

copy(value) -> {Any}

Copies its argument by value.

Parameters
Name Type Description
value Any The value to copy.

each(items, executable, thisarg) -> {Any}

Calls a provided function once for each element in a set of elements, in order. It returns the assigned "this" value.

Parameters
Name Type Description
items GObject, Array, ArrayLike, TypedArray, Buffer, Object, Node The value to iterate over.
executable Function The function to be run for each element within the set.
thisarg Any (optional) The value to be passed to the function to be used as its "this" value. If empty, the iterated set of elements will be assigned to it.

emitter(value) -> {Object}

A client side port of Node.js' events.js. Allows, enables, and returns an emitter object - one able to listen for and emit custom events.

Parameters
Name Type Description
value Object (optional) The object to turn into an emitter.

equal(one, two) -> {Boolean}

Determines if its two arguments are equal by value.

Parameters
Name Type Description
one Any A value to compare.
two Any A value to compare.

extend(value, add, overwrite) -> {Object}

Extends its first argument with its second.

Parameters
Name Type Description
value Object The value to extend.
add Object The extending value.
overwrite Boolean (optional; default: true) The value indicating if values with matching keys will be overwritten.

inherits(ctor, superCtor) -> {Function}

Its first argument prototypically inherits from its second.

Parameters
Name Type Description
ctor Function The inheriting value.
superCtor Function The inherited value.

inArray(list, value) -> {Boolean}

Checks if its second argument is contained within its first.

Parameters
Name Type Description
list Array The value to look through.
value Any The value to look for.

noop()

An empty function.


supplant(value, supplanter) -> {Boolean|String}

Does variable substitution on its first argument. It scans through its first argument looking for expressions enclosed in { } braces. If an expression is found, use it as a key on its second argument, and if the key has a string value or number value, it is substituted for the bracket expression and it repeats.

Parameters
Name Type Description
value String The value to scan.
supplanter Object The supplanting value.

uuid() -> {String}

Generates a universally unique identifier.


getPosition(node) -> {Object}

Gets its arguments absolute x and y coordinates.

Parameters
Name Type Description
node Node The Node to get the position of.

getStyle(node, pseudo) -> {Object}

Shorthand for window.getComputedStyle.

Parameters
Name Type Description
node Node The node to get the computed style of.
pseudo String (optional; default: null) The pseudo-element to get.

setImmediate(executable) -> {Object}

Shorthand for window.setTimeout with 0 wait time.

Parameters
Name Type Description
executable Function The function that will be run.

getById(id, supplanter) -> {Node}

Combines supplant and document.getElementById, in that order.

Parameters
Name Type Description
id String The value to scan.
supplanter Object The supplanting value.

select(selector, supplanter, node) -> {Node}

Combines document.querySelector and supplant, in that order, where document is replaced by the optional third argument if provided.

Parameters
Name Type Description
selector String The value to scan.
supplanter Object The supplanting value.
node Node The node to execute the query from.

selectAll(selector, supplanter, node) -> {ArrayLike}

Combines document.querySelectorAll and supplant, in that order, where document is replaced by the optional third argument if provided.

Parameters
Name Type Description
selector String The value to scan.
supplanter Object The supplanting value.
node Node The node to execute the query from.

scrollIntoView(node, easingExec)

Scrolls its first argument into view using its second argument as the easing function.

Parameters
Name Type Description
node Node The node to scroll into view.
easingExec Function (optional, default: ease.easeInOutSine) The easing function to use when scrolling the page.

scrollToTop(node, easingExec)

Scrolls to the top of its first argument using its second argument as the easing function.

Parameters
Name Type Description
node Node The node to scroll to the top of.
easingExec Function (optional, default: ease.easeInOutSine) The easing function to use when scrolling.

create(tag) -> {GObject|Null}

Case insensitive shorthand for document.createElement. The new node is converted to a gobject before being returned. If its argument is not a correctly named node it returns null.

Parameters
Name Type Description
tag String The name of the node to create.

keyboardListener(options)

Listens for keyboard key down events.

Parameters
Name Type Description
options Object Each options key is a keyCode (Number, String) of the keyboard key to listen for when pressed down with one exception - "preventDefault": (Boolean). Optionally, five strings are recognized as keys: "enter", "leftarrow", "uparrow", "downarrow", and "rightarrow". Each value is a function to run when its corresponding key is pressed down.

mouseListener(options)

Listens for mouse key down events.

Parameters
Name Type Description
options Object Each options key is a button code (Number, String) of the mouse button to listen for when pressed down with one exception - "preventDefault": (Boolean). Optionally, three strings are recognized as keys: "left", "middle", and "right". Each value is a function to run when its corresponding button is pressed down.

removeKeyboardListeners()

Removes all keyboard listeners.


removeMouseListeners()

Removes all mouse listeners.


Attributes

ease

A collection of easing functions that return a current value based on four parameters.

Parameters
Name Type Description
t Number The current time.
b Number The initial value.
c Number The change in value.
d Number The total duration.
Methods
  • linearTween
  • easeInQuad
  • easeOutQuad
  • easeInOutQuad
  • easeInCubic
  • easeOutCubic
  • easeInOutCubic
  • easeInQuart
  • easeOutQuart
  • easeInOutQuart
  • easeInQuint
  • easeOutQuint
  • easeInOutQuint
  • easeInSine
  • easeOutSine
  • easeInOutSine
  • easeInExpo
  • easeOutExpo
  • easeInOutExpo
  • easeInCirc
  • easeOutCirc
  • easeInOutCirc

cdb

An emitter that is a small, SQL-like interface to indexedDB.

Methods
Name Parameters Description
open
NameTypeDescription
nameStringThe name of the database to open.
version (optional, default: 1)NumberThe version of the database.
executableFunction(Event, CDBDatabase)Is assigned to onupgradeneeded.
Opens a new database.
delete
NameTypeDescription
nameStringThe name of the database to delete.
Deletes a database.
Events
Name Type Description
open Event, CDBRequest Fired when a new database is successfully opened.
delete-db Event Fired when a database is successfully deleted.
delete-table String Fired when an object store is successfully deleted.
error Event Fired when an error occurs.

CDBDatabase

A wrapper around an IDBDatabase object.

Methods
Name Parameters Description
database Returns the unwrapped IDBDatabase object.
create
NameTypeDescription
tableStringThe name of the object store.
optionsObject (optional)Set the keyPath and/or autoIncrement features.
schemaObject (optional)The index name, keyPath, and unique, multiEntry, locale features for each.
Creates a new object store.
delete
NameTypeDescription
tableStringThe name of the object store.
Deletes an object store.

CDBRequest

A wrapper around an IDBRequest object.

Methods
Name Parameters Description
request Returns the unwrapped IDBDatabase object.
database Returns the unwrapped IDBDatabase object.
select
NameTypeDescription
tableStringThe name of the object store.
keyStringThe key name.
Gets a value with a given key name at a specified object store.
selectAll
NameTypeDescription
tableStringThe name of the object store.
querykey or IDBKeyRange (optional, default: all)The key or key range to be queried.
countNumber (optional)The number of values to return if more than one is found (optional, default: > 0 < 2^32-1)
Gets appropriate number of values within the given key range or with a given key at a specified object store.
selectAllKeys
NameTypeDescription
tableStringThe name of the object store.
queryValue resolving to an IDBKeyRange (optional, default: all)The key or key range to be queried.
countNumber (optional)The number of values to return if more than one is found (optional, default: > 0 < 2^32-1)
Gets all keys for all objects in the object store.
selectIndex
NameTypeDescription
tableStringThe name of the object store.
indexStringThe index name.
keyStringThe key name.
Gets a value with a given index and key name at a specified object store.
delete
NameTypeDescription
tableStringThe name of the object store.
keykey name or IDBKeyRangeThe key or key range to match.
Deletes all matched records from a given object store and key or keyRange.
insert
NameTypeDescription
tableStringThe name of the object store.
valueAnyThe new value.
keyStringThe key name.
Inserts a value with a given key name in a given object store.
update
NameTypeDescription
tableStringThe name of the object store.
valueAnyThe new value.
keyStringThe key name.
Updates a value with a given key name in a given object store.
clear
NameTypeDescription
tableStringThe object store name.
Removes all records and records in indexes from a given object store.
count
NameTypeDescription
tableStringThe name of the object store.
querykey or IDBKeyRange (optional, default: all)The key or key range to be queried.
Gets the total number of matched records from a given object store.

gobject

A gg factory object.

Methods

add(value) -> {GObject}

Adds nodes to the gobject.

Parameters
Name Type Description
value GObject, Array, ArrayLike, Node The nodes to add.

addClass(value) -> {GObject}

Adds a class to all nodes contained within the gobject.

Parameters
Name Type Description
value String The class to add.

after(value) -> {GObject}

Places nodes after each node contained within the gobject.

Parameters
Name Type Description
value GObject, Array, ArrayLike, Node The nodes to place after.

append(value) -> {GObject}

Appends nodes to each node contained within the gobject.

Parameters
Name Type Description
value GObject, Array, ArrayLike, Node The nodes to append.

appendTo(value) -> {GObject}

Appends the nodes contained within the gobject to its argument.

Parameters
Name Type Description
value GObject, Array, ArrayLike, Node The nodes to append to.

attr(name, value) -> {GObject|String|Array|Object}

Sets or gets an attribute on the nodes contained within the gobject.

Parameters
Name Type Description
name String, Object, Array The attribute name.
value String (optional) The attribute value.

before(value) -> {GObject}

Places nodes before each node contained within the gobject.

Parameters
Name Type Description
value GObject, Array, ArrayLike, Node The nodes to place before.

children() -> {GObject}

Gets the children of the nodes contained within the gobject.


classes(value) -> {GObject|String|Array}

Sets or gets the className attribute on the nodes contained within the gobject.

Parameters
Name Type Description
value String (optional) The className value.

clone(deep, deeper) -> {GObject}

Clones the nodes contained within the gobject.

Parameters
Name Type Description
deep Boolean (optional, default: false) Specifies whether all descendants of each node should be cloned.
deeper Boolean (optional, default: false) Specifies whether all event handlers of each node should be cloned.

create(tag) -> {GObject}

Creates a new node and appends it to the original gobject.

Parameters
Name Type Description
tag String The type of node to be created.

data(name, value) -> {GObject|String|Array|Object}

Sets or gets a data attribute on the nodes contained within the gobject.

Parameters
Name Type Description
name String, Object, Array The attribute name.
value String (optional) The attribute value.

each(executable) -> {GObject}

Iterates over the nodes contained within the gobject. Every node is wrapped in its own gobject instance before being passed to the executable.

Parameters
Name Type Description
executable Function The function to pass each node to.

eachRaw(executable) -> {GObject}

Iterates over the nodes contained within the gobject. Every node is passed to the executable in its raw form.

Parameters
Name Type Description
executable Function The function to pass each node to.

get(index) -> {GObject}

Gets the specified node from within the gobject.

Parameters
Name Type Description
index Number (optional) The node position within the gobject.

hasClass(value) -> {Boolean|Array}

Determines whether the nodes contained within the gobject have a specified class.

Parameters
Name Type Description
value String The class to check for.

html(value) -> {GObject|String|Array}

Sets or gets the innerHTML attribute on the nodes contained within the gobject.

Parameters
Name Type Description
value String (optional) The innerHTML value.

insert(pos, value) -> {GObject}

Inserts raw HTML at the specified position relative to each node contained within the gobject.

Parameters
Name Type Description
pos String The position to place the raw HTML.
value String The raw HTML.

length() -> {Number}

Gets the number of nodes contained within the gobject.


off(type, executable, bub) -> {GObject}

Removes event handlers from the nodes contained within the gobject.

Parameters
Name Type Description
type String The name of the event.
executable Function (optional) The specific handler to remove.
bub Boolean (optional, default: false) Determines event bubbling.

on(type, executable, bub, arg) -> {GObject}

Adds event handlers to the nodes contained within the gobject.

Parameters
Name Type Description
type String The name of the event.
executable Function The handler to add.
bub Boolean (optional, default: false) Determines event bubbling.
arg Any (optional) The argument to pass to the handler upon execution.

once(type, executable, bub, arg) -> {GObject}

Adds event handlers to the nodes contained within the gobject. The handler is removed after execution.

Parameters
Name Type Description
type String The name of the event.
executable Function The handler to add.
bub Boolean (optional, default: false) Determines event bubbling.
arg Any (optional) The argument to pass to the handler upon execution.

parents() -> {GObject}

Gets the parents of the nodes contained within the gobject.


prepend(value) -> {GObject}

Prepends nodes to each node contained within the gobject.

Parameters
Name Type Description
value GObject, Array, ArrayLike, Node The nodes to prepend.

prependTo(value) -> {GObject}

Prepends the nodes contained within the gobject to its argument.

Parameters
Name Type Description
value GObject, Array, ArrayLike, Node The nodes to prepend to.

prop/css/style(name, value) -> {GObject|String|Array|Object}

Sets or gets properties on the nodes contained within the gobject.

Parameters
Name Type Description
name String, Object, Array The property name.
value String (optional) The property value.

raw(index) -> {Node|Array}

Gets the raw value of specified node from within the gobject

Parameters
Name Type Description
index Number (optional) The node position within the gobject.

remove(value) -> {GObject}

Removes the nodes contained within the gobject or just their specified children.

Parameters
Name Type Description
value GObject, Array, ArrayLike, Node (optional) The children to remove.

remAttr(name) -> {GObject}

Removes attributes from the nodes contained within the gobject.

Parameters
Name Type Description
name String, Object, Array The attribute name.

remClass(value) -> {GObject}

Removes classes from the nodes contained within the gobject.

Parameters
Name Type Description
value String The class to remove.

remData(name) -> {GObject}

Removes data attributes from the nodes contained within the gobject.

Parameters
Name Type Description
name String, Object, Array The data attribute name.

remHtml() -> {GObject}

Removes the innerHTML from the nodes contained within the gobject.


remProp/remCss/remStyle(name) -> {GObject}

Removes properties from the nodes contained within the gobject.

Parameters
Name Type Description
name String, Object, Array The property name.

remText() -> {GObject}

Removes the textContent from the nodes contained within the gobject.


select(selector, supplanter) -> {GObject}

Runs querySelector on the nodes contained within a gobject.

Parameters
Name Type Description
selector String The value to scan.
supplanter Object The supplanting value.

selectAll(selector, supplanter) -> {GObject}

Runs querySelectorAll on the nodes contained within a gobject.

Parameters
Name Type Description
selector String The value to scan.
supplanter Object The supplanting value.

subtract(index) -> {GObject}

Removes nodes from the gobject.

Parameters
Name Type Description
index Number The node position within the gobject.

text(value) -> {GObject|String|Array}

Sets or gets the textContent attribute on the nodes contained within the gobject.

Parameters
Name Type Description
value String (optional) The textContent value.

togClass(value) -> {GObject}

Toggles a class on the nodes contained within the gobject.

Parameters
Name Type Description
value String The class to toggle.

About

A JavaScript and DOM utility library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published