krl-stdlib
Advanced tools
Comparing version 0.45.1 to 0.45.4
{ | ||
"name": "krl-stdlib", | ||
"version": "0.45.1", | ||
"version": "0.45.4", | ||
"description": "Standard library for KRL", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -189,5 +189,9 @@ var _ = require("lodash"); | ||
if(type === "RegExp"){ | ||
if(val_type === "String"){ | ||
return new RegExp(val); | ||
var regexSrc = types.toString(val); | ||
if(val_type !== "String" && /^\[[a-z]+\]$/i.test(regexSrc)){ | ||
regexSrc = regexSrc | ||
.replace(/^\[/, "\\[") | ||
.replace(/\]$/, "\\]"); | ||
} | ||
return new RegExp(regexSrc); | ||
} | ||
@@ -194,0 +198,0 @@ throw new TypeError("Cannot use the .as(\""+type+"\") operator with " + types.toString(val) + " (type " + val_type + ")"); |
@@ -306,2 +306,7 @@ var _ = require("lodash"); | ||
t.equals(stdlib.as(defaultCTX, "^a.*z$", "RegExp").source, /^a.*z$/.source); | ||
t.equals(stdlib.as(defaultCTX, null, "RegExp").source, "null"); | ||
t.equals(stdlib.as(defaultCTX, 123, "RegExp").source, "123"); | ||
t.equals(stdlib.as(defaultCTX, _.noop, "RegExp").source, "\\[Function\\]"); | ||
t.equals(stdlib.as(defaultCTX, "[Function]", "RegExp").source, "[Function]"); | ||
var test_regex = /^a.*z$/; | ||
@@ -308,0 +313,0 @@ tf("as", [test_regex, "RegExp"], test_regex); |
67930
1952