1.2.2 • Published 5 years ago

smize v1.2.2

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
5 years ago

smize : object

Kind: global namespace

smize.composables : object

A collection of composable classes that provide reusable functionality.

Kind: static namespace of smize

composables.AJAX

A composable class that provides AJAX functionality

Kind: static class of composables
Properties

NameTypeDescription
classPathstringThe path to the class in the global namespace
lastResponseobjectThe last response from an AJAX call
lastStatusstringThe last status from an AJAX call
lastXHRobjectThe last XHR object
scopeobjectThe class instance that initialized this composable

new AJAX(scope)

Creates a new, scoped instance of the AJAX class

ParamTypeDescription
scopeobjectThe class instance that created this instance

AJAX.afterAll(xhr, status, response) ⇒ boolean

Tasks performed after all AJAX calls in a series of calls

Kind: static method of AJAX
Returns: boolean - The method executed successfully

ParamTypeDescription
xhrobjectThe XMLHttpRequest for the AJAX call
statusstringThe status of the XMLHttpRequest
responseobjectThe response object from the XMLHttpRequest

AJAX.afterEach(xhr, status, response) ⇒ boolean

Tasks performed after each AJAX call in a series of calls

Kind: static method of AJAX
Returns: boolean - The method executed successfully

ParamTypeDescription
xhrobjectThe XMLHttpRequest for the AJAX call
statusstringThe status of the XMLHttpRequest
responseobjectThe response object from the XMLHttpRequest

AJAX.call(config, stopOnError) ⇒ void

Places an AJAX call

Kind: static method of AJAX

ParamTypeDescription
configobjectThe configuration properties for the AJAX call, or an array of configs: data {object}: A collection of key: value pairs to send in the payload (POST/PATCH) or ampersand-delimited key=value pairs to request on the query string (GET) error {function}: A callback to execute on error headers {object}: A collection of headers to apply to the request as key: value pairs method {string}: The method, defaults to 'GET' success {function}: A callback to execute on success type {string}: The responseType, defaults to 'json' url {string}: The URL to call, required
stopOnErrorbooleanShould the chain end when there is an error?

composables.Base

A base class that can be extended to provide common functionality

Kind: static class of composables
Properties

NameTypeDescription
configobjectThe initial configuration received from the constructor
elobjectThe element this class instance was bound to
initializedbooleanHas the instance initialized?
loadedbooleanHas the instance loaded all content?
setupbooleanHas the instance completed its setup tasks?
subscriptionsarrayA collection of events to subscribe to

new Base(config, defaults)

Creates a new instance of the Base class

ParamTypeDescription
configobjectShared configuration for a group of class instances
defaultsobjectThe default configuration for an extending class

Base.configure(config) ⇒ boolean

Configures a class instance from a configuration object

Kind: static method of Base
Returns: boolean - Was the configuration successful?

ParamTypeDescription
configobjectThe object to configure from

Base.subscribe(eventNames) ⇒ boolean

Subscribes to one or more events using smize.events.subscribe

Kind: static method of Base
Returns: boolean - Were events successfully subscribed to?

ParamTypeDescription
eventNamesobjectAn array of event names, or a single event name string

Base.handleSubscriptions(eventName) ⇒ boolean

A handler method that delegates resolved subscriptions to the appropriate method

Kind: static abstract method of Base
Returns: boolean - Was the subscription event handled?

ParamTypeDescription
eventNamestringThe name of the event to handle

composables.Debug

A composable class that provides Debug functionality

Kind: static class of composables
Properties

NameTypeDescription
classPathstringThe path to the class in the global namespace
debugEnabledbooleanIs debug enabled? Defaults to global state
debugFiltersarrayA collection of debug filters, defaults to global state
debugLevelstringThe allowed debug level, defaults to global state
scopeobjectThe class instance that initialized this composable

new Debug(scope, config)

Creates a new, scoped instance of the Debug class

ParamTypeDescription
scopeobjectThe class instance that created this instance
configobjectOptional configuration overrides

Debug.error() ⇒ boolean

Writes an error log, accepting the same params as console.error

Kind: static method of Debug
Returns: boolean - Was the message logged?

Debug.formatMessage(methodName, message) ⇒ string

Formats a message string

Kind: static method of Debug
Returns: string - The formatted message or an empty string

