Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/toddmotto/mapify
Map iteration for Arrays and Objects
https://github.com/toddmotto/mapify
Last synced: 11 days ago
JSON representation
Map iteration for Arrays and Objects
- Host: GitHub
- URL: https://github.com/toddmotto/mapify
- Owner: toddmotto
- License: other
- Created: 2015-04-18T21:51:06.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-04-18T23:31:16.000Z (over 9 years ago)
- Last Synced: 2024-10-11T08:10:41.353Z (29 days ago)
- Language: JavaScript
- Homepage:
- Size: 119 KB
- Stars: 14
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mapify.js [![Build Status](https://travis-ci.org/toddmotto/mapify.svg)](https://travis-ci.org/toddmotto/mapify)
Mapify is a 0.7KB standalone module for map iteration over Arrays and Objects, in the same fashion `Array.prototype.map` works, but also includes `Object` iteration support and is faster than `.map` itself.
### Array mapping
Creates a new `Array` with the results of calling a provided function on every element in this `Array`.##### Syntax
```javascript
mapify(arr, callback[, thisArg]);// Callback parameters
// currentValue: The current element being processed in the array.
// index: The index of the current element being processed in the array.
// array: The array being mapped.// thisArg (optional)
// Value to use as this when executing callback.
```##### Example
```javascript
var mapped = mapify([1, 3, 9], function (currentValue, index, array) {
return currentValue * currentValue;
})
console.log(mapped); // 1, 9, 81
```### Object mapping
Creates a new `Object` with the results of calling a provided function on every property in this `Object`.##### Syntax
```javascript
mapify(obj, callback[, thisArg]);// Callback parameters
// currentValue: The current element being processed in the object.
// propName: The name of the current property being processed in the object.
// object: The object being mapped.
//
// thisArg (optional)
// Value to use as this when executing callback.
```##### Example
```javascript
var mapped = mapify({ a: 1, b: 2, c: 3 }, function (currentValue, propName, object) {
return currentValue * currentValue;
})
console.log(mapped); // { a: 1, b: 4, c: 9 }
```## Installing with Bower
To install Mapify into your project using Bower, use the GitHub repository hook:```
bower install https://github.com/toddmotto/mapify.git
```## Manual installation
Drop your files into your required folders, make sure you're using the files from the `dist` folder, which is the compiled production-ready code. Ensure you place the script before the closing `
var mapped = mapify([1, 3, 9], function (currentValue, index, array) {
return currentValue * currentValue;
})
console.log(mapped);