Security News
Internet Archive Hacked, 31 Million Record Compromised
The Internet Archive's "Wayback Machine" has been hacked and defaced, with 31 millions records compromised.
regex-safe
Advanced tools
Easy controls with Regex.
import { isEqual } from "regex-safe";
isEqual({ foo: "bar" }, { foo: "bar" }); // true
isEqual({ foo: "bar" }, { bar: "foo" }); // false
import { mul } from "regex-safe";
mul(1, 2, 3, 4); // 24
import { digitize } from "regex-safe";
digitize(123); // [1, 2, 3]
import { decToBi } from "regex-safe";
decToBi(10); //1010
import { toChars } from "regex-safe";
toChars(0); // A
toChars(1); // B
toChars(25); // Z
import { gcd } from "regex-safe";
const gcd = (a, b) => (b === 0 ? a : gcd(b, a % b));
import { clamp } from "regex-safe";
clamp(199, 10, 25); // 25
import { remainder } from "regex-safe";
remainder(1, 2, 3, 4); // 1
import { mod } from "regex-safe";
mod(-1, 5); // 4
mod(3, 5); // 3
mod(6, 5); // 1
import { factorial } from "regex-safe";
factorial(2); // 2
factorial(3); // 6
factorial(4); // 24
factorial(5); // 120
factorial(6); // 720
import { division } from "regex-safe";
division(1, 2, 3, 4); // 0.04166666666666666
import { average } from "regex-safe";
average(1, 2, 3, 4); // 2.5
import { xor } from "regex-safe";
xor(true, true); // false
xor(false, false); // false
xor(true, false); // true
xor(false, true); // true
import { curry } from "regex-safe";
const sum = (a, b, c) => a + b + c;
curry(sum)(1)(2)(3); // 6
curry(sum)(1, 2, 3); // 6
curry(sum, 1)(2, 3); // 6
curry(sum, 1)(2)(3); // 6
curry(sum, 1, 2)(3); // 6
curry(sum, 1, 2, 3); // 6
import { unary } from "regex-safe";
["1", "2", "3", "4", "5"].map(unary(parseInt)); // [1, 2, 3, 4, 5]
import { getPosition } from "regex-safe";
getPosition(document.body); // { left: 0, top: 0 }
import { sortDescending } from "regex-safe";
sortDescending([new Date("2019-01-03"), new Date("2019-01-01")]); // [new Date("2019-01-03"), new Date("2019-01-01")]
import { yesterday } from "regex-safe";
yesterday(); // 2022-07-10T14:32:24.326Z
import { getWeekday } from "regex-safe";
getWeekday(new Date()); // sunday
import { numberOfDays } from "regex-safe";
numberOfDays(2022); // 365
import { tomorrow } from "regex-safe";
tomorrow(); // 2022-07-10T17:34:28.400Z
import { getTimezone } from "regex-safe";
getTimezone(); // Europe/Istanbul
import { daysInMonth } from "regex-safe";
daysInMonth(2020, 1); // 30
import { getMonthName } from "regex-safe";
getMonthName(new Date()); // July
import { getLastDate } from "regex-safe";
getLastDate(new Date("2020-01-01")); // 2020-01-30T21:00:00.000Z
import { getFirstDate } from "regex-safe";
getFirstDate(); // 2022-06-30T21:00:00.000Z
getFirstDate(new Date("2020-01-01")); // 2020-01-01T00:00:00.
import { dayOfYear } from "regex-safe";
dayOfYear(new Date(2020, 04, 16)); // 137
import { formatLocaleDate } from "regex-safe";
formatLocaleDate(new Date(), "pt-BR"); // 06/05/2020
formatLocaleDate(new Date(), "tr-TR"); // 06.05.2020
import { formatSeconds } from "regex-safe";
formatSeconds(200); // 00:03:20
import { monthDiff } from "regex-safe";
monthDiff(new Date("2020-01-01"), new Date("2021-01-01")); // 12
import { diffDays } from "regex-safe";
diffDays(new Date("2014-12-19"), new Date("2020-01-01")); // 1839
import { suffixAmPm } from "regex-safe";
suffixAmPm(0); // '12am'
suffixAmPm(12); // '12pm'
import { swapItems } from "regex-safe";
swapItems([1, 2, 3, 4, 5], 1, 4); // [1, 5, 3, 4, 2]
import { transpose } from "regex-safe";
transpose([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
]); // [ [ 1, 4, 7 ], [ 2, 5, 8 ], [ 3, 6, 9 ] ]
import { chunk } from "regex-safe";
chunk([1, 2, 3, 4, 5, 6, 7, 8], 4); // [[1, 2, 3, 4], [5, 6, 7, 8]]
import { sort } from "regex-safe";
sort([1, 5, 2, 4, 3]); // [1, 2, 3, 4, 5]
import { shuffle } from "regex-safe";
shuffle([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // [9, 1, 10, 6, 8, 5, 2, 3, 7, 4]
import { repeat } from "regex-safe";
repeat([1, 2, 3], 3); // [1, 2, 3, 1, 2, 3, 1, 2, 3]```
import { removeFalsy } from "regex-safe";
removeFalsy([0, "mehmet", "", NaN, true, 5, undefined, "regex-safe", false]); // [ 'mehmet', true, 5, 'regex-safe' ]
import { groupBy } from "regex-safe";
groupBy(
[
{ branch: "audi", model: "q8", year: "2019" },
{ branch: "audi", model: "rs7", year: "2020" },
{ branch: "ford", model: "mustang", year: "2019" },
{ branch: "ford", model: "explorer", year: "2020" },
{ branch: "bmw", model: "x7", year: "2020" },
],
"branch"
); // { audi: [{ branch: "audi", model: "q8", year: "2019" }, { branch: "audi", model: "rs7", year: "2020" }], ford: [{ branch: "ford", model: "mustang", year: "2019" }, { branch: "ford", model: "explorer", year: "2020" }], bmw: [{ branch: "bmw", model: "x7", year: "2020" }] }
import { union } from "regex-safe";
union([1, 2], [2, 3], [3]); // [1, 2, 3]
import { unique } from "regex-safe";
unique([1, 2, 3, 1, 2, 3, 4, 5]); // [1, 2, 3, 4, 5]
import { sum } from "regex-safe";
sum([1, 2, 3, 4, 5]); // 15
import { getIntersection } from "regex-safe";
getIntersection([1, 2, 3], [2, 3, 4]); // [2, 3]
import { getNthItems } from "regex-safe";
getNthItems([1, 2, 3, 4, 5, 6, 7, 8, 9], 2); // [2, 4, 6, 8]
getNthItems([1, 2, 3, 4, 5, 6, 7, 8, 9], 3); // [3, 6, 9]
import { getConsecutiveArrays } from "regex-safe";
getConsecutiveArrays([1, 2, 3, 4, 5], 2); // [[1, 2], [2, 3], [3, 4], [4, 5]]
getConsecutiveArrays([1, 2, 3, 4, 5], 3); // [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
getConsecutiveArrays([1, 2, 3, 4, 5], 6); // []
import { flat } from "regex-safe";
flat(["regex-safe", ["regex", "safe"]]); // ["regex-safe", "regex", "safe"]
import { indexOfMax } from "regex-safe";
indexOfMax([6, 2, 5, 9, 7]); // 3
import { indexOfMin } from "regex-safe";
indexOfMin([6, 2, 5, 9, 7]); // 1
import { minByArray } from "regex-safe";
minByArray(
[
{
name: "John",
age: 20,
},
{
name: "Jane",
age: 30,
},
{
name: "Joe",
age: 10,
},
],
"age"
); // { name: "Joe", age: 10 },
import { maxByArray } from "regex-safe";
maxByArray(
[
{
name: "John",
age: 20,
},
{
name: "Jane",
age: 30,
},
{
name: "Joe",
age: 10,
},
],
"age"
); // { name: "Jane", age: 30 },
import { range } from "regex-safe";
range(1, 10); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
range(2, 5); // [2, 3, 4, 5]
import { countOccurrences } from "regex-safe";
countOccurrences(["Mehmet", "Mehmet", "Regex", "Safe"], "mehmet"); // 2
countOccurrences([2, 1, 3, 4, 5, 2, 7, 2], 2); // 3
Convert to Object from Array.
import { convertArray } from "regex-safe";
convertObject(
[
{ id: 1, name: "John" },
{ id: 2, name: "Jane" },
],
"name"
); // { John: { id: 1, name: "John" }, Jane: { id: 2, name: "Jane" } }
convertObject([
{ id: 1, name: "John" },
{ id: 2, name: "Jane" },
]); // { 0: { id: 1, name: "John" }, 1: { id: 2, name: "Jane" } }
import { castArray } from "regex-safe";
castArray(1, 2, 3); // [1, 2, 3]
castArray([1, 2, 3]); // [1, 2, 3]
import { isEqualArray } from "regex-safe";
isEqualArray([1, 2, 3], [1, "2", 3]); // true
isEqualArray([1, 2, 3], [1, "2", 3], true); // false
isEqualArray([1, 2, 3], [1, 2, 3], true); // true
import { boldText } from "regex-safe";
const text = "
You can make the areas you want bold in our texts using boldText. Example usage of BoldText is as follows.";
boldText(text, 'boldText'); // You can make the areas you want bold in our texts using <b>boldText</b>. Example usage of <b>BoldText</b> is as follows.
boldText(text, 'boldText', true); // You can make the areas you want bold in our texts using <b>boldText</b>. Example usage of BoldText is as follows.
import { removeHTMLTags } from "regex-safe";
removeHTMLTags("<h1>Hello world</h1>"); // Hello world
import { isEmail } from "regex-safe";
isEmail("username@mail.com"); // true
isEmail("username@m.c"); // false
import { isURL } from "regex-safe";
isURL("https://mehmetsagir.com"); // true
isURL("htp://mehmetsagir.c"); // false
import { isNum } from "regex-safe";
isNum("1"); // true
isNum("1a+"); // false
Requires first and last name.
import { isName } from "regex-safe";
isName("Mehmet Sağır"); // true
isName("Mehmet"); // false
By default all rules are enabled.
English and Turkish error message options. Default language is English.
import { isPassword } from "regex-safe";
isPassword("Test-123"); // true
isPassword("Test -123", { whitespace: false }, "tr"); // true
isPassword("Test -123"); // { valid: false, message: 'Must not contain whitespace.' }
isPassword("Test -123", {}, "tr"); // { valid: false, message: 'Boşluk içermemeli.' }
URL and image types control.
import { isImageURL } from "regex-safe";
isImageURL("https://mehmetsagir.com/wallpaper/3.webp"); // true
isImageURL("https://mehmets>agir.com/wallpaper/3."); // false
Allows us to check the value with External Regex.
import { isRegex } from "regex-safe";
isRegex("0123", /^[1-9]\d*$/g); // true
isRegex("Mehmet", /^[1-9]\d*$/g); // false
isRegex("Mehmet"); // false
import { isSlug } from "regex-safe";
isSlug("hello-world"); // true
isSlug("hello--world"); // false
import { isBoolean } from "regex-safe";
isBoolean(false); // true
isBoolean("true"); // true
isBoolean("value"); // false
import { isEven } from "regex-safe";
isEven(2); // true
isEven("2"); // true
isEven(1); // false
import { isOdd } from "regex-safe";
isOdd(3); // true
isOdd("3"); // true
isOdd(2); // false
import { isInteger } from "regex-safe";
isInteger(2); // true
isInteger(2.2); // false
import { isHexColor } from "regex-safe";
isHexColor("#000"); // true
isHexColor("00"); // false
import { isIPv4 } from "regex-safe";
isIPv4("01.102.103.104"); // true
isIPv4("01.102.103"); // false
import { isIPv6 } from "regex-safe";
isIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); // true
isIPv6("2001:0db8:85a3:0000:0000:8a2e:0370"); // false
import { isHTMLTags } from "regex-safe";
isHTMLTags("<h1>Mehmet</h1>"); // true
isHTMLTags("Mehmet"); // false
We use GitHub for versioning.
Licensed under the MIT license, see LICENSE for details.
FAQs
Easy controls with Regex.
The npm package regex-safe receives a total of 3 weekly downloads. As such, regex-safe popularity was classified as not popular.
We found that regex-safe demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Internet Archive's "Wayback Machine" has been hacked and defaced, with 31 millions records compromised.
Security News
TC39 is meeting in Tokyo this week and they have approved nearly a dozen proposals to advance to the next stages.
Security News
Our threat research team breaks down two malicious npm packages designed to exploit developer trust, steal your data, and destroy data on your machine.