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

sand-util

v1.0.5

Published

Sand is a JavaScript utility library delivering modularity, consistency and more

Downloads

14

Readme

Sand

Sand is a JavaScript utility library delivering modularity, consistency and more, following UMD pattern.

Installation

Manual download

See my releases page for download.

NPM


npm install --save sand-util

Load

Directly by HTML using global variable sand.


<script src="sand.min.js"></script>

CommonJS


var sand = require('sand-util');

AMD


require('sand-util', function (sand) {
  ...
});

Usage

Please do your project use the default name for our library like sand.

Specifications and examples

In the sand there are specific methods for certain types.

Function

Throttle - Throttle calls to callback routine and ensure that it is not invoked any more often than delay milliseconds.


function method() {
  ...
}

var delay = 100;

sand.throttle(delay, method);

Debounce - Returns a function, that, as long as it continues to be invoked, will not be triggered. The function will be called after it stops being called for n milliseconds.


function method() {
  ...
}

var delay = 100;

sand.debounce(delay, method);
Array

Find - Find a object in an array according to informed rule.


var array = [{a: 2, b: 'b'}, {a: 1, b: 'a'}];

sand.find(array, {b: 'a'});       // {a: 1, b: 'a'}
sand.find(array, {b: 'k'});       // undefined

Filter - Creates a new array with all elements that pass the test implemented by callback.


var array = [{a: 2, b: 'b'}, {a: 1, b: 'a'}];

var callback = function (elem) {
    return elem.b === 'b';
};

sand.filter(array, callback);     // [{a: 2, b: 'b'}]

Map - Creates a new array with the results of calling the callback on every element in this array.


var array = [{a: 2, b: 'b'}, {a: 1, b: 'a'}];

var callback = function (elem) {
    return elem;
};

sand.map(array, callback);        // [{a: 2, b: 'b'}, {a: 1, b: 'a'}]

Sort - Sort an array according to informed key. Order default is asc.


var array = [{a: 2, b: 'b'}, {a: 1, b: 'a'}];

sand.sort(array, 'a');            // [{a: 1, b: 'a'}, {a: 2, b: 'b'}]
sand.sort(array, 'b', 'asc');     // [{a: 1, b: 'a'}, {a: 2, b: 'b'}]
sand.sort(array, 'a', 'desc');    // [{a: 2, b: 'b'}, {a: 1, b: 'a'}]
sand.sort(array, 'b', 'desc');    // [{a: 2, b: 'b'}, {a: 1, b: 'a'}]

Inject - Inject methods for manipulation. It does not inject methods in the prototype, it injects methods in the given array.

| Method | Description | | :-----------: | :------------------------------------------------------------------------ | | get | returns the object at the current position or in the given position | | set | change the current position of the array and call get | | previous | returns the object in the previous position found or false if there is no | | next | returns the object in the next position found or false if there is no |

example:


var array = [{a: 2, b: 'b'}, {a: 1, b: 'a'}];

sand.inject(array);

array.get();                      // {a: 2, b: 'b'}
array.get(1);                     // {a: 1, b: 'a'}

array.set({a: 1});                // {a: 1, b: 'a'}

array.get();                      // {a: 1, b: 'a'}
array.get(0);                     // {a: 2, b: 'b'}

array.previous();                 // {a: 2, b: 'b'}
array.previous();                 // false

array.next();                     // {a: 2, b: 'b'}
array.next();                     // {a: 1, b: 'a'}
array.next();                     // false
Object

Has key - Check if exists the key directly in object.


var object = {a: 1, b: 2, c: 3, d: 4, e: 5};

sand.hasKey(object, 'd');         // true
sand.hasKey(object, 't');         // false

Has value - Check if exists the value directly in object.


var object = {a: 1, b: 2, c: 3, d: 4, e: 5};

sand.hasValue(object, 4);         // true
sand.hasValue(object, 7);         // false

Inject - Inject methods for manipulation of keys. It does not inject methods in the prototype, it injects methods in the given object.

| Method | Description | | :-----------: | :--------------------------------------------------------------------- | | keys | returns all keys of object | | getKey | returns the key at the current position | | setKey | change the current position of the key and call getKey | | previousKey | returns the key in the previous position found or false if there is no | | nextKey | returns the key in the next position found or false if there is no |

example:


var object = {a: 'a', b: 'b', c: 'c', d: 'd', e: 'e'};

sand.inject(object);

object.keys();                    // ['a', 'b', 'c', 'd', 'e']

object.getKey();                  // 'a'
object.setKey('c');               // 'c'

object.nextKey();                 // 'd'
object.nextKey();                 // 'e'

object.previousKey();             // 'd'
object.previousKey();             // 'c'
Date

Now - Gets the current timestamp as integer.


sand.now();                       // example: 1432395347945
Number

Is number - Check if a value is number.


sand.isNumber('test');            // false
sand.isNumber('');                // false
sand.isNumber(0);                 // true
sand.isNumber(7);                 // true
sand.isNumber('9');               // true

Issues

For questions, bug reports, improve documentation, and feature request please search through existing issue and if you don't find and answer open a new one here. If you need support send me an email. You can also contact me for any non public concerns.

Contribution

When issuing a pull request, please exclude changes in the dist folder to avoid merge conflicts.

License

Sand is released under the MIT license. See LICENSE for details.

More

Sand is a work in progress, feel free to improve it.

References