Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

copy to-iso-string; closes #2378

Christopher Hiller08a6ccf0c40b
diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 00000000..e9067bb7
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1 @@
+lib/to-iso-string/
diff --git a/lib/to-iso-string/LICENSE b/lib/to-iso-string/LICENSE
new file mode 100644
index 00000000..c25db565
--- /dev/null
+++ b/lib/to-iso-string/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2016 Segment.io, Inc. ([email protected])
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/lib/to-iso-string/index.js b/lib/to-iso-string/index.js
new file mode 100644
index 00000000..cd28d7be
--- /dev/null
+++ b/lib/to-iso-string/index.js
@@ -0,0 +1,37 @@
+'use strict';
+
+/**
+ * Pad a `number` with a ten's place zero.
+ *
+ * @param {number} number
+ * @return {string}
+ */
+function pad(number) {
+ var n = number.toString();
+ return n.length === 1 ? '0' + n : n;
+}
+
+/**
+ * Turn a `date` into an ISO string.
+ *
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
+ *
+ * @param {Date} date
+ * @return {string}
+ */
+function toISOString(date) {
+ return date.getUTCFullYear()
+ + '-' + pad(date.getUTCMonth() + 1)
+ + '-' + pad(date.getUTCDate())
+ + 'T' + pad(date.getUTCHours())
+ + ':' + pad(date.getUTCMinutes())
+ + ':' + pad(date.getUTCSeconds())
+ + '.' + String((date.getUTCMilliseconds()/1000).toFixed(3)).slice(2, 5)
+ + 'Z';
+}
+
+/*
+ * Exports.
+ */
+
+module.exports = toISOString;
diff --git a/lib/utils.js b/lib/utils.js
index dfe591c1..17bd1950 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -13,7 +13,7 @@ var join = require('path').join;
var readdirSync = require('fs').readdirSync;
var statSync = require('fs').statSync;
var watchFile = require('fs').watchFile;
-var toISOString = require('to-iso-string');
+var toISOString = require('./to-iso-string');
/**
* Ignored directories.
diff --git a/package.json b/package.json
index cb9d9e02..ecd1515b 100644
--- a/package.json
+++ b/package.json
@@ -310,8 +310,7 @@
"json3": "3.3.2",
"lodash.create": "3.1.1",
"mkdirp": "0.5.1",
- "supports-color": "3.1.2",
- "to-iso-string": "0.0.2"
+ "supports-color": "3.1.2"
},
"devDependencies": {
"browser-stdout": "^1.2.0",