Tabnine Logo For Javascript
template
Code IndexAdd Tabnine to your IDE (free)

How to use
template
function
in
lodash

Best JavaScript code snippets using lodash.template(Showing top 15 results out of 315)

origin: jonschlinkert/template-helpers

describe('last', function() {
 it('should return an empty string when undefined.', function() {
  assert.equal(template('<%= last() %>', imports)(), '');
 });

 it('should return the last item in an array.', function() {
  assert.equal(template('<%= last(arr) %>', imports)(context), 'h');
 });
 it('should return an array with the last two items in an array.', function() {
  assert.deepEqual(template('<%= last(arr, 2) %>', imports)(context), ['g', 'h'].toString());
 });
});
origin: jonschlinkert/template-helpers

describe('basename', function() {
  it('should return the basename:', function() {
   assert.strictEqual(template('<%= basename("a/b/c/e.js") %>', imports)(), 'e.js');
   assert.strictEqual(template('<%= path.basename("a/b/c/e.js") %>', imports)(), 'e.js');
  });
 });
origin: jonschlinkert/template-helpers

describe('first', function() {
 it('should return an empty string when undefined.', function() {
  assert.equal(template('<%= first() %>', imports)(), '');
 });

 it('should return the first item in an array.', function() {
  var fn = template('<%= first(foo) %>', imports);
  assert.equal(fn({foo: ['a', 'b', 'c']}), 'a');
 });

 it('should return an array with the first two items in an array.', function() {
  var fn = template('<%= first(foo, 2) %>', imports);
  assert.deepEqual(fn({foo: ['a', 'b', 'c']}), ['a', 'b'].toString());
 });
});
origin: jonschlinkert/template-helpers

describe('before', function() {
 it('should return an empty string when undefined.', function() {
  assert.equal(template('<%= before() %>', imports)(), '');
 });
 it('should return all of the items in an array before the given index.', function() {
  var fn = template('<%= before(arr, 5) %>', imports);
  assert.deepEqual(fn(context), ['a', 'b', 'c'].toString());
 });
});
origin: jonschlinkert/template-helpers

describe('isArray', function() {
 it('should return true if the value is an array.', function() {
  assert.equal(template('<%= isArray("foo") %>', imports)(), 'false');
  assert.equal(template('<%= isArray(["foo"]) %>', imports)(), 'true');
 });
});
origin: jonschlinkert/template-helpers

describe('reverse', function() {
  it('should return an empty string when undefined.', function() {
   assert.equal(template('<%= reverse() %>', imports)(), '');
  });
  it('should reverse the characters in a string.', function() {
   assert.equal(template('<%= reverse("abc") %>', imports)(), 'cba');
  });
 });
origin: jonschlinkert/template-helpers

describe('length', function() {
 it('should return an empty string when undefined.', function() {
  assert.equal(template('<%= length() %>', imports)(), '');
 });

 it('should return zero when the value is not an array.', function() {
  var fn = template('<%= length("foo") %>', imports);
  assert.equal(fn(context), '0');
 });

 it('should return the length of an array.', function() {
  var fn = template('<%= length(["b", "c", "a"]) %>', imports);
  assert.equal(fn(context), '3');
 });
});
origin: jonschlinkert/template-helpers

describe('titlecase', function() {
  it('should return an empty string when undefined.', function() {
   assert.equal(template('<%= titlecase("foo") %>', imports)(), 'Foo');
  });
  it('should upper case the characters in a string.', function() {
   var fn = template('<%= titlecase("one two three") %>', imports);
   assert.equal(fn(), 'One Two Three');
  });
 });
origin: jonschlinkert/template-helpers

describe('dirname', function() {
  it('should return the dirname:', function() {
   assert.strictEqual(template('<%= dirname("a/b/c/e.js") %>', imports)(), 'a/b/c');
   assert.strictEqual(template('<%= path.dirname("a/b/c/e.js") %>', imports)(), 'a/b/c');
  });
 });
origin: jonschlinkert/template-helpers

