Skip to content

Commit

Permalink
fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
catamphetamine committed Jul 23, 2015
1 parent bcd0c57 commit 6f7326f
Show file tree
Hide file tree
Showing 15 changed files with 685 additions and 40 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# test coverage folder
coverage
/coverage/

# npm modules
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules
/node_modules/

# npm errors
npm-debug.log

# github pages
gh-pages/
/gh-pages/

# for OS X users
.DS_Store
Expand All @@ -23,7 +23,7 @@ gh-pages/
*.sublime-workspace

# webpack build target folder
build-modules/
/babel-transpiled-modules/

# NUL
NUL
6 changes: 3 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
.travis.yml

# test coverage folder
coverage/
/coverage/

# npm errors
npm-debug.log

# github pages
gh-pages/
/gh-pages/

# workspace files are user-specific
*.sublime-workspace

# NUL
NUL
/NUL
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ const style = styler`
`
```

### ES6

This module is written in ES6/ES7 syntax and therefore requires [Babel](https://babeljs.io/) transpilation to support all the web browsers (not only the modern ones). Using [Babel](https://babeljs.io/) for ES6/ES7 transpilation in web development workflow is a common practice nowadays so just in case you happen to never used it in your projects - start using it now. It works everywhere: command line, Webpack, Browserify, whatever. In case you don't want to use Babel in your workflow for whatever reason you can still grab an already transpiled and concatenated build from the `build` folder.

### What's next

I can add the features you want (or you can do it). I can work on making errors more user friendly and helpful if anyone else uses this module.
Expand Down
119 changes: 119 additions & 0 deletions build-modules/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// if the variable is defined
'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});
exports.starts_with = starts_with;
exports.ends_with = ends_with;
exports.repeat = repeat;
exports.is_blank = is_blank;
exports.zip = zip;
exports.extend = extend;
var exists = function exists(what) {
return typeof what !== 'undefined';
};

exports.exists = exists;
// if the string starts with the substring

function starts_with(string, what) {
return string.indexOf(what) === 0;
}

// if the string ends with the substring

function ends_with(string, what) {
var index = string.lastIndexOf(what);
if (index < 0) {
return;
}
return index === string.length - what.length;
}

// repeat string N times

function repeat(what, times) {
var result = '';
while (times > 0) {
result += what;
times--;
}
return result;
}

// if the text is blank

function is_blank(text) {
return !exists(text) || !text.replace(/\s/g, '');
}

// zips two arrays

function zip(a, b) {
return a.map(function (_, index) {
return [a[index], b[index]];
});
}

// extends the first object with
/* istanbul ignore next: some weird transpiled code, not testable */

function extend() {
var _this = this,
_arguments = arguments;

var _again = true;

_function: while (_again) {
_len = objects = _key = to = from = last = intermediary_result = _iteratorNormalCompletion = _didIteratorError = _iteratorError = undefined;
_again = false;

for (var _len = _arguments.length, objects = Array(_len), _key = 0; _key < _len; _key++) {
objects[_key] = _arguments[_key];
}

var to = objects[0];
var from = objects[1];

if (objects.length > 2) {
var last = objects.pop();
var intermediary_result = extend.apply(_this, objects);
_this = undefined;
_arguments = [intermediary_result, last];
_again = true;
continue _function;
}

var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
for (var _iterator = Object.keys(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var key = _step.value;

if (typeof from[key] === 'object' && exists(to[key])) {
to[key] = extend(to[key], from[key]);
} else {
to[key] = from[key];
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator['return']) {
_iterator['return']();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}

return to;
}
}
Loading

0 comments on commit 6f7326f

Please sign in to comment.