@spices/basil
v1.8.0
Published
Javascript utility library for common tasks with a plugin system
Readme
Spices - Basil
A JavaScript utility library for common tasks with a plugin system.
Motivations
- To have a go to for simple tasks without the over-weight of a lodash like package.
- To allow a plugin system to extends that logic for extensibility but more on demand.
How does it works?
Install by default
By default @spices is build for VueJS but it is an option for basil.
import { basil } from '@spices/basil'
let n = basil.random(1, 8); // yield a number between 1 - 8Install for VueJS
Installing @spices/basil for VueJS will give you some more feature:
- Declare the
$basilproperty to the Vue prototype that allows you to use all the utilities from the components. - Declare some
mixinsto easily transform your data from the components.
import Vue from 'vue'
import { basil, install } from '@spices/basil`
Vue.use(install)API
basil.debounce(fn:Function, [wait:Number=0], [options:Object={}]):Function`Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked. The debounced function comes with a cancel method to cancel delayed func invocations and a flush method to immediately invoke them. Provide options to indicate whether func should be invoked on the leading and/or trailing edge of the wait timeout. The func is invoked with the last arguments provided to the debounced function. Subsequent calls to the debounced function return the result of the last func invocation.
Arguments
fn (Function): The function to debounce.
[wait=0] : The number of milliseconds to delay.
[options={}] : The options object.
[options.leading=false] : Specify invoking on the leading edge of the timeout.
[options.maxWait] : The maximum time func is allowed to be delayed before it's invoked.
[options.trailing=true] : Specify invoking on the trailing edge of the timeout.
Returns
Returns the new debounced function.
from: lodash
basil.delay(wait:Number):PromiseReturns a Promise that will be resolved after wait milliseconds.
Arguments
wait The number of milliseconds to delay.
Returns
Returns the Promise of completion.
basil.get(object:Object, path:Array|String, [defaultValue]):*Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
Argument
object The object to query.
path <Array|string> The path of the property to get.
[defaultValue] The value returned for undefined resolved values.
Returns
Returns the resolved value.
from: lodash
basil.global:Boolean = falseWhen set to true, declare basil as a property of the global namespace aka window in the browser context.
basil.isArray(value:*):BooleanChecks if value is classified as an Array object.
Arguments
value The value to check.
Returns
Returns true if value is an array, else false.
from: lodash
basil.isBoolean(value:*):BooleanChecks if value is classified as a Boolean primitive or object.
Arguments
value The value to check.
Returns
Returns true if value is a boolean, else false.
from: lodash
basil.isEmpty(value:*):BooleanChecks if value is an empty object, collection, map, or set.
Objects are considered empty if they have no own enumerable string keyed properties.
Array-like values such as arguments objects, arrays, buffers, strings, or jQuery-like collections are considered empty if they have a length of 0. Similarly, maps and sets are considered empty if they have a size of 0.
Arguments
value The value to check.
Returns
Returns true if value is a empty, else false.
from: lodash
basil.isFunction(value:*):booleanChecks if value is classified as a Function object.
Arguments
value The value to check.
Returns
Returns true if value is a function, else false.
from: lodash
basil.isNumber(value:*):booleanChecks if value is classified as a Number primitive or object.
Arguments
value The value to check.
Returns
Returns true if value is a number, else false.
from: lodash
basil.isNil(value:*):booleanChecks if value is null or undefined.
Arguments
value The value to check.
Returns
Returns true if value is nullish, else false.
from: lodash
basil.isObject(value:*):booleanChecks if value is the language type of Object. (e.g. arrays, functions, objects, regexes, new Number(0), and new String(''))
Arguments
value The value to check.
Returns
Returns true if value is an object, else false.
from: lodash
basil.isRegExp(value:*):booleanChecks if value is classified as a RegExp primitive or object.
Arguments
value The value to check.
Returns
Returns true if value is a regexp, else false.
from: lodash
basil.isString(value:*):booleanChecks if value is classified as a String primitive or object.
Arguments
value The value to check.
Returns
Returns true if value is a String, else false.
from: lodash
basil.isSymbol(value:*):BooleanChecks if value is classified as a Symbol primitive or object.
Arguments
value The value to check.
Returns
Returns true if value is a symbol, else false.
from: lodash
basil.random([min:number=0], [max:number=1], [floating:boolean = false]):numberProduces a random number between the inclusive min and max bounds. If floating is true, a floating-point number is returned instead of an integer.
Arguments
min The inclusive minimum value.
max The inclusive maximum value.
floating Whether or not the result should be floating.
Returns
The random value.
basil.sequence(tasks:Array.<function>):PromiseRun an array of tasks in sequence, without overlap. Each task will be called with the arguments passed to when.sequence(), and each may return a promise or a value.
When all tasks have completed, the returned promise will resolve to an array containing the result of each task at the corresponding array position. The returned promise will reject when any task throws or returns a rejection.
Arguments
tasks The list of tasks to run
Returns
A promise of completion or rejection.
basil.slugify(value:String):StringSlugifies a String.
Arguments
value The value to "slugify".
Returns
The value "Slugified".
basil.uniqId([prefix:String = '']):StringGenerates a unique ID. If prefix is given, the ID is appended to it.
Arguments
[prefix=''] The value to prefix the ID with.
Returns
Returns the unique ID.
from: lodash
basil.uuid():stringGenerate a universally unique identifier (uuid)
Returns
A uuid String
Plugins
Basil comes at heart with a plugin system allowing to extends its abilities without flooding the codebase.
- [@spices/basil-i18n)(https://github.com/alexandremasy/spices-basil-i18n)