describe('after', function() {
 it('should return an empty string when undefined.', function() {
  assert.equal(template('<%= after() %>', imports)(), '');
 });

 it('should return all of the items in an array after the given index.', function() {
  var fn = template('<%= after(arr, 5) %>', imports);
  assert.deepEqual(fn(context), ['f', 'g', 'h'].toString());
 });
});
origin: jonschlinkert/template-helpers

describe('compact', function() {
 it('should return an empty string when undefined.', function() {
  assert.equal(template('<%= compact() %>', imports)(), '');
 });

 it('should remove falsey values from an array.', function() {
  var fn = template('<%= compact([null, "a", undefined, 0, false, "b", "c", ""]) %>', imports);
  assert.equal(fn(context), 'a,b,c');
 });
});
origin: jonschlinkert/template-helpers

describe('extname', function() {
  it('should return the extname with dot:', function() {
   assert.strictEqual(template('<%= extname("a/b/c/e.js") %>', imports)(), '.js');
   assert.strictEqual(template('<%= path.extname("a/b/c/e.js") %>', imports)(), '.js');
  });
 });
origin: jonschlinkert/template-helpers

describe('ext', function() {
  it('should return the extension without dot:', function() {
   assert.strictEqual(template('<%= ext("a/b/c/e.js") %>', imports)(), 'js');
   assert.strictEqual(template('<%= path.ext("a/b/c/e.js") %>', imports)(), 'js');
  });
 });
origin: jonschlinkert/template-helpers

describe('trim', function() {
  it('should return an empty string when undefined.', function() {
   assert.equal(template('<%= trim() %>', imports)(), '');
  });
  it('should strip leading whitespace from a string.', function() {
   var fn = template('<%= trim("    abc") %>', imports);
   assert.equal(fn(), 'abc');
  });
  it('should strip trailing whitespace from a string.', function() {
   var fn = template('<%= trim("abc   ") %>', imports);
   assert.equal(fn(), 'abc');
  });
 });
origin: jonschlinkert/template-helpers

describe('unique', function() {
 it('should return an empty string when undefined.', function() {
  assert.equal(template('<%= unique() %>', imports)(), '');
 });
 it('should unique items from multiple arrays:', function() {
  var fn = template('<%= unique(["a", "b", "c", "c"]) %>', imports);
  assert.equal(fn(context), 'a,b,c');
 });
});
lodash(npm)template

Most used lodash functions

  • LoDashStatic.map
    Creates an array of values by running each element in collection through iteratee. The iteratee is
  • LoDashStatic.isEmpty
    Checks if value is empty. A value is considered empty unless it’s an arguments object, array, string
  • LoDashStatic.forEach
    Iterates over elements of collection invoking iteratee for each element. The iteratee is invoked wit
  • LoDashStatic.find
    Iterates over elements of collection, returning the first element predicate returns truthy for.
  • LoDashStatic.pick
    Creates an object composed of the picked `object` properties.
  • LoDashStatic.get,
  • LoDashStatic.isArray,
  • LoDashStatic.filter,
  • LoDashStatic.merge,
  • LoDashStatic.isString,
  • LoDashStatic.isFunction,
  • LoDashStatic.assign,
  • LoDashStatic.extend,
  • LoDashStatic.includes,
  • LoDashStatic.keys,
  • LoDashStatic.cloneDeep,
  • LoDashStatic.uniq,
  • LoDashStatic.isObject,
  • LoDashStatic.omit

Popular in JavaScript

  • through2
    A tiny wrapper around Node.js streams.Transform (Streams2/3) to avoid explicit subclassing noise
  • aws-sdk
    AWS SDK for JavaScript
  • ms
    Tiny millisecond conversion utility
  • qs
    A querystring parser that supports nesting and arrays, with a depth limit
  • axios
    Promise based HTTP client for the browser and node.js
  • minimist
    parse argument options
  • debug
    small debugging utility
  • ws
    Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js
  • mongodb
    The official MongoDB driver for Node.js
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJavascript Code Index
Get Tabnine for your IDE now