@gooddata/js-utils
Advanced tools
Comparing version 0.4.1 to 0.4.2
{ | ||
"name": "@gooddata/js-utils", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Various utils shared on GoodData frontend", | ||
"main": "dist/index.js", | ||
"main": "lib/index.js", | ||
"files": [ | ||
"dist", | ||
"README.md", | ||
"lib", | ||
"src" | ||
@@ -20,3 +21,3 @@ ], | ||
"scripts": { | ||
"build": "rimraf dist && babel src --out-dir dist", | ||
"build": "rimraf lib && babel src --out-dir lib --ignore test", | ||
"prepublish": "npm run build" | ||
@@ -27,8 +28,7 @@ }, | ||
"babel-core": "6.14.0", | ||
"babel-eslint": "6.1.2", | ||
"babel-loader": "6.2.10", | ||
"babel-plugin-lodash": "3.2.11", | ||
"babel-preset-es2015": "6.18.0", | ||
"babel-preset-stage-2": "6.18.0", | ||
"ember": "gooddata/emberjs#1.8.1", | ||
"eslint": "1.7.3", | ||
"eslint-config-gooddata": "0.0.8", | ||
"expect.js": "0.3.1", | ||
@@ -35,0 +35,0 @@ "exports-loader": "0.6.3", |
@@ -1,3 +0,1 @@ | ||
import * as promiseUtils from './utils/promise'; | ||
import * as emberUtils from './utils/ember'; | ||
import * as stringUtils from './utils/string'; | ||
@@ -8,13 +6,7 @@ import * as envUtils from './utils/env'; | ||
var computed = { cssClass: emberUtils.cssClass }; | ||
delete emberUtils.cssClass; | ||
export { | ||
promiseUtils as promise, | ||
emberUtils as ember, | ||
stringUtils as string, | ||
translationUtils as translation, | ||
dateUtils as date, | ||
envUtils as env, | ||
computed | ||
envUtils as env | ||
}; |
import { isString, isNumber } from 'lodash'; | ||
/** | ||
* Escapes html characters in a string. | ||
* @param {String} str string to be escaped | ||
* @returns {String} escaped string | ||
*/ | ||
export function htmlEscape(str) { | ||
return Em.Handlebars.Utils.escapeExpression(str); | ||
} | ||
/** | ||
* @param {String} value string to be shortened | ||
@@ -18,7 +9,7 @@ * @param {Object} options currently only allows you to specify maxLength | ||
export function shortenText(value, options) { | ||
options = options || {}; | ||
var maxLength = options.maxLength; | ||
options = options || {}; // eslint-disable-line no-param-reassign | ||
const maxLength = options.maxLength; | ||
if (value && maxLength && value.length > maxLength) { | ||
value = value.substr(0, maxLength) + '...'; | ||
value = `${value.substr(0, maxLength)}…`; // eslint-disable-line no-param-reassign | ||
} | ||
@@ -34,4 +25,4 @@ | ||
*/ | ||
export function escapeRegExp(string){ | ||
return string.replace(/([.*+?^${}()|\[\]\/\\])/g, '\\$1'); | ||
export function escapeRegExp(string) { | ||
return string.replace(/([.*+?^${}()|\[\]\/\\])/g, '\\$1'); // eslint-disable-line | ||
} | ||
@@ -45,5 +36,5 @@ | ||
export function randomString(len) { | ||
var text = ''; | ||
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
for( var i = 0; i < len; i++) { | ||
let text = ''; | ||
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
for (let i = 0; i < len; i += 1) { | ||
text += possible.charAt(Math.floor(Math.random() * possible.length)); | ||
@@ -60,5 +51,5 @@ } | ||
export function simplifyText(str) { | ||
var isValid = isString(str) || isNumber(str); | ||
var s = isValid ? str.toString() : ''; | ||
const isValid = isString(str) || isNumber(str); | ||
const s = isValid ? str.toString() : ''; | ||
return s.replace(/[^a-zA-Z0-9]/g, '_').toLowerCase(); | ||
} |
import { | ||
htmlEscape, | ||
randomString, | ||
escapeRegExp, | ||
shortenText, | ||
@@ -9,15 +7,4 @@ simplifyText | ||
describe('#htmlEscape', function() { | ||
it('should correctly escape strings with html', function() { | ||
expect(htmlEscape('<button></button>')).to.eql('<button></button>'); | ||
}); | ||
it('should keep non-html strings intact', function() { | ||
var str = 'This is a simple string'; | ||
expect(htmlEscape(str)).to.eql(str); | ||
}); | ||
}); | ||
describe('#randomString', function() { | ||
it('should generate alphanumeric string with correct length', function() { | ||
describe('#randomString', () => { | ||
it('should generate alphanumeric string with correct length', () => { | ||
expect(randomString(10)).to.match(/^[0-9a-zA-Z]{10}$/); | ||
@@ -27,29 +14,15 @@ }); | ||
describe('#escapeRegExp', function() { | ||
it('should escape special characters', function() { | ||
expect(escapeRegExp('()')).to.eql('\\(\\)'); | ||
expect(escapeRegExp('{}')).to.eql('\\{\\}'); | ||
expect(escapeRegExp('[]')).to.eql('\\[\\]'); | ||
expect(escapeRegExp('^')).to.eql('\\^'); | ||
expect(escapeRegExp('+')).to.eql('\\+'); | ||
expect(escapeRegExp('*')).to.eql('\\*'); | ||
expect(escapeRegExp('.')).to.eql('\\.'); | ||
expect(escapeRegExp('?')).to.eql('\\?'); | ||
expect(escapeRegExp('$')).to.eql('\\$'); | ||
describe('#shortenText', () => { | ||
it('should shorten text to maximum length and add ellipsis', () => { | ||
const shortened = shortenText('Lorem ipsum dolor sit amet', { maxLength: 11 }); | ||
expect(shortened).to.eql('Lorem ipsum…'); | ||
}); | ||
}); | ||
describe('#shortenText', function() { | ||
it('should shorten text to maximum length and add ellipsis', function() { | ||
var shortened = shortenText('Lorem ipsum dolor sit amet', { maxLength: 11 }); | ||
expect(shortened).to.eql('Lorem ipsum...'); | ||
}); | ||
it('should NOT shorten text when maxLength is not passed', function() { | ||
var shortened = shortenText('Lorem ipsum dolor sit amet'); | ||
it('should NOT shorten text when maxLength is not passed', () => { | ||
const shortened = shortenText('Lorem ipsum dolor sit amet'); | ||
expect(shortened).to.eql('Lorem ipsum dolor sit amet'); | ||
}); | ||
it('should NOT shorten text when text is shorter than maxLength', function() { | ||
var shortened = shortenText('Lorem ipsum dolor sit amet', { maxLength: 100 }); | ||
it('should NOT shorten text when text is shorter than maxLength', () => { | ||
const shortened = shortenText('Lorem ipsum dolor sit amet', { maxLength: 100 }); | ||
expect(shortened).to.eql('Lorem ipsum dolor sit amet'); | ||
@@ -59,4 +32,4 @@ }); | ||
describe('#simplifyText', function() { | ||
it('should simplify text', function() { | ||
describe('#simplifyText', () => { | ||
it('should simplify text', () => { | ||
expect(simplifyText('')).to.be(''); | ||
@@ -63,0 +36,0 @@ expect(simplifyText(123)).to.be('123'); |
@@ -22,3 +22,3 @@ import { fromJS } from 'immutable'; | ||
'buttons.load': 'load', | ||
'saving': 'saving' | ||
saving: 'saving' | ||
}; | ||
@@ -25,0 +25,0 @@ |
@@ -7,3 +7,3 @@ export const flattenMessages = (nestedMessages, prefix = '') => { | ||
if (typeof value === 'string') { | ||
messages[prefixedKey] = value; | ||
messages[prefixedKey] = value; // eslint-disable-line no-param-reassign | ||
} else { | ||
@@ -10,0 +10,0 @@ Object.assign(messages, flattenMessages(value, prefixedKey)); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
35
21560
16
464
2