Skip to content

Commit 8cc746d

Browse files
author
Steve Hobbs
authored
Merge pull request #27 from auth0/inline-format
Inline format function from the native utils module
2 parents d57db7c + 2fb3894 commit 8cc746d

File tree

9 files changed

+932
-8
lines changed

9 files changed

+932
-8
lines changed

.circleci/config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 2.1
2+
orbs:
3+
node: circleci/node@1.1
4+
jobs:
5+
build:
6+
executor:
7+
name: node/default
8+
tag: '14.15'
9+
steps:
10+
- checkout
11+
- node/with-cache:
12+
steps:
13+
- run: npm install
14+
- run: npm run test

LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,26 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1818
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
1919
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2020
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
============================================================================
23+
24+
Copyright + license attribution for `format` function used in lib/helper.js:
25+
26+
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
27+
Permission is hereby granted, free of charge, to any person obtaining a copy
28+
of this software and associated documentation files (the "Software"), to
29+
deal in the Software without restriction, including without limitation the
30+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
31+
sell copies of the Software, and to permit persons to whom the Software is
32+
furnished to do so, subject to the following conditions:
33+
34+
The above copyright notice and this permission notice shall be included in
35+
all copies or substantial portions of the Software.
36+
37+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
42+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
43+
IN THE SOFTWARE.

examples/basic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var assert = require('assert');
22

3-
var format = require('util').format;
3+
var format = require('../lib/helper').format;
44

55
var PasswordPolicy = require('..').PasswordPolicy;
66

examples/custom-rule.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
var assert = require('assert');
22

3-
var format = require('util').format;
4-
53
// Custom rules
64

75
// Let's create a custom rule named Foo. The rule will enforce that

lib/helper.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,43 @@ _.isNaN = function(obj) {
7070
return _.isNumber(obj) && isNaN(obj);
7171
};
7272

73+
// Code attribution
74+
// Inlined and modified from https://github.com/browserify/node-util/blob/e37ce41f4063bcd7bc27e01470d6654053bdcd14/util.js#L33-L69
75+
// Copyright Joyent, Inc. and other Node contributors.
76+
// Please see LICENSE for full copyright and license attribution.
77+
var formatRegExp = /%[sdj%]/g;
78+
79+
_.format = function (f) {
80+
var i = 1;
81+
var args = arguments;
82+
var len = args.length;
83+
var str = String(f).replace(formatRegExp, function(x) {
84+
if (x === '%%') return '%';
85+
if (i >= len) return x;
86+
switch (x) {
87+
case '%s':
88+
return String(args[i++]);
89+
case '%d':
90+
return Number(args[i++]);
91+
case '%j':
92+
try {
93+
return JSON.stringify(args[i++]);
94+
} catch (_) {
95+
return '[Circular]';
96+
}
97+
default:
98+
return x;
99+
}
100+
});
101+
for (var x = args[i]; i < len; x = args[++i]) {
102+
if (x === null || !_.isObject(x)) {
103+
str += ' ' + x;
104+
} else if (x !== null) {
105+
str += ' ' + JSON.stringify(x);
106+
}
107+
}
108+
return str;
109+
}
110+
// End code attribution
111+
73112
module.exports = _;

lib/policy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var format = require('util').format;
1+
var format = require('./helper').format;
22

33
var PasswordPolicyError = require('./policy_error');
44

0 commit comments

Comments
 (0)