@gooddata/js-utils
Advanced tools
Comparing version 0.5.0 to 0.5.1-pbenes-pb-tc-utils-2017-05-02T08-15-31-492Z
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
exports.env = exports.date = exports.string = undefined; | ||
@@ -24,2 +22,2 @@ | ||
exports.date = dateUtils; | ||
exports.env = envUtils; | ||
exports.env = envUtils; |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
exports.getDateTimeConfig = getDateTimeConfig; | ||
@@ -48,2 +46,2 @@ | ||
}; | ||
} | ||
} |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
exports.isProductionHostname = isProductionHostname; | ||
@@ -14,2 +12,2 @@ /** | ||
return !(hostname === 'localhost' || /getgooddata\.com$/.test(hostname) || /intgdc\.com$/.test(hostname)); | ||
} | ||
} |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
@@ -19,2 +17,3 @@ var _isNumber2 = require('lodash/isNumber'); | ||
exports.simplifyText = simplifyText; | ||
exports.parseStringToArray = parseStringToArray; | ||
@@ -68,5 +67,27 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function simplifyText(str) { | ||
var isValid = (0, _isString3.default)(str) || (0, _isNumber3.default)(str); | ||
var isValid = ()(str) || ()(str); | ||
var s = isValid ? str.toString() : ''; | ||
return s.replace(/[^a-zA-Z0-9]/g, '_').toLowerCase(); | ||
} | ||
} | ||
/** | ||
* Parse string in a form of [foo, bar] to an array of objects. | ||
* Assume alphanumeric strings in the array; if some is not alphanumeric , return null | ||
* @param {String} str input string with the array definition | ||
* @returns {Array} parsed array of strings | ||
*/ | ||
function parseStringToArray(str) { | ||
if (str) { | ||
if (str.match(/^\[]$/)) { | ||
// empty array of tags [] | ||
return []; | ||
} | ||
if (str.match(/^\[[a-zA-Z0-9]+(,[a-zA-Z0-9]+)*]$/)) { | ||
// [foo], [foo,bar] | ||
return str.slice(1, -1).split(','); | ||
} | ||
} | ||
return null; | ||
} |
{ | ||
"name": "@gooddata/js-utils", | ||
"version": "0.5.0", | ||
"version": "0.5.1-pbenes-pb-tc-utils-2017-05-02T08-15-31-492Z", | ||
"description": "Various utils shared on GoodData frontend", | ||
@@ -21,3 +21,3 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"build": "rm -rf lib && babel src --out-dir lib --ignore test", | ||
"build": "grunt build", | ||
"prepublish": "yarn run build" | ||
@@ -30,2 +30,4 @@ }, | ||
"babel-plugin-lodash": "3.2.11", | ||
"babel-preset-env": "1.4.0", | ||
"babel-plugin-transform-runtime": "6.22.0", | ||
"babel-preset-es2015": "6.22.0", | ||
@@ -37,3 +39,5 @@ "babel-preset-stage-2": "6.22.0", | ||
"grunt": "1.0.1", | ||
"grunt-babel": "6.0.0", | ||
"grunt-cli": "1.2.0", | ||
"grunt-contrib-clean": "1.0.0", | ||
"grunt-karma": "2.0.0", | ||
@@ -40,0 +44,0 @@ "grunt-webpack": "1.0.14", |
@@ -52,1 +52,23 @@ import { isString, isNumber } from 'lodash'; | ||
} | ||
/** | ||
* Parse string in a form of [foo, bar] to an array of objects. | ||
* Assume alphanumeric strings in the array; if some is not alphanumeric , return null | ||
* @param {String} str input string with the array definition | ||
* @returns {Array} parsed array of strings | ||
*/ | ||
export function parseStringToArray(str) { | ||
if (str) { | ||
if (str.match(/^\[]$/)) { | ||
// empty array of tags [] | ||
return []; | ||
} | ||
if (str.match(/^\[[a-zA-Z0-9]+(,[a-zA-Z0-9]+)*]$/)) { | ||
// [foo], [foo,bar] | ||
return str.slice(1, -1).split(','); | ||
} | ||
} | ||
return null; | ||
} |
import { | ||
randomString, | ||
shortenText, | ||
simplifyText | ||
simplifyText, | ||
parseStringToArray | ||
} from '../string'; | ||
@@ -40,1 +41,24 @@ | ||
}); | ||
describe('parseStringToArray', () => { | ||
it('should parse string to array correctly', () => { | ||
const tagsConfigs = [ | ||
// valid are empty [] and a-zA-Z0-9 separated by comma [asdf], [asdf,qwer], [asdf,2] | ||
{ tag: '[]', result: [] }, | ||
{ tag: '[asdf]', result: ['asdf'] }, | ||
{ tag: '[asdf,qwer]', result: ['asdf', 'qwer'] }, | ||
{ tag: '[asdf,2]', result: ['asdf', '2'] }, | ||
// invalid | ||
{ tag: '[asdf', result: null }, | ||
{ tag: 'asdf]', result: null }, | ||
{ tag: '[asdf, qwer]', result: null }, | ||
{ tag: '[asdf#]', result: null }, | ||
{ tag: '[asdf?]', result: null }, | ||
{ tag: '[asdf&]', result: null } | ||
]; | ||
tagsConfigs.forEach((tagConfig) => { | ||
expect(parseStringToArray(tagConfig.tag)).to.eql(tagConfig.result); | ||
}); | ||
}); | ||
}); |
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
27950
17
609
0
37