Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
The 'mout' npm package is a comprehensive utility library that provides a wide range of functions for various tasks such as array manipulation, object handling, string operations, and more. It is designed to be modular, allowing developers to include only the specific utilities they need.
Array Utilities
Mout provides various array manipulation functions such as shuffle, flatten, and unique. In this example, the 'shuffle' function is used to randomly shuffle the elements of an array.
const mout = require('mout');
const arr = [1, 2, 3, 4, 5];
const shuffled = mout.array.shuffle(arr);
console.log(shuffled);
Object Utilities
Mout offers a range of object utilities like deep cloning, merging, and key extraction. This example demonstrates the 'keys' function, which retrieves all the keys of an object.
const mout = require('mout');
const obj = { a: 1, b: 2, c: 3 };
const keys = mout.object.keys(obj);
console.log(keys);
String Utilities
String manipulation functions such as capitalize, trim, and escape are available in Mout. The example shows the 'capitalize' function, which capitalizes the first letter of a string.
const mout = require('mout');
const str = 'hello world';
const capitalized = mout.string.capitalize(str);
console.log(capitalized);
Function Utilities
Mout includes function utilities like debounce, throttle, and memoize. This example uses the 'debounce' function to limit the rate at which a function can be executed.
const mout = require('mout');
const debounce = mout.function.debounce;
const log = () => console.log('Debounced!');
const debouncedLog = debounce(log, 1000);
debouncedLog();
Number Utilities
Number utilities such as round, clamp, and random are part of Mout. The example demonstrates the 'round' function, which rounds a number to a specified number of decimal places.
const mout = require('mout');
const num = 123.456;
const rounded = mout.number.round(num, 2);
console.log(rounded);
Lodash is a modern JavaScript utility library delivering modularity, performance, and extras. It provides a wide range of utility functions for arrays, objects, strings, and more, similar to Mout. Lodash is known for its performance optimizations and extensive documentation.
Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. It offers similar functionalities to Mout, such as array and object manipulation, but is generally considered less performant than Lodash.
Ramda is a practical functional library for JavaScript programmers. It focuses on immutability and pure functions, providing utilities for functional programming. While it offers similar utilities to Mout, Ramda emphasizes a functional approach and currying.
Modular JavaScript Utilities.
All code is library agnostic and consist mostly of helper methods that aren't directly related with the DOM, the purpose of this library isn't to replace Dojo, jQuery, YUI, Mootools, etc, but to provide modular solutions for common problems that aren't solved by most of them. Consider it as a crossbrowser JavaScript standard library.
mout also works on node.js, just run:
npm install mout
It will download mout from the NPM repository and convert the AMD modules into a node.js compatible format using nodefy, there is no extra overhead, you can use it like a regular node.js package.
// you can load individual methods
var map = require('mout/array/map');
map([1, 2], function(v){ return val * val; }); // [1, 4]
// a single package
var stringUtils = require('mout/string');
stringUtils.camelCase('Foo Bar'); // "fooBar"
// or the whole lib
var utils = require('mout');
console.log( utils.math.clamp(100, 0, 50) ); // 50
Since code is very modular (broken into multiple files) it is really important that you run an optimizer before deploying the code to a server, otherwise you may end up having too many file requests which can degrade load-time performance a lot. See RequireJS optimization for more info.
Fork the project on Github: https://github.com/mout/mout
"Write clearly, don't be too clever" - The Elements of Programming Style
Avoid unnamed functions and follow the other modules structure. By only using named functions it will be easier to extract the code from the AMD module if needed and it will also give better error messages, JavaScript minifiers like Google Closure Compiler and UglifyJS will make sure code is as small/optimized as possible.
"Make it clear before you make it faster." - The Elements of Programming Style
Be sure to always create tests for each proposed module. Features will only be merged if they contain proper tests and documentation.
"Good code is its own best documentation." - Steve McConnell
We should do a code review before merging to make sure names makes sense and implementation is as good as possible.
Check the contributors list at github.
The build script have a set of very helpful commands, run npm install --dev
(only required once) and then check the available commands:
node build --help
The build script can be used to update packages and specs files:
node build pkg
The packages/specs are automatically updated every time you run npm test
as
well.
You can also add new modules with the command node build add package/moduleName
, this will create a new module src/package/moduleName.js
and also a failing spec tests/spec/package/spec-moduleName.js
.
Tests can be found inside the tests
folder, to execute them in the browser
open the tests/runner.html
. The same tests also work on node.js by running
npm test
.
We should have tests for all methods and ensure we have a high code coverage through our continuous integration server (travis). When you ask for a pull request Travis will automatically run the tests on node.js and check the code coverage as well.
We run node build pkg
automatically before any npm test
, so specs and
packages should always be in sync. (will avoid human mistakes)
To check code coverage run npm test --coverage
, it will generate the reports
inside the coverage
folder and also log the results. Please note that node.js
doesn't execute all code branches since we have some conditionals that are only
met on old JavaScript engines (eg. IE 7-8), so we will never have 100% code
coverage (but should be close to it).
The documentation is generated based on markdown files inside the
doc
folder using mdoc.
To compile the docs run:
node build doc
It will replace all the files inside the doc_html
folder.
Documentation files should be always up-to-date since modules are only
committed to the master
branch after they get proper tests and documentation.
Online documentation can be found at http://mout.github.com/docs/
Because AMD is awesome!
By keeping each function in a separate package we can require just the methods/packages that are required by our app and let the RequireJS optimizer bundle only what is currently being used. We also have an extra benefit that we split the methods into separate packages so we reduce the chance of name collisions and the code is more organized. AMD is flexible and enables things that wouldn't be possible with a different module system or with a conventional namespace approach (remapping a module, conditionally loading, etc).
Read these links if you still can't see why:
Also since most node.js modules are installed through npm it's easier to write
it using the AMD format and them convert into a node.js compatible format
during npm publish
or before each npm test
. We use
nodefy to convert the AMD modules
into regular node.js modules so it won't add any extra overhead for you node.js
apps. The opposite approach would be harder to automate.
PS: Your mileage may vary...
Online documentation can be found at http://mout.github.com/docs or inside the
doc
folder.
Released under the MIT License.
v0.1.0 (2013/01/09)
FAQs
Modular Utilities
The npm package mout receives a total of 198,391 weekly downloads. As such, mout popularity was classified as popular.
We found that mout demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.