@iamkenos/iris
Version:
Test API endpoints with Axios & Jest using a collection of custom matchers and built-in utility functions.
60 lines • 2.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.changecase = exports.parseJSON = exports.isJSON = exports.isURL = void 0;
const change_case_1 = require("change-case");
function isURL(str) {
try {
const url = new URL(str);
return url.href.replace(/([^:]\/)\/+/g, "$1");
}
catch (e) {
return false;
}
}
exports.isURL = isURL;
function isJSON(str) {
if (typeof str !== "string")
return false;
try {
const result = JSON.parse(str);
return result instanceof Array || result instanceof Object;
}
catch (e) {
return false;
}
}
exports.isJSON = isJSON;
function parseJSON(object) {
try {
return JSON.parse(object);
}
catch (e) {
return object;
}
}
exports.parseJSON = parseJSON;
exports.changecase = {
/** Convert a string to camel case (`fooBar`). */
camelCase: change_case_1.camelCase,
/** Convert a string to capital case (`Foo Bar`). */
capitalCase: change_case_1.capitalCase,
/** Convert a string to constant case (`FOO_BAR`). */
constantCase: change_case_1.constantCase,
/** Convert a string to dot case (`foo.bar`). */
dotCase: change_case_1.dotCase,
/** Convert a string to kebab case (`foo-bar`). */
kebabCase: (input) => (0, change_case_1.noCase)(input).replace(new RegExp(/ /, "g"), "-"),
/** Convert a string to space separated lower case (`foo bar`). */
noCase: change_case_1.noCase,
/** Convert a string to pascal case (`FooBar`). */
pascalCase: change_case_1.pascalCase,
/** Convert a string to path case (`foo/bar`). */
pathCase: change_case_1.pathCase,
/** Convert a string to path case (`Foo bar`). */
sentenceCase: change_case_1.sentenceCase,
/** Convert a string to snake case (`foo_bar`). */
snakeCase: change_case_1.snakeCase,
/** Split any cased input strings into an array of words. */
split: (input) => (0, change_case_1.noCase)(input).split(" ")
};
//# sourceMappingURL=string.js.map