ParamTypeDescription
methodNamestringThe name of the caller method
messagestringThe message to format

Debug.info() ⇒ boolean

Writes an info log, accepting the same params as console.info

Kind: static method of Debug
Returns: boolean - Was the message logged?

Debug.matchesFilters(message) ⇒ boolean

Ensures a message matches any filters specified

Kind: static method of Debug
Returns: boolean - Did the message pass our filters?

ParamTypeDescription
messagestringThe message argument passed to the logger

Debug.warn() ⇒ boolean

Writes an warn log, accepting the same params as console.warn

Kind: static method of Debug
Returns: boolean - Was the message logged?

Debug.write(writeArguments) ⇒ boolean

Writes a log to the console if it is able to

Kind: static method of Debug
Returns: boolean - Was the message logged?

ParamTypeDescription
writeArgumentsarrayA collection of arguments for debugging

smize.data : object

Provides data-related utilities

Kind: static namespace of smize

data.getCookies(cookieString) ⇒ object

Retrieves cookies as key: value pairs

Kind: static method of data
Returns: object - A collection of keys

ParamTypeDescription
cookieStringstringThe cookies to parse, defaults to document.cookie

data.getLocalItem(itemName, defaultValue) ⇒ object

Retrieves an item from localStorage - type inferred from the default value

Kind: static method of data
Returns: object - The stored value, defaults to string

ParamTypeDescription
itemNamestringThe name of the localStorage item
defaultValueobjectAn optional default value if none is retrieved

data.getMetaKeys() ⇒ object

Retrieves element values as key: value pairs

Kind: static method of data
Returns: object - A collection of keys

data.getQueryKeys(queryString) ⇒ object

Retrieves query string parameters as key: value pairs

Kind: static method of data
Returns: object - A collection of keys

ParamTypeDescription
queryStringstringThe optional query string to retrieve keys from, defaults to document.location.search

data.getSessionItem(itemName, defaultValue) ⇒ object

Retrieves an item from sessionStorage - type inferred from the default value

Kind: static method of data
Returns: object - The stored value, defaults to a string

ParamTypeDescription
itemNamestringThe name of the sessionStorage item
defaultValueobjectAn optional default value if none is retrieved

data.removeLocalItem(itemName) ⇒ boolean

Removes an item from localStorage if it exists

Kind: static method of data
Returns: boolean - Was the removal successful?

ParamTypeDescription
itemNamestringThe name of the localStorage item

data.removeSessionItem(itemName) ⇒ boolean

Removes an item from sessionStorage if it exists

Kind: static method of data
Returns: boolean - Was the removal successful?

ParamTypeDescription
itemNamestringThe name of the sessionStorage item

data.setLocalItem(itemName, value) ⇒ boolean

Creates or updates a localStorage item

Kind: static method of data
Returns: boolean - Was the update successful?

ParamTypeDescription
itemNamestringThe name of the localStorage item
valueobjectThe new value for the item

data.setSessionItem(itemName, value) ⇒ boolean

Creates or updates a sessionStorage item

Kind: static method of data
Returns: boolean - Was the update successful?

ParamTypeDescription
itemNamestringThe name of the sessionStorage item
valueobjectThe new value for the item

data.transferKeys(source, target, concatArrays, dedupeArrays) ⇒ boolean

Transfers key: value pairs between two objects

Kind: static method of data
Returns: boolean - Was the transfer successful?
Todo

  • Explore object copying APIs to clean this logic up
ParamTypeDescription
sourceobjectThe source collection to read values from
targetobjectThe target collection add values to
concatArraysbooleanShould arrays be merged?
dedupeArraysbooleanShould array members be unique?

smize.events : object

Provides utilities for publishing and subscribing to events

Kind: static namespace of smize

events.debounce(originalFunction, executionDelay, callImmediately) ⇒ function

Debounces event calls to improve performance

Kind: static method of events
Returns: function - The debounced function or the original value

ParamTypeDescription
originalFunctionfunctionThe function call to be debounced
executionDelaynumberThe number of milliseconds to delay by
callImmediatelybooleanShould the function be called immediately?

events.publish(subscriptionName) ⇒ boolean

Publishes information to all subscribers of a given subscription

Kind: static method of events
Returns: boolean - Was the subscription published?

