diff --git a/README.md b/README.md index d110c57..3b3c3ed 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ var pattern = new Pattern(':sub.google.com', '.'); ``` the default separator is `/`. you can pass a custom separator -as the second argument to `newPattern`. +as the second argument to `Pattern`. ##### match pattern against domain @@ -117,7 +117,7 @@ pattern.match('www.google.io'); // => null ##### make pattern from regex ```javascript -var regexPattern = urlPattern.newPattern(/example\.(.*)/); +var regexPattern = new Pattern(/example\.(.*)/); ``` ##### match regex pattern against domain diff --git a/lib/url-pattern.js b/lib/url-pattern.js index 61a9969..8315a62 100644 --- a/lib/url-pattern.js +++ b/lib/url-pattern.js @@ -113,5 +113,8 @@ var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i }); return "^" + stringWithEscapedSeparators + "$"; }; + UrlPattern.newPattern = function() { + throw Error('`urlPattern.newPattern` is no longer supported. Use `new Pattern` instead.'); + }; return UrlPattern; }); diff --git a/src/url-pattern.coffee b/src/url-pattern.coffee index e6029c4..efe653e 100644 --- a/src/url-pattern.coffee +++ b/src/url-pattern.coffee @@ -103,6 +103,10 @@ .replace(':' + name,"([^\\#{separator}]+)") return "^#{stringWithEscapedSeparators}$" + + UrlPattern.newPattern = () -> + # helpful hint for new API + throw Error('`urlPattern.newPattern` is no longer supported. Use `new Pattern` instead.'); return UrlPattern ) diff --git a/test/url-pattern.coffee b/test/url-pattern.coffee index c324934..8533df5 100644 --- a/test/url-pattern.coffee +++ b/test/url-pattern.coffee @@ -273,3 +273,7 @@ module.exports = userId: '10' taskId: '52' test.done() + + 'new API warning': (test) -> + test.throws Pattern.newPattern + test.done() \ No newline at end of file