clone-help-test01 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +35 -0
- package/package.json +15 -0
- package/rollup.config.js +8 -0
- package/src/clone.js +26 -0
- package/src/index.html +23 -0
package/dist/bundle.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var _ = (function (exports) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
function type(data) {
|
|
5
|
+
return Object.prototype.toString.call(data).slice(8, -1).toLowerCase();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function clone(source) {
|
|
10
|
+
const t = type(source);
|
|
11
|
+
if (t !== 'object' && t !== 'array') {
|
|
12
|
+
return source;
|
|
13
|
+
}
|
|
14
|
+
let target;
|
|
15
|
+
if (t === 'object') {
|
|
16
|
+
target = {};
|
|
17
|
+
for (const i in source) {
|
|
18
|
+
if (source.hasOwnProperty(i)) {
|
|
19
|
+
target[i] = clone(source[i]);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
target = [];
|
|
24
|
+
for (let i = 0; i < source.length; i++) {
|
|
25
|
+
target[i] = clone(target[i]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return target;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.clone = clone;
|
|
32
|
+
|
|
33
|
+
return exports;
|
|
34
|
+
|
|
35
|
+
})({});
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "clone-help-test01",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "clone.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"build": "rollup -c"
|
|
9
|
+
},
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"rollup": "^4.59.0"
|
|
14
|
+
}
|
|
15
|
+
}
|
package/rollup.config.js
ADDED
package/src/clone.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function type(data) {
|
|
2
|
+
return Object.prototype.toString.call(data).slice(8, -1).toLowerCase();
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export function clone(source) {
|
|
7
|
+
const t = type(source)
|
|
8
|
+
if (t !== 'object' && t !== 'array') {
|
|
9
|
+
return source;
|
|
10
|
+
}
|
|
11
|
+
let target;
|
|
12
|
+
if (t === 'object') {
|
|
13
|
+
target = {};
|
|
14
|
+
for (const i in source) {
|
|
15
|
+
if (source.hasOwnProperty(i)) {
|
|
16
|
+
target[i] = clone(source[i])
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
target = [];
|
|
21
|
+
for (let i = 0; i < source.length; i++) {
|
|
22
|
+
target[i] = clone(target[i])
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return target;
|
|
26
|
+
}
|
package/src/index.html
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>Document</title>
|
|
8
|
+
<script src="../dist/bundle.js"></script>
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
<script>
|
|
13
|
+
const obj = {
|
|
14
|
+
name: 'sunian',
|
|
15
|
+
age: '28',
|
|
16
|
+
}
|
|
17
|
+
const cloneData = _.clone(obj)
|
|
18
|
+
console.log(cloneData);
|
|
19
|
+
|
|
20
|
+
</script>
|
|
21
|
+
</body>
|
|
22
|
+
|
|
23
|
+
</html>
|