ParamTypeDescription
subscriptionNamestringThe name of the subscription

events.subscribe(subscriptionName, subscriber) ⇒ boolean

Publishes information to all subscribers of a given subscription

Kind: static method of events
Returns: boolean - Did we successfully subscribe?

ParamTypeDescription
subscriptionNamestringThe name of the subscription
subscriberfunctionThe subscriber function

smize.html : object

Provides generic utilities for managing HTML nodes

Kind: static namespace of smize

html.addClass(elements, classNames) ⇒ boolean

Adds one or more CSS classes to one or more elements

Kind: static method of html
Returns: boolean - Was the operation successful?

ParamTypeDescription
elementsobjectAn HTML element or an Array-like of HTML elements
classNamesobjectA CSS class name or an Array of CSS class names

html.getClasses(elements) ⇒ array

Returns an Array of all classes on one or more elements

Kind: static method of html
Returns: array - The classes found on the element(s)

ParamTypeDescription
elementsobjectAn HTML element or an Array-like of HTML elements

html.hasClass(elements, classNames) ⇒ boolean

Checks that all elements have all CSS classes

Kind: static method of html
Returns: boolean - Do all elements have all classes?

ParamTypeDescription
elementsobjectAn HTML element or an Array-like of HTML elements
classNamesobjectA CSS class name or an Array of CSS class names

html.isValidElement(element) ⇒ boolean

Verifies that one object is a valid HTML element

Kind: static method of html
Returns: boolean - Is this a valid element?

ParamTypeDescription
elementobjectA single element to verify

html.nodeListToArray(elements) ⇒ array

Creates an Array from an element or a NodeList

Kind: static method of html
Returns: array - An Array of one or more HTML elements

ParamTypeDescription
elementsobjectAn HTML element or an Array-like of HTML elements

html.removeClass(elements, classNames) ⇒ boolean

Removes one or more CSS classes from one or more elements

Kind: static method of html
Returns: boolean - Was the operation successful?

ParamTypeDescription
elementsobjectAn HTML element or an array-like of HTML elements
classNamesobjectA CSS class name or an Array of CSS class names

smize.il8n : object

Provides utilities for localization and internationalization

Kind: static namespace of smize

il8n.addDictionaryKey(dictionaryKey) ⇒ boolean

Kind: static method of il8n
Returns: boolean - Was the key successfully added?

ParamTypeDescription
dictionaryKeyobjectThe dictionary key to add

il8n.addDictionaryKeys(dictionaryKeys) ⇒ boolean

Adds a collection of dictionary keys to the DICTIONARY; key format (provide as many language/country values as needed): { "name": "A unique name for the dictionary key", "en": "A default English value; use ISO 639-1 values for the language code", "en-US": "The US English value; use IETF language tags" }

Kind: static method of il8n
Returns: boolean - Were the key successfully added?

ParamTypeDescription
dictionaryKeysarrayThe dictionary keys to add

il8n.formatDate(date, language) ⇒ string

Formats an instance of Date as a localized string for a given language

Kind: static method of il8n
Returns: string - The formatted date

ParamTypeDescription
dateDateThe date to format
languagestringThe language/locale to format the date for

il8n.formatDateString(dateString, language) ⇒ string

Formats a date string for a given language

Kind: static method of il8n
Returns: string - The formatted date or an empty string

ParamTypeDescription
dateStringstringThe date to format
languagestringThe language/locale to format the date for

il8n.formatNumber(numberValue, language, options) ⇒ string

Formats a number for display in a given language

Kind: static method of il8n
Returns: string - The formatted number or an empty string

ParamTypeDescription
numberValuenumber | stringThe number to format, either a number or a string
languagestringThe language/locale to format the number for
optionsobjectConfiguration to tell the localization how to format the number, defaults to { style: 'decimal' }

il8n.getKeyValue(dictionaryKeyName, language) ⇒ string

Retrieves the localized value for the given dictionary key

Kind: static method of il8n
Returns: string - The dictionary key value or an empty string

ParamTypeDescription
dictionaryKeyNamestringThe name of the dictionary key to retrieve
languagestringThe language/locale to retrieve the value for

il8n.setKeyValue(dictionaryKeyName, language, value) ⇒ boolean

Updates the value of a given dictionary key for the specified language

Kind: static method of il8n
Returns: boolean - Was the dictionary key updated?

