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

smart-utils

v0.0.7

Published

Collection of util things

Downloads

306

Readme

smart-utils

Collection of util things

Usage

npm install smart-utils

Tagrize

Generate an tag name for HTML tags to angularjs components.

  • Where smartUtils turns to smart-utils
  • Where SmartUtils turns to smart-utils
  • Where ISmartUtils turns to i-smart-utils
  • Where SmartUtilsAndEtc turns to smart-utils-and-etc
var smartUtils = require('smart-utils');

var wordOne = "smartUtils";
var wordTwo = "SmartUtils";
var wordThre = "ISmartUtils";
var wordFour = "SmartUtilsAndEtc";

console.log(smartUtils.tagrize(wordOne));
console.log(smartUtils.tagrize(wordTwo));
console.log(smartUtils.tagrize(wordThre));
console.log(smartUtils.tagrize(wordFour));

EnsureDirectoryExists

Ensure the directory exists

var smartUtils = require('smart-utils');

function ensureDirectoryExists_callback(error) {
    if (error) {
        console.log('Houston, We\'ve Had a Problem');
    }
};

smartUtils.ensureDirectoryExists('C:/temp', ensureDirectoryExists_callback);

console.log('All ok.');

Now EnsureDirectoryExists with promise

var Promise = require('promise');
var smartUtils = require('smart-utils');

var ensureDirectoryExists = Promise.denodeify(smartUtils.ensureDirectoryExists);

ensureDirectoryExists('C:/temp')
    .then(() => {

        console.log('All right');
    }, (error) => {
        
        console.log('Houston, We\'ve Had a Problem');
    });

With promise but Q lib

var Q = require('q');
var smartUtils = require('smart-utils');

var ensureDirectoryExists = Q.denodeify(smartUtils.ensureDirectoryExists);

ensureDirectoryExists('C:/temp')
    .then(() => {

        console.log('All right');
    }, (error) => {
        
        console.log('Houston, We\'ve Had a Problem');
    });

With promise multi nivel path

var path = require('path');
var Promise = require('promise');
var smartUtils = require('smart-utils');

var ensureDirectoryExists = Promise.denodeify(smartUtils.ensureDirectoryExists);

ensureDirectoryExists(path.join('C:', 'temp'))
    .then(() => {
        return ensureDirectoryExists(path.join('C:', 'temp', 'smartUtils'));
    })
    .then(() => {
        return ensureDirectoryExists(path.join('C:', 'temp', 'smartUtils', 'multi'));
    })
    .then(() => {
        return ensureDirectoryExists(path.join('C:', 'temp', 'smartUtils', 'multi', 'nivel'));
    })
    .then(() => {

        console.log('Now the path "C:\\temp\\smartUtils\\multi\\nivel" exists ;D');
        console.log('All right');
    }, (error) => {
        
        console.log('Houston, We\'ve Had a Problem');
    });

ListDirectoryContentRecursive

List directory and file inside an directory recursively

var smartUtils = require('smart-utils');

function listDirectoryContentRecursive_callback(error, result) {
    
    if(error){
        console.log('Ooops, problems!');
        console.log(error);
        return;
    }

    for (var index = 0; index < result.length; index++) {
        var element = result[index];
        console.log(element);
    }
};

smartUtils.listDirectoryContentRecursive('C:/temp/', listDirectoryContentRecursive_callback);

ListDirectoryContent

List directory and files inside an directory with options or no to list recursively

var smartUtils = require('smart-utils');

function listDirectoryContent_callback(error, result) {
    
    if(error){
        console.log('Ooops, problems!');
        console.log(error);
        return;
    }

    for (var index = 0; index < result.length; index++) {
        var element = result[index];
        console.log(element);
    }
    
    console.log('----------------------------------------');
};

var options = {
    recursive: true
};

// With options to recursive
smartUtils.listDirectoryContent('C:/temp', options, listDirectoryContent_callback);

// Without options, list just que first directory level  
smartUtils.listDirectoryContent('C:/temp', listDirectoryContent_callback);

ObjectDeepFind

Get the value of an property deep into in a object, or not.
Do not ask me the utility of it ;D

var smartUtils = require('smart-utils');

var dataObject = {
    one: {
        two: {
            three: {
                value: "This is the final value!"
            },
            value: "This is not the final value! Go ahead!"
        },
        value: "This is the second level value."
    },
    value: "Yeap, first level value."
};

console.log(smartUtils.objectDeepFind(dataObject, 'value'));
console.log(smartUtils.objectDeepFind(dataObject, 'one.value'));
console.log(smartUtils.objectDeepFind(dataObject, 'one.two.value'));
console.log(smartUtils.objectDeepFind(dataObject, 'one.two.three.value'));

ReplaceAll

Replace all found values at once, without regex ;D.

var smartUtils = require('smart-utils');

var text = "object is a color, but object is a fruit to.";

console.log(smartUtils.replaceAll(text, "object", "orange"));
  

News

  • 0.0.1 Created the project, added tagrize function.
  • 0.0.2 Added ensureDirectoryExists function.
  • 0.0.3 Fix callback function of ensureDirectoryExists and added release to update npm package.
  • 0.0.4 Added listDirectoryContentRecursive function.
  • 0.0.5 Added objectDeepFind function.
  • 0.0.6 Added replaceAll function.
  • 0.0.7 Added listDirectoryContent function.

Thanks