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

@ultraq/string-utils

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ultraq/string-utils - npm Package Compare versions

Comparing version
1.1.0
to
1.2.0
+11
jest.config.js
/* eslint-env node */
'use strict'; // eslint-disable-line
module.exports = {
collectCoverage: true,
coverageReporters: [
'html',
'lcov',
'text-summary'
]
};
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.escapeHtml = escapeHtml;
exports.format = format;
/*
* Copyright 2017, Emanuel Rabina (http://www.ultraq.net.nz/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Escapes special HTML characters in a string with their entity code
* equivalents.
*
* @param {String} string
* @return {String}
* HTML escaped string, safe for use in HTML.
*/
function escapeHtml(string) {
return typeof string !== 'string' ? string : string.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;');
}
/**
* Returns the replacement of each placeholder in a template string with a
* corresponding replacement value.
*
* @param {String} template
* @param {...String} values
* Argument list of values or a single array of values.
* @return {String}
* Replaced template string.
*/
function format(template) {
for (var _len = arguments.length, values = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
values[_key - 1] = arguments[_key];
}
return template.replace(/\{(\d+)\}/g, function (match, index) {
return values[+index] + '';
});
}
//# sourceMappingURL=string-utils.cjs.js.map
{"version":3,"sources":["string-utils.js"],"names":[],"mappings":";;;;;QAwBgB,U,GAAA,U;QAoBA,M,GAAA,M;AA5ChB;;;;;;;;;;;;;;;;AAgBA;;;;;;;;AAQO,SAAS,UAAT,CAAoB,MAApB,EAA4B;;AAElC,SAAO,OAAO,MAAP,KAAkB,QAAlB,GAA6B,MAA7B,GAAsC,OAC3C,OAD2C,CACnC,IADmC,EAC7B,OAD6B,EAE3C,OAF2C,CAEnC,IAFmC,EAE7B,MAF6B,EAG3C,OAH2C,CAGnC,IAHmC,EAG7B,MAH6B,EAI3C,OAJ2C,CAInC,IAJmC,EAI7B,QAJ6B,EAK3C,OAL2C,CAKnC,IALmC,EAK7B,QAL6B,CAA7C;AAMA;;AAED;;;;;;;;;;AAUO,SAAS,MAAT,CAAgB,QAAhB,EAAqC;AAAA,oCAAR,MAAQ;AAAR,UAAQ;AAAA;;AAE3C,SAAO,SAAS,OAAT,CAAiB,YAAjB,EAA+B,UAAC,KAAD,EAAQ,KAAR;AAAA,WAAkB,OAAO,CAAC,KAAR,IAAiB,EAAnC;AAAA,GAA/B,CAAP;AACA","file":"string-utils.cjs.js","sourcesContent":["/* \n * Copyright 2017, Emanuel Rabina (http://www.ultraq.net.nz/)\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Escapes special HTML characters in a string with their entity code\n * equivalents.\n * \n * @param {String} string\n * @return {String}\n * HTML escaped string, safe for use in HTML.\n */\nexport function escapeHtml(string) {\n\n\treturn typeof string !== 'string' ? string : string\n\t\t.replace(/&/g, '&amp;')\n\t\t.replace(/</g, '&lt;')\n\t\t.replace(/>/g, '&gt;')\n\t\t.replace(/\"/g, '&quot;')\n\t\t.replace(/'/g, '&#039;');\n}\n\n/**\n * Returns the replacement of each placeholder in a template string with a\n * corresponding replacement value.\n * \n * @param {String} template\n * @param {...String} values\n * Argument list of values or a single array of values.\n * @return {String}\n * Replaced template string.\n */\nexport function format(template, ...values) {\n\n\treturn template.replace(/\\{(\\d+)\\}/g, (match, index) => values[+index] + '');\n}\n"]}
/*
* Copyright 2017, Emanuel Rabina (http://www.ultraq.net.nz/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Escapes special HTML characters in a string with their entity code
* equivalents.
*
* @param {String} string
* @return {String}
* HTML escaped string, safe for use in HTML.
*/
export function escapeHtml(string) {
return typeof string !== 'string' ? string : string.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;');
}
/**
* Returns the replacement of each placeholder in a template string with a
* corresponding replacement value.
*
* @param {String} template
* @param {...String} values
* Argument list of values or a single array of values.
* @return {String}
* Replaced template string.
*/
export function format(template) {
for (var _len = arguments.length, values = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
values[_key - 1] = arguments[_key];
}
return template.replace(/\{(\d+)\}/g, function (match, index) {
return values[+index] + '';
});
}
//# sourceMappingURL=string-utils.es.js.map
{"version":3,"sources":["string-utils.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;AAgBA;;;;;;;;AAQA,OAAO,SAAS,UAAT,CAAoB,MAApB,EAA4B;;AAElC,SAAO,OAAO,MAAP,KAAkB,QAAlB,GAA6B,MAA7B,GAAsC,OAC3C,OAD2C,CACnC,IADmC,EAC7B,OAD6B,EAE3C,OAF2C,CAEnC,IAFmC,EAE7B,MAF6B,EAG3C,OAH2C,CAGnC,IAHmC,EAG7B,MAH6B,EAI3C,OAJ2C,CAInC,IAJmC,EAI7B,QAJ6B,EAK3C,OAL2C,CAKnC,IALmC,EAK7B,QAL6B,CAA7C;AAMA;;AAED;;;;;;;;;;AAUA,OAAO,SAAS,MAAT,CAAgB,QAAhB,EAAqC;AAAA,oCAAR,MAAQ;AAAR,UAAQ;AAAA;;AAE3C,SAAO,SAAS,OAAT,CAAiB,YAAjB,EAA+B,UAAC,KAAD,EAAQ,KAAR;AAAA,WAAkB,OAAO,CAAC,KAAR,IAAiB,EAAnC;AAAA,GAA/B,CAAP;AACA","file":"string-utils.es.js","sourcesContent":["/* \n * Copyright 2017, Emanuel Rabina (http://www.ultraq.net.nz/)\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Escapes special HTML characters in a string with their entity code\n * equivalents.\n * \n * @param {String} string\n * @return {String}\n * HTML escaped string, safe for use in HTML.\n */\nexport function escapeHtml(string) {\n\n\treturn typeof string !== 'string' ? string : string\n\t\t.replace(/&/g, '&amp;')\n\t\t.replace(/</g, '&lt;')\n\t\t.replace(/>/g, '&gt;')\n\t\t.replace(/\"/g, '&quot;')\n\t\t.replace(/'/g, '&#039;');\n}\n\n/**\n * Returns the replacement of each placeholder in a template string with a\n * corresponding replacement value.\n * \n * @param {String} template\n * @param {...String} values\n * Argument list of values or a single array of values.\n * @return {String}\n * Replaced template string.\n */\nexport function format(template, ...values) {\n\n\treturn template.replace(/\\{(\\d+)\\}/g, (match, index) => values[+index] + '');\n}\n"]}
/*
* Copyright 2017, Emanuel Rabina (http://www.ultraq.net.nz/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-env jest */
import {escapeHtml, format} from './string-utils';
/**
* Tests for the string utilities.
*/
describe('StringUtils', function() {
describe('#escapeHtml', function() {
test('Escape special characters', function() {
let string = `This & that < thing > sing "ring" 'king'`;
let result = escapeHtml(string);
expect(result).toBe(`This &amp; that &lt; thing &gt; sing &quot;ring&quot; &#039;king&#039;`);
});
test('Return the value back to the user if the type is not a string', function() {
[null, undefined, 123, Date.now, []].forEach(value => {
let result = escapeHtml(value);
expect(value).toBe(result);
});
});
});
describe('#format', function() {
let template = "There's a {0} in my {1}, dear {2}";
test('Should replace each token with the corresponding value', function() {
let result = format(template, 'hole', 'bucket', 'Liza');
expect(result).toBe("There's a hole in my bucket, dear Liza");
});
test('Non-string values should be coerced to strings before formatting', function() {
let result = format(template, 0, 1, 2);
expect(result).toBe("There's a 0 in my 1, dear 2");
});
});
});
+15
-13
{
"name": "@ultraq/string-utils",
"version": "1.1.0",
"version": "1.2.0",
"description": "A collection of utilities for JavaScript strings",

@@ -18,19 +18,21 @@ "author": "Emanuel Rabina <emanuelrabina@gmail.com> (http://www.ultraq.net.nz/)",

],
"main": "string-utils.node.js",
"module": "string-utils.js",
"module": "string-utils.es.js",
"main": "string-utils.cjs.js",
"scripts": {
"build": "rollup --input string-utils.js --format cjs --output string-utils.node.js",
"lint": "eslint string-utils.js test",
"test": "npm run lint && mocha --require babel-register",
"lint": "eslint '*.js'",
"test": "npm run lint && jest",
"coverage": "cat ./coverage/lcov.info | coveralls",
"build": "npm run build:cjs && npm run build:es",
"build:cjs": "BABEL_ENV=cjs babel string-utils.js --out-file string-utils.cjs.js --source-maps",
"build:es": "BABEL_ENV=es babel string-utils.js --out-file string-utils.es.js --source-maps",
"prepublish": "npm run build"
},
"devDependencies": {
"babel-plugin-transform-es2015-modules-umd": "^6.24.1",
"babel-register": "^6.24.1",
"chai": "^3.5.0",
"eslint": "^3.19.0",
"eslint-config-ultraq": "^1.0.1",
"mocha": "^3.2.0",
"rollup": "^0.41.6"
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"coveralls": "^2.13.1",
"eslint": "^4.8.0",
"eslint-config-ultraq": "^2.0.0",
"jest": "^21.2.1"
}
}

