npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@spices/basil

v1.8.0

Published

Javascript utility library for common tasks with a plugin system

Downloads

4

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 - 8

Install for VueJS

Installing @spices/basil for VueJS will give you some more feature:

  • Declare the $basil property to the Vue prototype that allows you to use all the utilities from the components.
  • Declare some mixins to 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):Promise

Returns 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 = false

When set to true, declare basil as a property of the global namespace aka window in the browser context.


basil.isArray(value:*):Boolean

Checks 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:*):Boolean

Checks 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:*):Boolean

Checks 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:*):boolean

Checks 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:*):boolean

Checks 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:*):boolean

Checks 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:*):boolean

Checks 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:*):boolean

Checks 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:*):boolean

Checks 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:*):Boolean

Checks 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]):number

Produces 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>):Promise

Run 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):String

Slugifies a String.

Arguments

value The value to "slugify".

Returns

The value "Slugified".


basil.uniqId([prefix:String = '']):String

Generates 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():string

Generate 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)