Comparing version 0.6.0 to 0.6.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const numbers_1 = require("./numbers"); | ||
const common_1 = require("./utility/common"); | ||
function rgbToHex(r, g, b) { | ||
@@ -12,3 +13,3 @@ return '#' + numbers_1.numbers.convertToHex(r) + numbers_1.numbers.convertToHex(g) + numbers_1.numbers.convertToHex(b); | ||
const colorCleaned = color.charAt(0) === '#' ? color.slice(1) : color; | ||
return !!colorCleaned.match(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/); | ||
return common_1.common.isValid(colorCleaned, /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/); | ||
} | ||
@@ -15,0 +16,0 @@ function hexToRgb(hex) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const common_1 = require("./utility/common"); | ||
const getEmail = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/gi; | ||
@@ -9,3 +10,3 @@ function retrieve(str) { | ||
function isValid(str) { | ||
return getEmail.test(str); | ||
return common_1.common.isValid(str, getEmail); | ||
} | ||
@@ -16,3 +17,3 @@ function remove(str) { | ||
function swap(str, newEmail) { | ||
return str.replace(getEmail, newEmail); | ||
return common_1.common.swap(str, newEmail, getEmail); | ||
} | ||
@@ -19,0 +20,0 @@ const email = { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const common_1 = require("./utility/common"); | ||
const ipAddrOnly = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/m; | ||
const ipAddrContains = /(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/gm; | ||
function isValid(addr) { | ||
if (typeof addr !== 'string') { | ||
return false; | ||
} | ||
return ipAddrOnly.test(addr); | ||
return common_1.common.isValid(addr, ipAddrOnly); | ||
} | ||
@@ -30,6 +28,3 @@ function retrieve(str) { | ||
function swap(str, newStr) { | ||
if (!str || typeof str !== 'string') { | ||
return ''; | ||
} | ||
return str.replace(ipAddrContains, newStr); | ||
return common_1.common.swap(str, newStr, ipAddrContains); | ||
} | ||
@@ -36,0 +31,0 @@ const ip = { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const common_1 = require("./utility/common"); | ||
function containsNum(num) { | ||
@@ -8,3 +9,3 @@ if (typeof num === 'number') { | ||
if (typeof num === 'string') { | ||
return !!num.match(/-?\d/g); | ||
return common_1.common.isValid(num, /-?\d/g); | ||
} | ||
@@ -17,3 +18,3 @@ return false; | ||
} | ||
return !!num.toString().match(/^-?\d+$/g); | ||
return common_1.common.isValid(num.toString(), /^-?\d+$/g); | ||
} | ||
@@ -24,7 +25,7 @@ function decimal(num) { | ||
} | ||
return !!num.toString().match(/^-?\d*\.\d+$/g); | ||
return common_1.common.isValid(num.toString(), /^-?\d*\.\d+$/g); | ||
} | ||
function containsDecimal(num) { | ||
if (typeof num === 'string') { | ||
return !!num.match(/-?\d*\.\d+/g); | ||
return common_1.common.isValid(num.toString(), /-?\d*\.\d+/g); | ||
} | ||
@@ -40,3 +41,3 @@ if (typeof num === 'number') { | ||
} | ||
return !!num.toString().match(/^-?\d*\/\d+$/g); | ||
return common_1.common.isValid(num.toString(), /^-?\d*\/\d+$/g); | ||
} | ||
@@ -47,3 +48,3 @@ function containsFraction(num) { | ||
} | ||
return !!num.match(/-?\d*\/\d+/g); | ||
return common_1.common.isValid(num, /-?\d*\/\d+/g); | ||
} | ||
@@ -63,3 +64,3 @@ function convertToHex(num) { | ||
const test = typeof str === 'number' ? str.toString() : str; | ||
return !!test.match(/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im); | ||
return common_1.common.isValid(test, /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im); | ||
} | ||
@@ -66,0 +67,0 @@ const numbers = { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const common_1 = require("./utility/common"); | ||
function buildRegex(options) { | ||
@@ -8,3 +9,3 @@ return new RegExp(`^[${options.lc ? 'a-z' : ''}${options.capital ? 'A-Z' : ''}${options.num ? '0-9' : ''}${options.special || ''}]{${options.min},${options.max}}$`); | ||
const re = buildRegex(options); | ||
return re.test(str); | ||
return common_1.common.isValid(str, re); | ||
} | ||
@@ -11,0 +12,0 @@ function isValidAdvanced(str, options, advOptions) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const common_1 = require("./utility/common"); | ||
const semverStr = /(?<=^v?|\sv?)(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*)(?:\.(?:[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*))*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?(?=$|\s)/gi; | ||
@@ -8,3 +9,3 @@ function retrieve(str) { | ||
function isValid(str) { | ||
return semverStr.test(str); | ||
return common_1.common.isValid(str, semverStr); | ||
} | ||
@@ -11,0 +12,0 @@ function remove(str) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const common_1 = require("./utility/common"); | ||
const urlStr = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gm; | ||
@@ -9,3 +10,3 @@ const domainExp = /^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)/im; | ||
function isValid(str) { | ||
return urlStr.test(str); | ||
return common_1.common.isValid(str, urlStr); | ||
} | ||
@@ -12,0 +13,0 @@ function remove(str) { |
{ | ||
"name": "stringman", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "Stringman does a lot of string manipulation and regex operations for you.", | ||
@@ -21,3 +21,3 @@ "main": "lib/index.js", | ||
"lint": "tslint -p tsconfig.json", | ||
"docs": "rimraf ./docs && typedoc --exclude src/index.ts --name Stringman --out docs/ src/ && touch ./docs/.nojekyll" | ||
"docs": "rimraf ./docs && typedoc --exclude \"**/**/*+(index|test|spec|common).ts\" --name Stringman --out docs/ src/ && touch ./docs/.nojekyll" | ||
}, | ||
@@ -24,0 +24,0 @@ "keywords": [ |
22675
26
490