<commit_before>JavaScript Snippet Collection
=============================

Description
-----------

Small collection of useful small snippets for JavaScript and 
[Node.js](http://www.nodejs.org). Designed to be lightweight, independent and 
undisruptive as much as possible.

Installation for Node.js
------------------------

Simplest way to install is to use [npm](http://npmjs.org/), just simply `npm install snippets`.

License
-------

MIT-style license, see [INSTALL.txt](http://github.com/jheusala/js-snippets/blob/master/LICENSE.txt).

Foreach Example
---------------

See [examples/](http://github.com/jheusala/js-snippets/tree/master/examples) for full examples.

Initialize our foreach function:

	var foreach = require('../lib/snippets.js').foreach;

Write each array element to console:

	var a = [1,2,3,4,5];
	foreach(a).do(function(v) { console.log(v); });
  
Write each object key=value pair to console:

	a = {'foo':1,'bar':2};
	foreach(a).do(function(v, k) { console.log(k+"="+v); });

Write single value to console:

	a = 'foobar';
	foreach(a).do(function(v) { console.log(v); });<commit_msg>Fixed require()<commit_after>JavaScript Snippet Collection
=============================

Description
-----------

Small collection of useful small snippets for JavaScript and 
[Node.js](http://www.nodejs.org). Designed to be lightweight, independent and 
undisruptive as much as possible.

Installation for Node.js
------------------------

Simplest way to install is to use [npm](http://npmjs.org/), just simply `npm install snippets`.

License
-------

MIT-style license, see [INSTALL.txt](http://github.com/jheusala/js-snippets/blob/master/LICENSE.txt).

Foreach Example
---------------

See [examples/](http://github.com/jheusala/js-snippets/tree/master/examples) for full examples.

Initialize our foreach function:

	var foreach = require('snippets').foreach;

Write each array element to console:

	var a = [1,2,3,4,5];
	foreach(a).do(function(v) { console.log(v); });
  
Write each object key=value pair to console:

	a = {'foo':1,'bar':2};
	foreach(a).do(function(v, k) { console.log(k+"="+v); });

Write single value to console:

	a = 'foobar';
	foreach(a).do(function(v) { console.log(v); });
{'fraction_non_alphanumeric': 0.21435018050541516, 'fraction_numerical': 0.00631768953068592, 'mean_word_length': 3.6673684210526316, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2666236', 'n_tokens_mistral': 726, 'n_tokens_neox': 687, 'n_words': 185}