diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,21 @@ +{ + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": [ "error", "single" ], + "semi": ["error", "always"], + "linebreak-style": [ "error", "unix" ] + }, + "env": { + "es6": true, + "node": true, + "mocha": true, + "jasmine": true + }, + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true, + "impliedStrict": true + }, + "extends": "eslint:recommended" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ec41ffc --- /dev/null +++ b/.gitignore @@ -0,0 +1,140 @@ +# Created by https://www.gitignore.io/api/osx,vim,node,linux,windows + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +### OSX ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Vim ### +# swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-v][a-z] +[._]sw[a-p] +# session +Session.vim +# temporary +.netrwhist +# auto-generated tag files +tags + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/osx,vim,node,linux,windows diff --git a/index.js b/index.js new file mode 100644 index 0000000..22e138d --- /dev/null +++ b/index.js @@ -0,0 +1,9 @@ +'use strict'; + +const fp = require('./lib/fp.js'); + +module.exports = exports = {}; + +process.argv.slice(2).forEach( + (val, index, array) => fp.map(array, + (ele) => console.log(ele.toUpperCase()))); diff --git a/lib/fp.js b/lib/fp.js new file mode 100644 index 0000000..de2b55a --- /dev/null +++ b/lib/fp.js @@ -0,0 +1,46 @@ +'use strict'; + +module.exports = exports = {}; + +exports.map = (arr, callback) => { + if(typeof(arr) !== 'object') return 'first parameter must be array'; + if(typeof(callback) !== 'function') return 'second parameter must be callback function'; + return Array.prototype.map.call(arr, callback); +}; + +let mapResults = exports.map([1, 2, 3], (ele) => ele * 2); +console.log('map results:', mapResults); + +exports.filter = (arr, callback) => { + if(typeof(arr) !== 'object') return 'first parameter must be array'; + if(typeof(callback) !== 'function') return 'second parameter must be callback function'; + return Array.prototype.filter.call(arr, callback); +}; + +let filterResults = exports.filter([1, 2, 3], (ele) => ele >= 2); +console.log('filter results:', filterResults); + +exports.reduce = (arr, callback) => { + if(typeof(arr) !== 'object') return 'first parameter must be array'; + if(typeof(callback) !== 'function') return 'second parameter must be callback function'; + return Array.prototype.reduce.call(arr, callback); +}; + +let reduceResult = exports.reduce([1, 2, 3], (ele, i) => ele + i); +console.log('reduce results:', reduceResult); + +exports.concat = (arrOne, arrTwo) => { + if((typeof(arrOne) !== 'object') || (typeof(arrTwo) !== 'object')) return 'must have two arrays as parameters'; + return Array.prototype.concat.apply(arrOne, arrTwo); +}; + +let concatResult = exports.concat([1, 2, 3], [4, 5, 6]); +console.log('concat results:', concatResult); + +exports.splice = (arr, parameters) => { + if(typeof(arr) !== 'object') return 'first parameter must be array'; + return Array.prototype.splice.call(arr, parameters); +}; + +let spliceResults = exports.splice([1, 2, 3], (1, 1)); +console.log('splice results:', spliceResults); diff --git a/package.json b/package.json new file mode 100644 index 0000000..9dcce76 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "02-tools_and_context", + "version": "1.0.0", + "description": "![cf](https://i.imgur.com/7v5ASc8.png) 02: Tools and Context ======", + "main": "index.js", + "directories": { + "test": "test" + }, + "scripts": { + "lint": "eslint .", + "test": "mocha" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/loganabsher/02-tools_and_context.git" + }, + "author": "Logan Absher", + "license": "MIT", + "bugs": { + "url": "https://github.com/loganabsher/02-tools_and_context/issues" + }, + "homepage": "https://github.com/loganabsher/02-tools_and_context#readme", + "devDependencies": { + "chai": "^4.1.0" + } +} diff --git a/test/fp-test.js b/test/fp-test.js new file mode 100644 index 0000000..aaf43f9 --- /dev/null +++ b/test/fp-test.js @@ -0,0 +1,16 @@ +'use strict'; + +const fp = require('../lib/fp.js'); +const expect = require('chai').expect; + +const funcNames = ['map', 'filter', 'reduce', 'concat', 'splice', 'notFunctionFail']; + +describe('Fp Module', () => { + it('Should be type \"object\"', () => expect(fp).to.be.an('object')); + funcNames.forEach((ele) => { + describe(`#${ele}`, () => { + it(`Should have ${ele} exist`, () => expect(fp).to.have.property(ele)); + it('Should be type \"function\"', () => expect(fp[ele]).to.be.a('function')); + }); + }); +});