New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

stringlike

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stringlike

A string like object to use in templates

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

StringLike

A string-like object to work more easily with strings in templates. Inherits everything from string.js, and sprinkles some other methods on top:

npm install stringlike
var StringLike = require('stringlike');
var a = new StringLike('a string')
//or
var b = StringLike('a string') //you can skip the 'new'

Methods

lineBreaksToHTML()

converts single line returns to
s and more line returns to paragraphs

	var text = 'This is an example text, and here is a line break \n'
		+ 'that should convert to a BR. Now, if I use two line breaks \n\n\n'
		+ 'this text should be wrapped in P\'s\n\n';
	var converted_text = '<p>This is an example text, and here is a line break <br>'
		+ 'that should convert to a BR. Now, if I use two line breaks </p><p>'
		+ 'this text should be wrapped in P\'s</p>';
	var str = new StringLike(text)
	console.log(str.linebreaksToHTML().s == converted_text);

safe([prefix])

converts strings to class names that are safe to use in html elements if "prefix" is passed, it will be pre-pended to the string

Functions

StringLike.convert(object,[limit],[recurse])

converts all strings inside an object to instances of StringLike. Useful to convert a full "locals" object that you want to pass to your templates The function does not handle cyclic references unless you pass an array to 'recurse'

  • "limit" defaults to 10 nested objects, set it to -1 for infinite.
  • "recurse" if an array is passed (or true), the function will handle recursion
	var obj = {
		someProp:{
		someInsideProp:'a string'
		}
	,	someOtherProp:'a'
	}
	StringLike.convert(obj);
	console.log(
		(obj.someProp.someInsideProp.s === 'a string')
		&& (obj.someOtherProp.repeat(3).s === 'aaa')
	)

Keywords

string

FAQs

Package last updated on 08 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts