smize

1.2.2 • Public • Published

smize : object

Provides the `smize` library - Simple Module InitialiZEr

Quickly build controller classes, with a collection of composable/extendable classes and common utilities.

Examples can be found in `dist/index.html`

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

Name Type Description
classPath string The path to the class in the global namespace
lastResponse object The last response from an AJAX call
lastStatus string The last status from an AJAX call
lastXHR object The last XHR object
scope object The class instance that initialized this composable

new AJAX(scope)

Creates a new, scoped instance of the AJAX class

Param Type Description
scope object The 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

Param Type Description
xhr object The XMLHttpRequest for the AJAX call
status string The status of the XMLHttpRequest
response object The 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

Param Type Description
xhr object The XMLHttpRequest for the AJAX call
status string The status of the XMLHttpRequest
response object The response object from the XMLHttpRequest

AJAX.call(config, stopOnError) ⇒ void

Places an AJAX call

Kind: static method of AJAX

Param Type Description
config object The 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
stopOnError boolean Should 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

Name Type Description
config object The initial configuration received from the constructor
el object The element this class instance was bound to
initialized boolean Has the instance initialized?
loaded boolean Has the instance loaded all content?
setup boolean Has the instance completed its setup tasks?
subscriptions array A collection of events to subscribe to

new Base(config, defaults)

Creates a new instance of the Base class

Param Type Description
config object Shared configuration for a group of class instances
defaults object The 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?

Param Type Description
config object The 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?

Param Type Description
eventNames object An 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?

Param Type Description
eventName string The name of the event to handle

composables.Debug

A composable class that provides Debug functionality

Kind: static class of composables
Properties

Name Type Description
classPath string The path to the class in the global namespace
debugEnabled boolean Is debug enabled? Defaults to global state
debugFilters array A collection of debug filters, defaults to global state
debugLevel string The allowed debug level, defaults to global state
scope object The class instance that initialized this composable

new Debug(scope, config)

Creates a new, scoped instance of the Debug class

Param Type Description
scope object The class instance that created this instance
config object Optional 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

Param Type Description
methodName string The name of the caller method
message string The 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?

Param Type Description
message string The 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?

Param Type Description
writeArguments array A 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

Param Type Description
cookieString string The 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

Param Type Description
itemName string The name of the localStorage item
defaultValue object An 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

Param Type Description
queryString string The 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

Param Type Description
itemName string The name of the sessionStorage item
defaultValue object An 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?

Param Type Description
itemName string The 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?

Param Type Description
itemName string The 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?

Param Type Description
itemName string The name of the localStorage item
value object The 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?

Param Type Description
itemName string The name of the sessionStorage item
value object The 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
Param Type Description
source object The source collection to read values from
target object The target collection add values to
concatArrays boolean Should arrays be merged?
dedupeArrays boolean Should 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

Param Type Description
originalFunction function The function call to be debounced
executionDelay number The number of milliseconds to delay by
callImmediately boolean Should 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?

Param Type Description
subscriptionName string The 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?

Param Type Description
subscriptionName string The name of the subscription
subscriber function The 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?

Param Type Description
elements object An HTML element or an Array-like of HTML elements
classNames object A 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)

Param Type Description
elements object An 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?

Param Type Description
elements object An HTML element or an Array-like of HTML elements
classNames object A 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?

Param Type Description
element object A 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

Param Type Description
elements object An 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?

Param Type Description
elements object An HTML element or an array-like of HTML elements
classNames object A 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

Adds a single dictionary key 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 - Was the key successfully added?

Param Type Description
dictionaryKey object The 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?

Param Type Description
dictionaryKeys array The 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

Param Type Description
date Date The date to format
language string The 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

Param Type Description
dateString string The date to format
language string The 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

Param Type Description
numberValue number | string The number to format, either a number or a string
language string The language/locale to format the number for
options object Configuration 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

Param Type Description
dictionaryKeyName string The name of the dictionary key to retrieve
language string The 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?

Param Type Description
dictionaryKeyName string The name of the dictionary key to set
language string The language/locale to set the value for
value string The 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

Name Type Description
currentBreakpoint object The 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?

Param Type Description
breakpointName string the name of the breakpoint to add
breakpointSettings object The 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?

Param Type Description
breakpointNames object A string, comma-separated list, or Array of breakpointNames
subscriberFunction function The 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

Param Type Description
breakpointName string The 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

Param Type Description
viewport object An 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

Param Type Description
breakpointName string The 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?

Param Type Description
breakpointName string The 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?

Param Type Description
element object The 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?

Param Type Description
scope object The HTML element to search for module elements within
deferSelector string An 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?

Param Type Description
moduleName string The name of the module to register
ClassReference class The reference to the class to bind
defaultConfiguration object A 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

Param Type Description
arrayLike object The 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

Param Type Description
string string The 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

Param Type Description
originalString string The string to perform the token replacement on
tokenSources object One or more objects to find tokens in
removeRemainder boolean Remove 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

Param Type Description
bits string The bits to resolve
expectedType string The expected type of the final bit, defaults to object
root object The 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 ''

Param Type Description
obj object The 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?

Param Type Description
value object The 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?

Param Type Description
value object The value to verify
checkType string The 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?

Param Type Description
value object The 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?

Param Type Description
value object The 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?

Param Type Description
countryCode object The 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?

Param Type Description
value object The 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?

Param Type Description
value object The 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

Param Type Description
value object The value to validate as a boolean
defaultValue object An 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
Param Type Description
value object The value to validate as a number
defaultValue object An 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
Param Type Description
value object The value to validate as an object-type
defaultValue object An 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

Param Type Description
value object The value to validate as a string
defaultValue object An 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

Param Type Description
bitParts string The dot-notated namespace bits to split
root object The root object to extend

Package Sidebar

Install

npm i smize

Weekly Downloads

1

Version

1.2.2

License

Apache-2.0

Unpacked Size

377 kB

Total Files

11

Last publish

Collaborators

  • eatyrghost