@@ -6,2 +6,3 @@

[![Build Status](https://travis-ci.org/ultraq/string-utils.svg?branch=master)](https://travis-ci.org/ultraq/string-utils)
[![Coverage Status](https://coveralls.io/repos/github/ultraq/string-utils/badge.svg?branch=master)](https://coveralls.io/github/ultraq/string-utils?branch=master)
[![npm](https://img.shields.io/npm/v/@ultraq/string-utils.svg?maxAge=3600)](https://www.npmjs.com/package/@ultraq/string-utils)

@@ -8,0 +9,0 @@ [![License](https://img.shields.io/github/license/ultraq/string-utils.svg?maxAge=2592000)](https://github.com/ultraq/string-utils/blob/master/LICENSE.txt)

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/*
* Copyright 2017, Emanuel Rabina (http://www.ultraq.net.nz/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Escapes special HTML characters in a string with their entity code
* equivalents.
*
* @param {String} string
* @return {String}
* HTML escaped string, safe for use in HTML.
*/
function escapeHtml(string) {
return typeof string !== 'string' ? string : string
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}
/**
* Returns the replacement of each placeholder in a template string with a
* corresponding replacement value.
*
* @param {String} template
* @param {...String} values
* Argument list of values or a single array of values.
* @return {String}
* Replaced template string.
*/
function format(template, ...values) {
return template.replace(/\{(\d+)\}/g, (match, index) => values[+index] + '');
}
exports.escapeHtml = escapeHtml;
exports.format = format;