save code
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
max_line_length = 120
|
||||
|
||||
[CHANGELOG.md]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.json]
|
||||
max_line_length = off
|
||||
|
||||
[Makefile]
|
||||
max_line_length = off
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"root": true,
|
||||
|
||||
"extends": "@ljharb",
|
||||
|
||||
"rules": {
|
||||
"eqeqeq": [2, "allow-null"],
|
||||
"func-name-matching": 0,
|
||||
"func-style": 0,
|
||||
"indent": [2, 4],
|
||||
"max-nested-callbacks": [2, 3],
|
||||
"max-params": [2, 3],
|
||||
"max-statements": [2, 14],
|
||||
"no-extra-parens": 0,
|
||||
"no-invalid-this": 1,
|
||||
"no-restricted-syntax": [2, "BreakStatement", "ContinueStatement", "DebuggerStatement", "LabeledStatement", "WithStatement"],
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"files": "test/**",
|
||||
"rules": {
|
||||
"array-bracket-newline": 0,
|
||||
"array-element-newline": 0,
|
||||
"max-statements-per-line": 0,
|
||||
"no-magic-numbers": 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"all": true,
|
||||
"check-coverage": false,
|
||||
"reporter": ["text-summary", "text", "html", "json"],
|
||||
"exclude": [
|
||||
"coverage"
|
||||
]
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2012 Raynos.
|
||||
|
||||
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.
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
|
||||
var isCallable = require('is-callable');
|
||||
|
||||
var toStr = Object.prototype.toString;
|
||||
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
|
||||
/** @type {<This, A extends readonly unknown[]>(arr: A, iterator: (this: This | void, value: A[number], index: number, arr: A) => void, receiver: This | undefined) => void} */
|
||||
var forEachArray = function forEachArray(array, iterator, receiver) {
|
||||
for (var i = 0, len = array.length; i < len; i++) {
|
||||
if (hasOwnProperty.call(array, i)) {
|
||||
if (receiver == null) {
|
||||
iterator(array[i], i, array);
|
||||
} else {
|
||||
iterator.call(receiver, array[i], i, array);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** @type {<This, S extends string>(string: S, iterator: (this: This | void, value: S[number], index: number, string: S) => void, receiver: This | undefined) => void} */
|
||||
var forEachString = function forEachString(string, iterator, receiver) {
|
||||
for (var i = 0, len = string.length; i < len; i++) {
|
||||
// no such thing as a sparse string.
|
||||
if (receiver == null) {
|
||||
iterator(string.charAt(i), i, string);
|
||||
} else {
|
||||
iterator.call(receiver, string.charAt(i), i, string);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** @type {<This, O>(obj: O, iterator: (this: This | void, value: O[keyof O], index: keyof O, obj: O) => void, receiver: This | undefined) => void} */
|
||||
var forEachObject = function forEachObject(object, iterator, receiver) {
|
||||
for (var k in object) {
|
||||
if (hasOwnProperty.call(object, k)) {
|
||||
if (receiver == null) {
|
||||
iterator(object[k], k, object);
|
||||
} else {
|
||||
iterator.call(receiver, object[k], k, object);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** @type {(x: unknown) => x is readonly unknown[]} */
|
||||
function isArray(x) {
|
||||
return toStr.call(x) === '[object Array]';
|
||||
}
|
||||
|
||||
/** @type {import('.')._internal} */
|
||||
module.exports = function forEach(list, iterator, thisArg) {
|
||||
if (!isCallable(iterator)) {
|
||||
throw new TypeError('iterator must be a function');
|
||||
}
|
||||
|
||||
var receiver;
|
||||
if (arguments.length >= 3) {
|
||||
receiver = thisArg;
|
||||
}
|
||||
|
||||
if (isArray(list)) {
|
||||
forEachArray(list, iterator, receiver);
|
||||
} else if (typeof list === 'string') {
|
||||
forEachString(list, iterator, receiver);
|
||||
} else {
|
||||
forEachObject(list, iterator, receiver);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user