|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
826 bytes
|
| Line | |
|---|
| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | Deep-clone an object.
|
|---|
| 5 | */
|
|---|
| 6 | function clone(obj)
|
|---|
| 7 | {
|
|---|
| 8 | if (obj instanceof Object)
|
|---|
| 9 | {
|
|---|
| 10 | var clonedObj = (obj instanceof Array) ? [] : {};
|
|---|
| 11 |
|
|---|
| 12 | for (var i in obj)
|
|---|
| 13 | {
|
|---|
| 14 | if ( obj.hasOwnProperty(i) )
|
|---|
| 15 | {
|
|---|
| 16 | clonedObj[i] = clone( obj[i] );
|
|---|
| 17 | }
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | return clonedObj;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | return obj;
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | /*
|
|---|
| 29 | https://github.com/jonschlinkert/is-plain-object
|
|---|
| 30 | */
|
|---|
| 31 | function isPlainObject(obj)
|
|---|
| 32 | {
|
|---|
| 33 | return !!obj && typeof obj==="object" && obj.constructor===Object;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | /*
|
|---|
| 39 | Shallow-merge two objects.
|
|---|
| 40 | */
|
|---|
| 41 | function shallowMerge(target, source)
|
|---|
| 42 | {
|
|---|
| 43 | if (target instanceof Object && source instanceof Object)
|
|---|
| 44 | {
|
|---|
| 45 | for (var i in source)
|
|---|
| 46 | {
|
|---|
| 47 | if ( source.hasOwnProperty(i) )
|
|---|
| 48 | {
|
|---|
| 49 | target[i] = source[i];
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | return target;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 | module.exports =
|
|---|
| 60 | {
|
|---|
| 61 | clone: clone,
|
|---|
| 62 | isPlainObject: isPlainObject,
|
|---|
| 63 | shallowMerge: shallowMerge
|
|---|
| 64 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.