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

clod

v0.2.5

Published

Utility library for JavaScript with basic functions.

Downloads

8

Readme

Clod

Is a utility library for JavaScript that provides support for the basic functions or functions that are most used in one project, like (isEmpty, isNil, isObject, isArray ...) without extending any core JavaScript objects.

Supports ECMAScript 6+ !!!

Adding functionality continues!

Note: The documentation uses yarn commands, but npm will also work. You can learn about Yarn here.

Install

$ yarn add clod

Usage

Import into the script

var clod = require('clod');

// OR
import clod from 'clod';

Modules

Variables used in the examples.

var obj = {length: 0, b: 2};
var arr = [1, 2, 3, 4];

var Person = function (first, last) {
  this.name = {
    first: first,
    last: last,
  };
};
var Friend = new Person('Max', 'Muster');

var str = 'DRFAAAAAAAXYZAAAAAAAAMUN';

cap

clod.cap('only first letter or'); // Only first letter or
clod.cap('or every word', true); // Or Every Word

isNil

clod.isNil(null); // true
clod.isNil(undefined); // true
clod.isNil(0); // false
clod.isNil([]); // false

isEmpty

clod.isEmpty({}); // true
clod.isEmpty(Person); // true
clod.isEmpty(Friend); // false
clod.isEmpty(arr); // false
clod.isEmpty([]); // true
clod.isEmpty(''); // true
clod.isEmpty(null); // true
clod.isEmpty(obj); // false

Parameter testing functions

clod.isString('test'); // true
clod.isObject(obj); // true
clod.isNumber(123.2); // true
clod.isNumber(0); // true
clod.isNull(null); // true
clod.isUndefined(undefined); // true
clod.isBoolean(false); // true
clod.isDate(new Date()); // true
clod.isFunction(Person); // true
clod.isRegExp(/[a-z]/i); // true
clod.isArray(arr); // true

keys

clod.keys(obj); // [ 'length', 'b' ]
clod.keys(arr); // []

first

clod.first(obj); // length
clod.first(arr); // undefined

rand

clod.rand(200); // 155
clod.rand(-100); // -77
clod.rand(-10); // -7

random

clod.random(); // length 12:  392978968529
clod.random(15); // max length: 755392978968529
clod.random(6); // 968529
clod.random(6, 2); // base 2: 110011
clod.random(6, 8); // base 8: 532314
clod.random(6, 16); // base 16: 13ad33

replaceAt

// str = DRFAAAAAAAXYZAAAAAAAAMUN

// Removes substring at different indexes
clod.replaceAt(str, 3); // AAAAAAAXYZAAAAAAAAMUN
clod.replaceAt(str, 3, 10); // DRFAAAAAAAAAAAAAAAMUN
clod.replaceAt(str, 3, 21); // DRFAAAAAAAXYZAAAAAAAA

// Replaces substring at different indexes
clod.replaceAt(str, 3, 0, '---'); // ---AAAAAAAXYZAAAAAAAAMUN
clod.replaceAt(str, 3, 10, '...'); // DRFAAAAAAA...AAAAAAAAMUN
clod.replaceAt(str, 3, 21, '+++'); // DRFAAAAAAAXYZAAAAAAAA+++

rnd

// Used all sets of characters
clod.rnd(12); // J<^kl)OS+{Yv

// Used only numbers
clod.rnd(8, clod.rnd.num); // 84404908

// Used only lower alpha
clod.rnd(22, clod.rnd.alphaLower); // xkrjbluejcvtbuymuxzbjp

// Used only upper alpha
clod.rnd(18, clod.rnd.alphaUpper); // LRERONFKSEVBUFSCJR

// Used only special characters
clod.rnd(35, clod.rnd.special); // &;/{}?["/_[^^#^#_{$&=]&%_!?">=(.-.*

// Used random input characters
clod.rnd(17, [...'AB,0X-zM']); // ,B,,A,XMMMXMM,,X

merge

// Merge two or more Objects into one
clod.merge({}, 1); // {}
clod.merge({a: 1}, 1); // { a: 1 }
clod.merge({a: 5}, {b: 2}); // { a: 5, b: 2 }
clod.merge({a: 5}, {a: 1, b: 2}, {b: 6, c: 4}); // { a: 1, b: 6, c: 4 }
clod.merge([{a: 1}, {a: 3}]); // { 0: { a: 1 }, 1: { a: 3 } }

License

ISC