ParamTypeDescription
dictionaryKeyNamestringThe name of the dictionary key to set
languagestringThe language/locale to set the value for
valuestringThe new value for the dictionary key

smize.responsive : object

Provides utilities for handling responsive behavior

Kind: static namespace of smize

responsive.currentBreakpoint

Kind: static property of responsive
Properties

NameTypeDescription
currentBreakpointobjectThe current breakpoint object - defaults to the best match

responsive.addBreakpoint(breakpointName, breakpointSettings) ⇒ boolean

Adds a breakpoint to handle specific screen information

Kind: static method of responsive
Returns: boolean - Was the named breakpoint added?

ParamTypeDescription
breakpointNamestringthe name of the breakpoint to add
breakpointSettingsobjectThe settings for the breakpoint, accepted settings (only width and height are needed): dpi Dots Per Inch, display pixel density height The expected height minHeight The minimum expected height minWidth The minimum expected width orientation The device orientation width The expected width

responsive.addSubscriber(breakpointNames, subscriberFunction) ⇒ boolean

Adds a subscriber to one or more breakpoints Consumers can subscribe individually without this method See: smize.events.subscribe

Kind: static method of responsive
Returns: boolean - Was the subscription successful?

ParamTypeDescription
breakpointNamesobjectA string, comma-separated list, or Array of breakpointNames
subscriberFunctionfunctionThe subscriber function to add to each

responsive.bindEventHandlers() ⇒ boolean

Binds the responsive event handlers to manage breakpoints This is consumer-initialized to ensure additional breakpoints are added first

Kind: static method of responsive
Returns: boolean - Were the event handlers bound?

responsive.getBreakpoint(breakpointName) ⇒ object

Returns the named breakpoint

Kind: static method of responsive
Returns: object - The breakpoint

ParamTypeDescription
breakpointNamestringThe name of the breakpoint to retrieve

responsive.getCurrentBreakpoints(viewport) ⇒ Array

Returns all breakpoints that match the current viewport

Kind: static method of responsive
Returns: Array - A collection of matching viewports

ParamTypeDescription
viewportobjectAn optional viewport object to evaluate breakpoints for

responsive.getSubscriberCount(breakpointName) ⇒ number

Returns a count of subscribers for a given breakpoint

Kind: static method of responsive
Returns: number - The subscriber count for the breakpoint

ParamTypeDescription
breakpointNamestringThe name of the breakpoint

responsive.removeBreakpoint(breakpointName) ⇒ boolean

Removes the given breakpoint from the list of breakpoints to handle

Kind: static method of responsive
Returns: boolean - Was the named breakpoint removed?

ParamTypeDescription
breakpointNamestringThe name of the breakpoint to remove

smize.ui : object

Provides helper methods and generic user interface classes to be extended

Kind: static namespace of smize

ui.bindModule(element) ⇒ boolean

Determines which module to bind to an element and performs binding

Kind: static method of ui
Returns: boolean - Was the element successfully bound?

ParamTypeDescription
elementobjectThe element to bind

ui.bindScope(scope, deferSelector) ⇒ boolean

Binds all elements within the provided scope with the [data-module] attribute to the appropriate module

Kind: static method of ui
Returns: boolean - Was the scope successfully bound?

ParamTypeDescription
scopeobjectThe HTML element to search for module elements within
deferSelectorstringAn optional selector to filter items you don't wish to bind

ui.registerModule(moduleName, ClassReference, defaultConfiguration) ⇒ boolean

Registers a module for binding

Kind: static method of ui
Returns: boolean - Was the module successfully registered?

ParamTypeDescription
moduleNamestringThe name of the module to register
ClassReferenceclassThe reference to the class to bind
defaultConfigurationobjectA default configuration to pass to new instances

smize.utils : object

Provides generic utilities

Kind: static namespace of smize

utils.arrayFromArrayLike(arrayLike) ⇒ array

Creates an array from an array-like, including comma-separated strings

Kind: static method of utils
Returns: array - An array created from the array-like

ParamTypeDescription
arrayLikeobjectThe array-like to turn into an array

utils.objectFromString(string) ⇒ object

Attempts to parse a valid object from a string representation

Kind: static method of utils
Returns: object - The parsed object or null

ParamTypeDescription
stringstringThe string to parse as an object

