Collection of SweetJS macros.
npm install sweet-helpers --save-devUsing with Gulp
var gulp = require('gulp'),
sweetjs = requier('gulp-sweetjs');
gulp.task('sweetjs', function () {
gulp.src('./myFile.js')
.pipe(sweetjs({modules: ['./node_modules/sweet-helpers/index.sjs']}))
.pipe(gulp.dest('./public/js'));
});
gulp.task('default', ['sweetjs']);Template
undef$Result
void 0Returns true if the specified value is undefined.
Template
isUndef$(foo)Or
foo::isUndef$()Result
typeof foo === 'undefined'Returns true if the specified value isn't undefined.
Template
isNotUndef$(foo)Or
foo::isNotUndef$()Result
typeof foo !== 'undefined'Returns true if the specified value isn't null or undefined.
Template
isSet$(foo)Or
foo::isSet$()Result
typeof foo !== 'undefined' && foo !== nullReturns true if the specified value is null or undefined.
Template
isNotSet$(foo)Or
foo::isNotSet$()Result
typeof foo === 'undefined' || foo === nullReturns true if the specified value is null.
Template
isNull$(foo)Or
foo::isNull$()Result
typeof foo !== 'undefined' && foo === nullReturns true if the specified value isn't null.
Template
isNotNull$(foo)Or
foo::isNotNull$()Result
typeof foo === 'undefined' || foo !== nullReturns true if the specified value is boolean.
Template
isBoolean$(foo)Or
foo::isBoolean$()Result
typeof foo === 'boolean'Returns true if the specified value isn't boolean.
Template
isNotBoolean$(foo)Or
foo::isNotBoolean$()Result
typeof foo !== 'boolean'Returns true if the specified value is a string.
Template
isString$(foo)Or
foo::isString$()Result
typeof foo === 'string'Returns true if the specified value isn't a string.
Template
isNotString$(foo)Or
foo::isNotString$()Result
typeof foo !== 'string'Returns true if the specified value is a number.
Template
isNumber$(foo)Or
foo::isNumber$()Result
typeof foo === 'number'Returns true if the specified value is a number.
Template
isNotNumber$(foo)Or
foo::isNotNumber$()Result
typeof foo !== 'number'Returns true if the specified value is numeric.
Template
isNumber$(foo)Or
foo::isNumber$()Result
typeof foo === 'number' && isFinite(foo)Returns true if the specified value isn't numeric.
Template
isNotNumeric$(foo)Or
foo::isNotNumeric$()Result
typeof foo !== 'number' || !isFinite(foo)Returns true if the specified value is NaN.
Template
isRealNaN$(foo)Or
foo::isRealNaN$()Result
typeof foo === 'number' && isNaN(foo)Returns true if the specified value isn't NaN.
Template
isNotRealNaN$(foo)Or
foo::isNotRealNaN$()Result
typeof foo !== 'number' || !isNaN(foo)Returns true if the specified value is a function.
Template
isFunction$(foo)Or
foo::isFunction$()Result
typeof foo === 'function'Returns true if the specified value isn't a function.
Template
isNotFunction$(foo)Or
foo::isNotFunction$()Result
typeof foo !== 'function'Returns true if the specified value instance of a base object.
Template
instanceof$(foo, String)Or
foo::instanceof$(String)Result
foo instanceof String || foo && foo.constructor && foo.constructor.name === String.nameReturns [[class]] of the specified value.
Template
type$(foo)Or
foo::type$()Result
({}).toString.call(foo)Returns a link for an iterator of the specified value.
Template
iterator$(foo)Or
foo::iterator$()Result
typeof foo !== 'undefined' && foo !== null ?
(typeof foo['@@iterator'] === 'function' ?
foo['@@iterator'] : typeof Symbol === 'function' ?
foo[Symbol['iterator']] : void 0) : void 0Converts the specified value to a number.
Template
number$(foo)Or
foo::number$()Result
(+foo)Converts the specified value to a string.
Template
string$(foo)Or
foo::string$()Result
(foo + '')Converts the specified value to boolean.
Template
boolean$(foo)Or
foo::boolean$()Result
!!fooReturns an object for working with macro functions.
Gets the first non false property from an object.
Template
use$(foo).get('foo', 'bar')Or
foo::get$('foo', 'bar')Result
foo['foo'] || foo['bar']Returns true if all specified properties are exists in an object.
Template
use$(foo).in('foo', 'bar')Or
foo::in$('foo', 'bar')Result
'foo' in foo && 'bar' in fooReturns true if all specified properties aren't exists in an object.
Template
use$(foo).not('foo', 'bar')Or
foo::not$('foo', 'bar')Result
'foo' in foo === false && 'bar' in foo === falseReturns true if any of specified properties are exists in an object.
Template
use$(foo).some('foo', 'bar')Or
foo::some$('foo', 'bar')Result
'foo' in foo || 'bar' in fooDecorates a function.
Template
var foo = decorate$(bar, car) :: function () {
return 1;
};Or
var foo = decorate$(bar, car) || function () {
return 1;
};Result
var foo = car(bar(function () {
return 1;
}));The MIT License.