source: imaps-frontend/node_modules/relateurl/lib/util/object.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 826 bytes
Line 
1"use strict";
2
3/*
4 Deep-clone an object.
5*/
6function 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*/
31function isPlainObject(obj)
32{
33 return !!obj && typeof obj==="object" && obj.constructor===Object;
34}
35
36
37
38/*
39 Shallow-merge two objects.
40*/
41function 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
59module.exports =
60{
61 clone: clone,
62 isPlainObject: isPlainObject,
63 shallowMerge: shallowMerge
64};
Note: See TracBrowser for help on using the repository browser.