New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

man

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

man

JS utilities & helpers

  • 1.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
42
decreased by-22.22%
Maintainers
1
Weekly downloads
 
Created
Source

man – JS utilities & helpers

Base

Types

var _ = require('man');

_.type(null); // => null

Collections

var _ = require('man');

// Convert to array
_.arr(arguments);

// Filter values with certain type
_.filterType(list, 'string');
_.filterTypes(list, ['number', 'undefined']);

// Remove values with certain type
_.removeType(list, 'string');
_.removeTypes(list, ['number', 'undefined']);

// Create object with all properties set to true
_.flagger(['prop1', 'prop2']); // => { prop1: true, prop2: true }

// Improved iteration
_.for(list)
    .check(function (value, i) {
        if (_.type(value) === 'string') {
            return false;
        }
        return true;
    })
    .catch(function (err) {
        console.log(err.stack);
    })
    .each(function (value, i) {
        // ...
    })
    .done(function () {
        
    });

// Map collection to object
_.mapToObject(list, function (value, i) {
    return {
        name: 'item' + i,
        value: value
    };
});

Events

var _ = require('man');

var obj = {};

_.initEvents(obj);

obj.on('test', function (a, b) {
    // ...
});

obj.emit('test', 1, 2);

Math

var _ = require('man');

// Random number
_.rand(min, max);

// Generates random unique key
_.randomKey([prefix]);

// Generates counter-based unique id
_.id([prefix]);

// Rounds number to top or bottom margin
_.roundMin(85, 20); // => 80
_.roundMax(85, 20); // => 100

Objects

var _ = require('man');

// Create new object with properties of received objects
_.collect(obj1, obj2, obj3);

// Extends `target` object with properties of `source`, replacing only undefined values
_.extendUndefined(target, source);

// Set `name` property of `obj` object recursively
var obj = {};
_.set(obj, 'prop1.prop2.prop3', true);
obj // => { prop1: { prop2: { prop3: true } } }

// Returns `name` property of `obj` object recursively
var obj = {
    prop1: {
        prop2: {
            prop3: true
        }
    }
};
_.get(obj, 'prop1.prop2.prop3'); // => true 

// Flattens object to flat structure
var obj = {
    prop1: {
        prop2: {
            prop3: true
        }
    }
};
_.flat(obj);
obj // => { 'prop1.prop2.prop3': true }

// Defines object's properties (same as Object.defineProperty and Object.defineProperties)
_.define(obj, name, prop);
_.define(obj, props);

Strings

var _ = require('man');

// Removes HTML-tags from string
_.removeTags(str);

// Trim string by specified symbol
_.trim(str, symbol);
_.trimLeft(str, symbol);
_.trimRight(str, symbol);

/*
Search `sub` in `str` and returns array with objects {
    content: String,
    groups: Array,
    length: Number,
    start: Number,
    finish: Number
}
*/
_.search(str, sub, ignoreCase);

// Replace all found `sub` in `str` with `source`
_.replace(str, sub, source, ignoreCase)

// Same as `search` but returns `false` if nothing found
_.find(str, sub, ignoreCase);

// Capitalizes string
_.capitalize(str);

// Decode ASCII string
_.decodeChars(buffer);

// Decode Unicode string
_.decodeUnicode(buffer);

CML

var _ = require('man');

_.cmlParse(source); // => object
_.cml(data); // => document

Node

Builder

var _ = require('man');

_.buildClient('index.js', {
    // Output filename
    output: 'app.min.js',
    // Babel-transform ECMAScript6-features
    transform: true,
    // Minify source
    min: true
}).then(function (source) {
    // ...
});

FS

var _ = require('man');

// Create new random temp directory name
_.tmpDir()

// Create new random temp filename 
_.tmpFile(prefix)

// Read dir
_.rdir(dirname, {
    recursive: false,
    fullPath: false,
    onlyFiles: false,
    onlyDirs: false,
    ext: ['.js', '.md'],
    ignoreExt: ['.txt']
});
_.rdirAll(dirname);

// Read & write files
_.read(filename, isBin)
_.readb(filename)
_.write(filename, content)
_.copy(from, to)
_.copyStream(from, to).then
_.remove(filename)

// Test filenames
_.exists(filename)
_.isFile(filename)
_.isDir(filename)
_.firstExists(filenames, dirname, onlyFiles)
_.firstExistsFile(filenames, dirname)

CML

var _ = require('man');

_.cmlDump(dir, outputJSONFilename);
_.cmlDir(dir); // => document
_.cmlFile(filename); // => document

Browser

CML

_.cmlLoadUrl(url).then(function (data) {
    // ...
});

Request

_.get(url)
    .then(function (content) {
        // ...
    });
    
_.getJSON(url)
    .then(function (data) {
        // ...
    });

FAQs

Package last updated on 18 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc