commit ba475dc6688e9699d5a3b5c3d0c769fefc989a39 Author: Martin Donnelly Date: Wed Mar 23 15:52:57 2016 +0000 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3be6088 --- /dev/null +++ b/.gitignore @@ -0,0 +1,190 @@ +### Archives template +# It's better to unpack these files and commit the raw source because +# git has its own built in compression methods. +*.7z +*.jar +*.rar +*.zip +*.gz +*.bzip +*.bz2 +*.xz +*.lzma +*.cab + +#packing-only formats +*.iso +*.tar + +#package management formats +*.dmg +*.xpi +*.gem +*.egg +*.deb +*.rpm +*.msi +*.msm +*.msp +### Windows template +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +### Xcode template +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ +DerivedData + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata + +## Other +*.xccheckout +*.moved-aside +*.xcuserstate +### OSX template +.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 + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk +### Node template +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git +node_modules + +# See http://help.github.com/ignore-files/ for more about ignoring files. + +# compiled output +/dist +/tmp + +# dependencies +/node_modules +/bower_components + +# misc +/.sass-cache +/connect.lock +/coverage/* +/libpeerconnection.log +npm-debug.log +testem.log diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..acd4f65 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,46 @@ +{ + "disallowKeywords": ["with"], + "disallowKeywordsOnNewLine": ["else"], + "disallowMixedSpacesAndTabs": true, + "disallowMultipleVarDecl": "exceptUndefined", + "disallowNewlineBeforeBlockStatements": true, + "disallowQuotedKeysInObjects": true, + "disallowSpaceAfterObjectKeys": true, + "disallowSpaceAfterPrefixUnaryOperators": true, + "disallowSpacesInFunction": { + "beforeOpeningRoundBrace": true + }, + "disallowSpacesInsideParentheses": true, + "disallowTrailingWhitespace": true, + "maximumLineLength": 120, + "requireCamelCaseOrUpperCaseIdentifiers": false, + "requireCapitalizedComments": true, + "requireCapitalizedConstructors": true, + "requireCurlyBraces": true, + "requireSpaceAfterKeywords": [ + "if", + "else", + "for", + "while", + "do", + "switch", + "case", + "return", + "try", + "catch", + "typeof" + ], + "requireSpaceAfterLineComment": true, + "requireSpaceAfterBinaryOperators": true, + "requireSpaceBeforeBinaryOperators": true, + "requireSpaceBeforeBlockStatements": true, + "requireSpaceBeforeObjectValues": true, + "requireSpacesInFunction": { + "beforeOpeningCurlyBrace": true + }, + "requireTrailingComma": false, + "requireEarlyReturn": true, + "validateIndentation": 2, + "validateLineBreaks": "LF", + "validateQuoteMarks": "'" +} diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..2f30d16 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,33 @@ +{ + "predef": [ + "server", + "document", + "window", + "-Promise" + ], + "browser": true, + "boss": true, + "curly": true, + "debug": false, + "devel": true, + "eqeqeq": true, + "evil": true, + "forin": false, + "immed": false, + "laxbreak": false, + "newcap": true, + "noarg": true, + "noempty": false, + "nonew": false, + "nomen": false, + "onevar": false, + "plusplus": false, + "regexp": false, + "undef": true, + "sub": true, + "strict": false, + "white": false, + "eqnull": true, + "esnext": true, + "unused": true +} diff --git a/index.js b/index.js new file mode 100644 index 0000000..dd7784d --- /dev/null +++ b/index.js @@ -0,0 +1,91 @@ +'use strict'; +/** + * + * User: Martin Donnelly + * Date: 2016-03-15 + * Time: 15:08 + * + */ + + +module.exports = { + reDashObject(source) { + var rObj = {}; + for (var item in source) { + if (source.hasOwnProperty(item)) { + let newName = item.replace('_', '-'); + rObj[newName] = source[item]; + } + } + + return rObj; + }, + unDashObject(source) { + var rObj = {}; + for (var item in source) { + if (source.hasOwnProperty(item)) { + let newName = item.replace('-', '_'); + rObj[newName] = source[item]; + } + } + + return rObj; + }, populateObject(source, reform) { + var rObj = {}; + for (var item in reform) { + if (source.hasOwnProperty()) { + rObj[item] = source[reform[item].from]; + } + } + + return rObj; + }, sanitiseObj: function(obj, methods) { + for (var item in methods) { + if (obj.hasOwnProperty(item)) { + if (typeof obj[item] === 'string') { + obj[item] = this.strip(obj[item], methods[item]); + } + } + } + return obj; + }, strip: function(text, loose) { + var _loose = loose || false; + var ch; + var s = []; + var SCRIPT_REGEX = /)<[^<]*)*<\/script>/gi; + + var CHECKCHARS = "0123456789" + // Numeric + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic + "abcdefghijklmnopqrstuvwxyz-'" + (_loose === false ? '' : "_,.!~*()@:+/\\"); + + if (typeof text === 'string') { + while (SCRIPT_REGEX.test(text)) { + text = text.replace(SCRIPT_REGEX, ''); + } + + for (var i = 0; i < text.length; i++) { + ch = text.charAt(i); + if (ch === ' ') { + s.push(' '); + } else if (ch.charCodeAt(0) < 255 && CHECKCHARS.indexOf(ch) !== -1) { + s.push(ch); + } + } + text = s.join('').trim(); + } + return text; + }, cloneTrim: function(from) { + var _out = {}; + if (typeof from === 'object' && Object.keys(from).length !== 0) { + // copy the required fields into the data object.. + for (var key in from) { + + if (from.hasOwnProperty(key)) { + _out[key] = typeof from[key] === 'string' ? from[key].trim() : from[key]; + } + } + } + return _out; + } + +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..a72395d --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "md-utils", + "version": "0.0.1", + "description": "A suite of useful misc utils", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Martin Donnelly ", + "license": "ISC" +}