utils.replaceTokens(originalString, tokenSources, removeRemainder) ⇒ string

Replaces tokens in the {token} format with key values from one or more objects

Kind: static method of utils
Returns: string - The new string with all tokens replaced

ParamTypeDescription
originalStringstringThe string to perform the token replacement on
tokenSourcesobjectOne or more objects to find tokens in
removeRemainderbooleanRemove the remaining tokens, defaults to false

utils.resolveBits(bits, expectedType, root) ⇒ object

Traverses an object to resolve the dot-notated bits as nested items

Kind: static method of utils
Returns: object - The type-correct bit or null

ParamTypeDescription
bitsstringThe bits to resolve
expectedTypestringThe expected type of the final bit, defaults to object
rootobjectThe root object to traverse, defaults to window

utils.stringFromObject(obj) ⇒ string

Attempts to create a string representation of an object

Kind: static method of utils
Returns: string - The string representation of the object or ''

ParamTypeDescription
objobjectThe object to stringify

smize.valid : object

Provides generic utilities for validation

Kind: static namespace of smize

valid.isDocumentValid() ⇒ boolean

Determines if the document object is available

Kind: static method of valid
Returns: boolean - Is document valid?

valid.isFalsy(value) ⇒ boolean

Quickly determine if a value is falsy

Kind: static method of valid
Returns: boolean - Was the value falsy?

ParamTypeDescription
valueobjectThe value to verify

valid.isOfType(value, checkType) ⇒ boolean

Checks that an object is of the desired type

Kind: static method of valid
Returns: boolean - Is the value of the requested type?

ParamTypeDescription
valueobjectThe value to verify
checkTypestringThe type to check the value against

valid.isTruthy(value) ⇒ boolean

Quickly determine if a value is truthy

Kind: static method of valid
Returns: boolean - Was the value truthy?

ParamTypeDescription
valueobjectThe value to verify

valid.isValidArray(value) ⇒ boolean

Determines if an object is an array-like

Kind: static method of valid
Returns: boolean - Is the value an array-like?

ParamTypeDescription
valueobjectThe value to verify

valid.isValidCountryCode(countryCode) ⇒ boolean

Determines if a value is a valid country code string

Kind: static method of valid
Returns: boolean - Was the input a valid country code?

ParamTypeDescription
countryCodeobjectThe value to test as a valid country code

valid.isValidObject(value) ⇒ boolean

Determines is of type 'object' and non-null

Kind: static method of valid
Returns: boolean - Is the value a valid object?

ParamTypeDescription
valueobjectThe value to verify

valid.isValidString(value) ⇒ boolean

Determines is of type 'string' and non-empty

Kind: static method of valid
Returns: boolean - Is the value a string?

ParamTypeDescription
valueobjectThe value to verify

valid.isWindowValid() ⇒ boolean

Determines if the window object is available

Kind: static method of valid
Returns: boolean - Is window valid?

valid.validBoolean(value, defaultValue) ⇒ boolean

Generates a valid boolean

Kind: static method of valid
Returns: boolean - The resulting boolean value

ParamTypeDescription
valueobjectThe value to validate as a boolean
defaultValueobjectAn optional default value to return

valid.validNumber(value, defaultValue) ⇒ number

Generates a valid number

Kind: static method of valid
Returns: number - The resulting number value
Todo

  • Eliminate try/catch
ParamTypeDescription
valueobjectThe value to validate as a number
defaultValueobjectAn optional default value to return

valid.validObject(value, defaultValue) ⇒ object

Generates a valid object

Kind: static method of valid
Returns: object - The resulting object
Todo

  • Eliminate try/catch
ParamTypeDescription
valueobjectThe value to validate as an object-type
defaultValueobjectAn optional default value to return

valid.validString(value, defaultValue) ⇒ string

Generates a valid string

Kind: static method of valid
Returns: string - The resulting string value

ParamTypeDescription
valueobjectThe value to validate as a string
defaultValueobjectAn optional default value to return

smize.ns(bitParts, root) ⇒ object

Builds a namespace with strict rules around extension

Kind: static method of smize
Returns: object - A namespace instance to extend

ParamTypeDescription
bitPartsstringThe dot-notated namespace bits to split
rootobjectThe root object to extend
1.2.2

5 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago