├── .gitattributes ├── .gitignore ├── .npmignore ├── License ├── README.html └── README.txt ├── Readme.md ├── browser ├── index.html ├── jasmine │ ├── MIT.LICENSE │ ├── jasmine-html.js │ ├── jasmine.css │ └── jasmine.js ├── object-merge_tests.html ├── object-merge_web.js └── tests │ └── object-merge.test.js ├── dev ├── browserMain.js └── browserify.js ├── docs ├── jsdoc │ ├── files.html │ ├── index.html │ └── symbols │ │ ├── _global_.html │ │ └── objectMerge.html └── vsdoc │ ├── OpenLayersAll.js │ ├── OpenLayersReferences.js │ ├── files.html │ ├── index.html │ └── symbols │ ├── _global_-vsdoc.js │ └── objectMerge-vsdoc.js ├── package.json ├── rebuild.cmd ├── specs └── object-merge.Spec.js └── src └── object-merge.js /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | logs/ 2 | node_modules/ 3 | *npm-debug.log 4 | 5 | ############# 6 | ## Windows detritus 7 | ############# 8 | 9 | # Windows image file caches 10 | Thumbs.db 11 | ehthumbs.db 12 | 13 | # Folder config file 14 | Desktop.ini 15 | 16 | # Recycle Bin used on file shares 17 | $RECYCLE.BIN/ 18 | /.vs 19 | /package-lock.json 20 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | logs/ 2 | node_modules/ 3 | *npm-debug.log 4 | 5 | ############# 6 | ## Windows detritus 7 | ############# 8 | 9 | # Windows image file caches 10 | Thumbs.db 11 | ehthumbs.db 12 | 13 | # Folder config file 14 | Desktop.ini 15 | 16 | # Recycle Bin used on file shares 17 | $RECYCLE.BIN/ 18 | /.vs 19 | /package-lock.json 20 | -------------------------------------------------------------------------------- /License/README.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | GNU General Public License v3.0 - GNU Project - Free Software Foundation (FSF) 6 | 8 | 9 | 10 |

GNU GENERAL PUBLIC LICENSE

11 |

Version 3, 29 June 2007

12 | 13 |

Copyright © 2007 Free Software Foundation, Inc. 14 | <http://fsf.org/>

15 | Everyone is permitted to copy and distribute verbatim copies 16 | of this license document, but changing it is not allowed.

17 | 18 |

Preamble

19 | 20 |

The GNU General Public License is a free, copyleft license for 21 | software and other kinds of works.

22 | 23 |

The licenses for most software and other practical works are designed 24 | to take away your freedom to share and change the works. By contrast, 25 | the GNU General Public License is intended to guarantee your freedom to 26 | share and change all versions of a program--to make sure it remains free 27 | software for all its users. We, the Free Software Foundation, use the 28 | GNU General Public License for most of our software; it applies also to 29 | any other work released this way by its authors. You can apply it to 30 | your programs, too.

31 | 32 |

When we speak of free software, we are referring to freedom, not 33 | price. Our General Public Licenses are designed to make sure that you 34 | have the freedom to distribute copies of free software (and charge for 35 | them if you wish), that you receive source code or can get it if you 36 | want it, that you can change the software or use pieces of it in new 37 | free programs, and that you know you can do these things.

38 | 39 |

To protect your rights, we need to prevent others from denying you 40 | these rights or asking you to surrender the rights. Therefore, you have 41 | certain responsibilities if you distribute copies of the software, or if 42 | you modify it: responsibilities to respect the freedom of others.

43 | 44 |

For example, if you distribute copies of such a program, whether 45 | gratis or for a fee, you must pass on to the recipients the same 46 | freedoms that you received. You must make sure that they, too, receive 47 | or can get the source code. And you must show them these terms so they 48 | know their rights.

49 | 50 |

Developers that use the GNU GPL protect your rights with two steps: 51 | (1) assert copyright on the software, and (2) offer you this License 52 | giving you legal permission to copy, distribute and/or modify it.

53 | 54 |

For the developers' and authors' protection, the GPL clearly explains 55 | that there is no warranty for this free software. For both users' and 56 | authors' sake, the GPL requires that modified versions be marked as 57 | changed, so that their problems will not be attributed erroneously to 58 | authors of previous versions.

59 | 60 |

Some devices are designed to deny users access to install or run 61 | modified versions of the software inside them, although the manufacturer 62 | can do so. This is fundamentally incompatible with the aim of 63 | protecting users' freedom to change the software. The systematic 64 | pattern of such abuse occurs in the area of products for individuals to 65 | use, which is precisely where it is most unacceptable. Therefore, we 66 | have designed this version of the GPL to prohibit the practice for those 67 | products. If such problems arise substantially in other domains, we 68 | stand ready to extend this provision to those domains in future versions 69 | of the GPL, as needed to protect the freedom of users.

70 | 71 |

Finally, every program is threatened constantly by software patents. 72 | States should not allow patents to restrict development and use of 73 | software on general-purpose computers, but in those that do, we wish to 74 | avoid the special danger that patents applied to a free program could 75 | make it effectively proprietary. To prevent this, the GPL assures that 76 | patents cannot be used to render the program non-free.

77 | 78 |

The precise terms and conditions for copying, distribution and 79 | modification follow.

80 | 81 |

TERMS AND CONDITIONS

82 | 83 |

0. Definitions.

84 | 85 |

“This License” refers to version 3 of the GNU General Public License.

86 | 87 |

“Copyright” also means copyright-like laws that apply to other kinds of 88 | works, such as semiconductor masks.

89 | 90 |

“The Program” refers to any copyrightable work licensed under this 91 | License. Each licensee is addressed as “you”. “Licensees” and 92 | “recipients” may be individuals or organizations.

93 | 94 |

To “modify” a work means to copy from or adapt all or part of the work 95 | in a fashion requiring copyright permission, other than the making of an 96 | exact copy. The resulting work is called a “modified version” of the 97 | earlier work or a work “based on” the earlier work.

98 | 99 |

A “covered work” means either the unmodified Program or a work based 100 | on the Program.

101 | 102 |

To “propagate” a work means to do anything with it that, without 103 | permission, would make you directly or secondarily liable for 104 | infringement under applicable copyright law, except executing it on a 105 | computer or modifying a private copy. Propagation includes copying, 106 | distribution (with or without modification), making available to the 107 | public, and in some countries other activities as well.

108 | 109 |

To “convey” a work means any kind of propagation that enables other 110 | parties to make or receive copies. Mere interaction with a user through 111 | a computer network, with no transfer of a copy, is not conveying.

112 | 113 |

An interactive user interface displays “Appropriate Legal Notices” 114 | to the extent that it includes a convenient and prominently visible 115 | feature that (1) displays an appropriate copyright notice, and (2) 116 | tells the user that there is no warranty for the work (except to the 117 | extent that warranties are provided), that licensees may convey the 118 | work under this License, and how to view a copy of this License. If 119 | the interface presents a list of user commands or options, such as a 120 | menu, a prominent item in the list meets this criterion.

121 | 122 |

1. Source Code.

123 | 124 |

The “source code” for a work means the preferred form of the work 125 | for making modifications to it. “Object code” means any non-source 126 | form of a work.

127 | 128 |

A “Standard Interface” means an interface that either is an official 129 | standard defined by a recognized standards body, or, in the case of 130 | interfaces specified for a particular programming language, one that 131 | is widely used among developers working in that language.

132 | 133 |

The “System Libraries” of an executable work include anything, other 134 | than the work as a whole, that (a) is included in the normal form of 135 | packaging a Major Component, but which is not part of that Major 136 | Component, and (b) serves only to enable use of the work with that 137 | Major Component, or to implement a Standard Interface for which an 138 | implementation is available to the public in source code form. A 139 | “Major Component”, in this context, means a major essential component 140 | (kernel, window system, and so on) of the specific operating system 141 | (if any) on which the executable work runs, or a compiler used to 142 | produce the work, or an object code interpreter used to run it.

143 | 144 |

The “Corresponding Source” for a work in object code form means all 145 | the source code needed to generate, install, and (for an executable 146 | work) run the object code and to modify the work, including scripts to 147 | control those activities. However, it does not include the work's 148 | System Libraries, or general-purpose tools or generally available free 149 | programs which are used unmodified in performing those activities but 150 | which are not part of the work. For example, Corresponding Source 151 | includes interface definition files associated with source files for 152 | the work, and the source code for shared libraries and dynamically 153 | linked subprograms that the work is specifically designed to require, 154 | such as by intimate data communication or control flow between those 155 | subprograms and other parts of the work.

156 | 157 |

The Corresponding Source need not include anything that users 158 | can regenerate automatically from other parts of the Corresponding 159 | Source.

160 | 161 |

The Corresponding Source for a work in source code form is that 162 | same work.

163 | 164 |

2. Basic Permissions.

165 | 166 |

All rights granted under this License are granted for the term of 167 | copyright on the Program, and are irrevocable provided the stated 168 | conditions are met. This License explicitly affirms your unlimited 169 | permission to run the unmodified Program. The output from running a 170 | covered work is covered by this License only if the output, given its 171 | content, constitutes a covered work. This License acknowledges your 172 | rights of fair use or other equivalent, as provided by copyright law.

173 | 174 |

You may make, run and propagate covered works that you do not 175 | convey, without conditions so long as your license otherwise remains 176 | in force. You may convey covered works to others for the sole purpose 177 | of having them make modifications exclusively for you, or provide you 178 | with facilities for running those works, provided that you comply with 179 | the terms of this License in conveying all material for which you do 180 | not control copyright. Those thus making or running the covered works 181 | for you must do so exclusively on your behalf, under your direction 182 | and control, on terms that prohibit them from making any copies of 183 | your copyrighted material outside their relationship with you.

184 | 185 |

Conveying under any other circumstances is permitted solely under 186 | the conditions stated below. Sublicensing is not allowed; section 10 187 | makes it unnecessary.

188 | 189 |

3. Protecting Users' Legal Rights From Anti-Circumvention Law.

190 | 191 |

No covered work shall be deemed part of an effective technological 192 | measure under any applicable law fulfilling obligations under article 193 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 194 | similar laws prohibiting or restricting circumvention of such 195 | measures.

196 | 197 |

When you convey a covered work, you waive any legal power to forbid 198 | circumvention of technological measures to the extent such circumvention 199 | is effected by exercising rights under this License with respect to 200 | the covered work, and you disclaim any intention to limit operation or 201 | modification of the work as a means of enforcing, against the work's 202 | users, your or third parties' legal rights to forbid circumvention of 203 | technological measures.

204 | 205 |

4. Conveying Verbatim Copies.

206 | 207 |

You may convey verbatim copies of the Program's source code as you 208 | receive it, in any medium, provided that you conspicuously and 209 | appropriately publish on each copy an appropriate copyright notice; 210 | keep intact all notices stating that this License and any 211 | non-permissive terms added in accord with section 7 apply to the code; 212 | keep intact all notices of the absence of any warranty; and give all 213 | recipients a copy of this License along with the Program.

214 | 215 |

You may charge any price or no price for each copy that you convey, 216 | and you may offer support or warranty protection for a fee.

217 | 218 |

5. Conveying Modified Source Versions.

219 | 220 |

You may convey a work based on the Program, or the modifications to 221 | produce it from the Program, in the form of source code under the 222 | terms of section 4, provided that you also meet all of these conditions:

223 | 224 | 246 | 247 |

A compilation of a covered work with other separate and independent 248 | works, which are not by their nature extensions of the covered work, 249 | and which are not combined with it such as to form a larger program, 250 | in or on a volume of a storage or distribution medium, is called an 251 | “aggregate” if the compilation and its resulting copyright are not 252 | used to limit the access or legal rights of the compilation's users 253 | beyond what the individual works permit. Inclusion of a covered work 254 | in an aggregate does not cause this License to apply to the other 255 | parts of the aggregate.

256 | 257 |

6. Conveying Non-Source Forms.

258 | 259 |

You may convey a covered work in object code form under the terms 260 | of sections 4 and 5, provided that you also convey the 261 | machine-readable Corresponding Source under the terms of this License, 262 | in one of these ways:

263 | 264 | 306 | 307 |

A separable portion of the object code, whose source code is excluded 308 | from the Corresponding Source as a System Library, need not be 309 | included in conveying the object code work.

310 | 311 |

A “User Product” is either (1) a “consumer product”, which means any 312 | tangible personal property which is normally used for personal, family, 313 | or household purposes, or (2) anything designed or sold for incorporation 314 | into a dwelling. In determining whether a product is a consumer product, 315 | doubtful cases shall be resolved in favor of coverage. For a particular 316 | product received by a particular user, “normally used” refers to a 317 | typical or common use of that class of product, regardless of the status 318 | of the particular user or of the way in which the particular user 319 | actually uses, or expects or is expected to use, the product. A product 320 | is a consumer product regardless of whether the product has substantial 321 | commercial, industrial or non-consumer uses, unless such uses represent 322 | the only significant mode of use of the product.

323 | 324 |

“Installation Information” for a User Product means any methods, 325 | procedures, authorization keys, or other information required to install 326 | and execute modified versions of a covered work in that User Product from 327 | a modified version of its Corresponding Source. The information must 328 | suffice to ensure that the continued functioning of the modified object 329 | code is in no case prevented or interfered with solely because 330 | modification has been made.

331 | 332 |

If you convey an object code work under this section in, or with, or 333 | specifically for use in, a User Product, and the conveying occurs as 334 | part of a transaction in which the right of possession and use of the 335 | User Product is transferred to the recipient in perpetuity or for a 336 | fixed term (regardless of how the transaction is characterized), the 337 | Corresponding Source conveyed under this section must be accompanied 338 | by the Installation Information. But this requirement does not apply 339 | if neither you nor any third party retains the ability to install 340 | modified object code on the User Product (for example, the work has 341 | been installed in ROM).

342 | 343 |

The requirement to provide Installation Information does not include a 344 | requirement to continue to provide support service, warranty, or updates 345 | for a work that has been modified or installed by the recipient, or for 346 | the User Product in which it has been modified or installed. Access to a 347 | network may be denied when the modification itself materially and 348 | adversely affects the operation of the network or violates the rules and 349 | protocols for communication across the network.

350 | 351 |

Corresponding Source conveyed, and Installation Information provided, 352 | in accord with this section must be in a format that is publicly 353 | documented (and with an implementation available to the public in 354 | source code form), and must require no special password or key for 355 | unpacking, reading or copying.

356 | 357 |

7. Additional Terms.

358 | 359 |

“Additional permissions” are terms that supplement the terms of this 360 | License by making exceptions from one or more of its conditions. 361 | Additional permissions that are applicable to the entire Program shall 362 | be treated as though they were included in this License, to the extent 363 | that they are valid under applicable law. If additional permissions 364 | apply only to part of the Program, that part may be used separately 365 | under those permissions, but the entire Program remains governed by 366 | this License without regard to the additional permissions.

367 | 368 |

When you convey a copy of a covered work, you may at your option 369 | remove any additional permissions from that copy, or from any part of 370 | it. (Additional permissions may be written to require their own 371 | removal in certain cases when you modify the work.) You may place 372 | additional permissions on material, added by you to a covered work, 373 | for which you have or can give appropriate copyright permission.

374 | 375 |

Notwithstanding any other provision of this License, for material you 376 | add to a covered work, you may (if authorized by the copyright holders of 377 | that material) supplement the terms of this License with terms:

378 | 379 | 403 | 404 |

All other non-permissive additional terms are considered “further 405 | restrictions” within the meaning of section 10. If the Program as you 406 | received it, or any part of it, contains a notice stating that it is 407 | governed by this License along with a term that is a further 408 | restriction, you may remove that term. If a license document contains 409 | a further restriction but permits relicensing or conveying under this 410 | License, you may add to a covered work material governed by the terms 411 | of that license document, provided that the further restriction does 412 | not survive such relicensing or conveying.

413 | 414 |

If you add terms to a covered work in accord with this section, you 415 | must place, in the relevant source files, a statement of the 416 | additional terms that apply to those files, or a notice indicating 417 | where to find the applicable terms.

418 | 419 |

Additional terms, permissive or non-permissive, may be stated in the 420 | form of a separately written license, or stated as exceptions; 421 | the above requirements apply either way.

422 | 423 |

8. Termination.

424 | 425 |

You may not propagate or modify a covered work except as expressly 426 | provided under this License. Any attempt otherwise to propagate or 427 | modify it is void, and will automatically terminate your rights under 428 | this License (including any patent licenses granted under the third 429 | paragraph of section 11).

430 | 431 |

However, if you cease all violation of this License, then your 432 | license from a particular copyright holder is reinstated (a) 433 | provisionally, unless and until the copyright holder explicitly and 434 | finally terminates your license, and (b) permanently, if the copyright 435 | holder fails to notify you of the violation by some reasonable means 436 | prior to 60 days after the cessation.

437 | 438 |

Moreover, your license from a particular copyright holder is 439 | reinstated permanently if the copyright holder notifies you of the 440 | violation by some reasonable means, this is the first time you have 441 | received notice of violation of this License (for any work) from that 442 | copyright holder, and you cure the violation prior to 30 days after 443 | your receipt of the notice.

444 | 445 |

Termination of your rights under this section does not terminate the 446 | licenses of parties who have received copies or rights from you under 447 | this License. If your rights have been terminated and not permanently 448 | reinstated, you do not qualify to receive new licenses for the same 449 | material under section 10.

450 | 451 |

9. Acceptance Not Required for Having Copies.

452 | 453 |

You are not required to accept this License in order to receive or 454 | run a copy of the Program. Ancillary propagation of a covered work 455 | occurring solely as a consequence of using peer-to-peer transmission 456 | to receive a copy likewise does not require acceptance. However, 457 | nothing other than this License grants you permission to propagate or 458 | modify any covered work. These actions infringe copyright if you do 459 | not accept this License. Therefore, by modifying or propagating a 460 | covered work, you indicate your acceptance of this License to do so.

461 | 462 |

10. Automatic Licensing of Downstream Recipients.

463 | 464 |

Each time you convey a covered work, the recipient automatically 465 | receives a license from the original licensors, to run, modify and 466 | propagate that work, subject to this License. You are not responsible 467 | for enforcing compliance by third parties with this License.

468 | 469 |

An “entity transaction” is a transaction transferring control of an 470 | organization, or substantially all assets of one, or subdividing an 471 | organization, or merging organizations. If propagation of a covered 472 | work results from an entity transaction, each party to that 473 | transaction who receives a copy of the work also receives whatever 474 | licenses to the work the party's predecessor in interest had or could 475 | give under the previous paragraph, plus a right to possession of the 476 | Corresponding Source of the work from the predecessor in interest, if 477 | the predecessor has it or can get it with reasonable efforts.

478 | 479 |

You may not impose any further restrictions on the exercise of the 480 | rights granted or affirmed under this License. For example, you may 481 | not impose a license fee, royalty, or other charge for exercise of 482 | rights granted under this License, and you may not initiate litigation 483 | (including a cross-claim or counterclaim in a lawsuit) alleging that 484 | any patent claim is infringed by making, using, selling, offering for 485 | sale, or importing the Program or any portion of it.

486 | 487 |

11. Patents.

488 | 489 |

A “contributor” is a copyright holder who authorizes use under this 490 | License of the Program or a work on which the Program is based. The 491 | work thus licensed is called the contributor's “contributor version”.

492 | 493 |

A contributor's “essential patent claims” are all patent claims 494 | owned or controlled by the contributor, whether already acquired or 495 | hereafter acquired, that would be infringed by some manner, permitted 496 | by this License, of making, using, or selling its contributor version, 497 | but do not include claims that would be infringed only as a 498 | consequence of further modification of the contributor version. For 499 | purposes of this definition, “control” includes the right to grant 500 | patent sublicenses in a manner consistent with the requirements of 501 | this License.

502 | 503 |

Each contributor grants you a non-exclusive, worldwide, royalty-free 504 | patent license under the contributor's essential patent claims, to 505 | make, use, sell, offer for sale, import and otherwise run, modify and 506 | propagate the contents of its contributor version.

507 | 508 |

In the following three paragraphs, a “patent license” is any express 509 | agreement or commitment, however denominated, not to enforce a patent 510 | (such as an express permission to practice a patent or covenant not to 511 | sue for patent infringement). To “grant” such a patent license to a 512 | party means to make such an agreement or commitment not to enforce a 513 | patent against the party.

514 | 515 |

If you convey a covered work, knowingly relying on a patent license, 516 | and the Corresponding Source of the work is not available for anyone 517 | to copy, free of charge and under the terms of this License, through a 518 | publicly available network server or other readily accessible means, 519 | then you must either (1) cause the Corresponding Source to be so 520 | available, or (2) arrange to deprive yourself of the benefit of the 521 | patent license for this particular work, or (3) arrange, in a manner 522 | consistent with the requirements of this License, to extend the patent 523 | license to downstream recipients. “Knowingly relying” means you have 524 | actual knowledge that, but for the patent license, your conveying the 525 | covered work in a country, or your recipient's use of the covered work 526 | in a country, would infringe one or more identifiable patents in that 527 | country that you have reason to believe are valid.

528 | 529 |

If, pursuant to or in connection with a single transaction or 530 | arrangement, you convey, or propagate by procuring conveyance of, a 531 | covered work, and grant a patent license to some of the parties 532 | receiving the covered work authorizing them to use, propagate, modify 533 | or convey a specific copy of the covered work, then the patent license 534 | you grant is automatically extended to all recipients of the covered 535 | work and works based on it.

536 | 537 |

A patent license is “discriminatory” if it does not include within 538 | the scope of its coverage, prohibits the exercise of, or is 539 | conditioned on the non-exercise of one or more of the rights that are 540 | specifically granted under this License. You may not convey a covered 541 | work if you are a party to an arrangement with a third party that is 542 | in the business of distributing software, under which you make payment 543 | to the third party based on the extent of your activity of conveying 544 | the work, and under which the third party grants, to any of the 545 | parties who would receive the covered work from you, a discriminatory 546 | patent license (a) in connection with copies of the covered work 547 | conveyed by you (or copies made from those copies), or (b) primarily 548 | for and in connection with specific products or compilations that 549 | contain the covered work, unless you entered into that arrangement, 550 | or that patent license was granted, prior to 28 March 2007.

551 | 552 |

Nothing in this License shall be construed as excluding or limiting 553 | any implied license or other defenses to infringement that may 554 | otherwise be available to you under applicable patent law.

555 | 556 |

12. No Surrender of Others' Freedom.

557 | 558 |

If conditions are imposed on you (whether by court order, agreement or 559 | otherwise) that contradict the conditions of this License, they do not 560 | excuse you from the conditions of this License. If you cannot convey a 561 | covered work so as to satisfy simultaneously your obligations under this 562 | License and any other pertinent obligations, then as a consequence you may 563 | not convey it at all. For example, if you agree to terms that obligate you 564 | to collect a royalty for further conveying from those to whom you convey 565 | the Program, the only way you could satisfy both those terms and this 566 | License would be to refrain entirely from conveying the Program.

567 | 568 |

13. Use with the GNU Affero General Public License.

569 | 570 |

Notwithstanding any other provision of this License, you have 571 | permission to link or combine any covered work with a work licensed 572 | under version 3 of the GNU Affero General Public License into a single 573 | combined work, and to convey the resulting work. The terms of this 574 | License will continue to apply to the part which is the covered work, 575 | but the special requirements of the GNU Affero General Public License, 576 | section 13, concerning interaction through a network will apply to the 577 | combination as such.

578 | 579 |

14. Revised Versions of this License.

580 | 581 |

The Free Software Foundation may publish revised and/or new versions of 582 | the GNU General Public License from time to time. Such new versions will 583 | be similar in spirit to the present version, but may differ in detail to 584 | address new problems or concerns.

585 | 586 |

Each version is given a distinguishing version number. If the 587 | Program specifies that a certain numbered version of the GNU General 588 | Public License “or any later version” applies to it, you have the 589 | option of following the terms and conditions either of that numbered 590 | version or of any later version published by the Free Software 591 | Foundation. If the Program does not specify a version number of the 592 | GNU General Public License, you may choose any version ever published 593 | by the Free Software Foundation.

594 | 595 |

If the Program specifies that a proxy can decide which future 596 | versions of the GNU General Public License can be used, that proxy's 597 | public statement of acceptance of a version permanently authorizes you 598 | to choose that version for the Program.

599 | 600 |

Later license versions may give you additional or different 601 | permissions. However, no additional obligations are imposed on any 602 | author or copyright holder as a result of your choosing to follow a 603 | later version.

604 | 605 |

15. Disclaimer of Warranty.

606 | 607 |

THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 608 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 609 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY 610 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 611 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 612 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 613 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 614 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

615 | 616 |

16. Limitation of Liability.

617 | 618 |

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 619 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 620 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 621 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 622 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 623 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 624 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 625 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 626 | SUCH DAMAGES.

627 | 628 |

17. Interpretation of Sections 15 and 16.

629 | 630 |

If the disclaimer of warranty and limitation of liability provided 631 | above cannot be given local legal effect according to their terms, 632 | reviewing courts shall apply local law that most closely approximates 633 | an absolute waiver of all civil liability in connection with the 634 | Program, unless a warranty or assumption of liability accompanies a 635 | copy of the Program in return for a fee.

636 | 637 |

END OF TERMS AND CONDITIONS

638 | 639 |

How to Apply These Terms to Your New Programs

640 | 641 |

If you develop a new program, and you want it to be of the greatest 642 | possible use to the public, the best way to achieve this is to make it 643 | free software which everyone can redistribute and change under these terms.

644 | 645 |

To do so, attach the following notices to the program. It is safest 646 | to attach them to the start of each source file to most effectively 647 | state the exclusion of warranty; and each file should have at least 648 | the “copyright” line and a pointer to where the full notice is found.

649 | 650 |
    <one line to give the program's name and a brief idea of what it does.>
651 |     Copyright (C) <year>  <name of author>
652 | 
653 |     This program is free software: you can redistribute it and/or modify
654 |     it under the terms of the GNU General Public License as published by
655 |     the Free Software Foundation, either version 3 of the License, or
656 |     (at your option) any later version.
657 | 
658 |     This program is distributed in the hope that it will be useful,
659 |     but WITHOUT ANY WARRANTY; without even the implied warranty of
660 |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
661 |     GNU General Public License for more details.
662 | 
663 |     You should have received a copy of the GNU General Public License
664 |     along with this program.  If not, see <http://www.gnu.org/licenses/>.
665 | 
666 | 667 |

Also add information on how to contact you by electronic and paper mail.

668 | 669 |

If the program does terminal interaction, make it output a short 670 | notice like this when it starts in an interactive mode:

671 | 672 |
    <program>  Copyright (C) <year>  <name of author>
673 |     This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
674 |     This is free software, and you are welcome to redistribute it
675 |     under certain conditions; type `show c' for details.
676 | 
677 | 678 |

The hypothetical commands `show w' and `show c' should show the appropriate 679 | parts of the General Public License. Of course, your program's commands 680 | might be different; for a GUI interface, you would use an “about box”.

681 | 682 |

You should also get your employer (if you work as a programmer) or school, 683 | if any, to sign a “copyright disclaimer” for the program, if necessary. 684 | For more information on this, and how to apply and follow the GNU GPL, see 685 | <http://www.gnu.org/licenses/>.

686 | 687 |

The GNU General Public License does not permit incorporating your program 688 | into proprietary programs. If your program is a subroutine library, you 689 | may consider it more useful to permit linking proprietary applications with 690 | the library. If this is what you want to do, use the GNU Lesser General 691 | Public License instead of this License. But first, please read 692 | <http://www.gnu.org/philosophy/why-not-lgpl.html>.

693 | 694 | 695 | -------------------------------------------------------------------------------- /License/README.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # object-merge 2 | 3 | Merges JavaScript objects recursively without altering the objects merged. 4 | 5 | ## Installation 6 | 7 | ``` 8 | npm install object-merge 9 | ``` 10 | 11 | https://npmjs.org/package/object-merge 12 | Source code available at: https://github.com/matthewkastor/object-merge/ 13 | 14 | ## Usage 15 | 16 | In Node: 17 | 18 | ``` 19 | var objectMerge = require('object-merge'); 20 | var x = { 21 | a : 'a', 22 | b : 'b', 23 | c : { 24 | d : 'd', 25 | e : 'e', 26 | f : { 27 | g : 'g' 28 | } 29 | } 30 | }; 31 | var y = { 32 | a : '`a', 33 | b : '`b', 34 | c : { 35 | d : '`d' 36 | } 37 | }; 38 | var z = { 39 | a : { 40 | b : '``b' 41 | }, 42 | fun : function foo () { 43 | return 'foo'; 44 | }, 45 | aps : Array.prototype.slice 46 | }; 47 | var out = objectMerge(x, y, z); 48 | // out.a will be { 49 | // b : '``b' 50 | // } 51 | // out.b will be '`b' 52 | // out.c will be { 53 | // d : '`d', 54 | // e : 'e', 55 | // f : { 56 | // g : 'g' 57 | // } 58 | // } 59 | // out.fun will be a clone of z.fun 60 | // out.aps will be equal to z.aps 61 | ``` 62 | 63 | Merging arrays is not the same as `concat`. When they're merged the arrays are 64 | handled as objects. This means that indexes are object properties with numeric 65 | names. Merging `['a']` with `['b']` will give you `['b']` because the two 66 | arrays both have a property `0` and the last one in overrides the first. 67 | However, merging `arr1['a', 'b']` with `arr2[1] = 'override'` will give you 68 | `['a', 'override']` because `arr1` has properties `0` and `1`, while `arr2` 69 | only has the property `1` which overrides `arr1[1]` in the output. 70 | 71 | Merging functions will cause the output function to be a clone of the last 72 | function merged and it will have all the properties of the merged functions 73 | recursively merged together. So something like: 74 | 75 | ``` 76 | var func = function () { 77 | return null; 78 | }; 79 | var func2 = function () { 80 | return 'hello'; 81 | }; 82 | func.wohoo = 'wohoo'; 83 | func.obj = {a:'a'}; 84 | func2.wee = 'wee'; 85 | func2.obj = {b:'b'}; 86 | func2.obj2 = {a:'a'}; 87 | var out = objectMerge(func, func2); 88 | ``` 89 | 90 | will give you a function `out` that is a clone of `func2`'s function definition 91 | but has the properties: `wohoo`, `obj`, `wee`, and `obj2`. `out.obj` will have 92 | the properties `a` and `b` because the properties of `func` and `func2` are 93 | merged recursively. 94 | 95 | ### Options 96 | 97 | Options exist to do things like limit the depth of object traversal and disable 98 | errors on detection of circular references. In order to specify the options you 99 | must create an options object using the provided method `createOptions`, a 100 | normal object just won't work. 101 | 102 | ``` 103 | var objectMerge = require('object-merge'); 104 | var a = { 105 | 'a1' : { 106 | 'a2' : { 107 | 'a3' : {} 108 | } 109 | } 110 | }; 111 | var b = { 112 | 'b1' : { 113 | 'b2' : { 114 | 'b3' : {} 115 | } 116 | } 117 | }; 118 | var opts = objectMerge.createOptions({depth : 2}); 119 | var res = objectMerge(opts, a, b); 120 | // res will be 121 | // { 122 | // 'a1' : { 123 | // 'a2' : {} 124 | // }, 125 | // 'b1' : { 126 | // 'b2' : {} 127 | // } 128 | // } 129 | ``` 130 | 131 | See the tests in `browser/tests` for more examples and expected outputs. 132 | 133 | In the browser, include `./browser/object-merge_web.js` in your page. 134 | `objectMerge` will be available in your page. 135 | 136 | For full documentation see the docs folder. 137 | 138 | ## Tests 139 | 140 | Tests can be run from the root of this package with 141 | 142 | ``` 143 | npm test 144 | ``` 145 | 146 | There are also browser tests available in the `browser` directory. 147 | 148 | ## Hacking 149 | 150 | There are several other scripts listed in package.json for development and 151 | hacking on this module. They can be run with `npm run-script` followed by the 152 | scripts property corresponding to the script you want to run. For example, 153 | given a script called `buildDocs`, it could be run from the package root by: 154 | 155 | ``` 156 | npm run-script buildDocs 157 | ``` 158 | 159 | ## Author 160 | 161 | Matthew Kastor 162 | matthewkastor@gmail.com 163 | https://plus.google.com/100898583798552211130 164 | 165 | ## License 166 | 167 | gpl-3.0 168 | http://www.gnu.org/licenses/gpl-3.0-standalone.html -------------------------------------------------------------------------------- /browser/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | object-merge Demo 5 | 6 | 9 | 10 | 11 | 12 |

object-merge Demo 13 |

14 |

15 | open up the web condole and try it out. 16 |

17 | 18 | 19 | -------------------------------------------------------------------------------- /browser/jasmine/MIT.LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2011 Pivotal Labs 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /browser/jasmine/jasmine-html.js: -------------------------------------------------------------------------------- 1 | jasmine.HtmlReporterHelpers = {}; 2 | 3 | jasmine.HtmlReporterHelpers.createDom = function(type, attrs, childrenVarArgs) { 4 | var el = document.createElement(type); 5 | 6 | for (var i = 2; i < arguments.length; i++) { 7 | var child = arguments[i]; 8 | 9 | if (typeof child === 'string') { 10 | el.appendChild(document.createTextNode(child)); 11 | } else { 12 | if (child) { 13 | el.appendChild(child); 14 | } 15 | } 16 | } 17 | 18 | for (var attr in attrs) { 19 | if (attr == "className") { 20 | el[attr] = attrs[attr]; 21 | } else { 22 | el.setAttribute(attr, attrs[attr]); 23 | } 24 | } 25 | 26 | return el; 27 | }; 28 | 29 | jasmine.HtmlReporterHelpers.getSpecStatus = function(child) { 30 | var results = child.results(); 31 | var status = results.passed() ? 'passed' : 'failed'; 32 | if (results.skipped) { 33 | status = 'skipped'; 34 | } 35 | 36 | return status; 37 | }; 38 | 39 | jasmine.HtmlReporterHelpers.appendToSummary = function(child, childElement) { 40 | var parentDiv = this.dom.summary; 41 | var parentSuite = (typeof child.parentSuite == 'undefined') ? 'suite' : 'parentSuite'; 42 | var parent = child[parentSuite]; 43 | 44 | if (parent) { 45 | if (typeof this.views.suites[parent.id] == 'undefined') { 46 | this.views.suites[parent.id] = new jasmine.HtmlReporter.SuiteView(parent, this.dom, this.views); 47 | } 48 | parentDiv = this.views.suites[parent.id].element; 49 | } 50 | 51 | parentDiv.appendChild(childElement); 52 | }; 53 | 54 | 55 | jasmine.HtmlReporterHelpers.addHelpers = function(ctor) { 56 | for(var fn in jasmine.HtmlReporterHelpers) { 57 | ctor.prototype[fn] = jasmine.HtmlReporterHelpers[fn]; 58 | } 59 | }; 60 | 61 | jasmine.HtmlReporter = function(_doc) { 62 | var self = this; 63 | var doc = _doc || window.document; 64 | 65 | var reporterView; 66 | 67 | var dom = {}; 68 | 69 | // Jasmine Reporter Public Interface 70 | self.logRunningSpecs = false; 71 | 72 | self.reportRunnerStarting = function(runner) { 73 | var specs = runner.specs() || []; 74 | 75 | if (specs.length == 0) { 76 | return; 77 | } 78 | 79 | createReporterDom(runner.env.versionString()); 80 | doc.body.appendChild(dom.reporter); 81 | setExceptionHandling(); 82 | 83 | reporterView = new jasmine.HtmlReporter.ReporterView(dom); 84 | reporterView.addSpecs(specs, self.specFilter); 85 | }; 86 | 87 | self.reportRunnerResults = function(runner) { 88 | reporterView && reporterView.complete(); 89 | }; 90 | 91 | self.reportSuiteResults = function(suite) { 92 | reporterView.suiteComplete(suite); 93 | }; 94 | 95 | self.reportSpecStarting = function(spec) { 96 | if (self.logRunningSpecs) { 97 | self.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...'); 98 | } 99 | }; 100 | 101 | self.reportSpecResults = function(spec) { 102 | reporterView.specComplete(spec); 103 | }; 104 | 105 | self.log = function() { 106 | var console = jasmine.getGlobal().console; 107 | if (console && console.log) { 108 | if (console.log.apply) { 109 | console.log.apply(console, arguments); 110 | } else { 111 | console.log(arguments); // ie fix: console.log.apply doesn't exist on ie 112 | } 113 | } 114 | }; 115 | 116 | self.specFilter = function(spec) { 117 | if (!focusedSpecName()) { 118 | return true; 119 | } 120 | 121 | return spec.getFullName().indexOf(focusedSpecName()) === 0; 122 | }; 123 | 124 | return self; 125 | 126 | function focusedSpecName() { 127 | var specName; 128 | 129 | (function memoizeFocusedSpec() { 130 | if (specName) { 131 | return; 132 | } 133 | 134 | var paramMap = []; 135 | var params = jasmine.HtmlReporter.parameters(doc); 136 | 137 | for (var i = 0; i < params.length; i++) { 138 | var p = params[i].split('='); 139 | paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]); 140 | } 141 | 142 | specName = paramMap.spec; 143 | })(); 144 | 145 | return specName; 146 | } 147 | 148 | function createReporterDom(version) { 149 | dom.reporter = self.createDom('div', { id: 'HTMLReporter', className: 'jasmine_reporter' }, 150 | dom.banner = self.createDom('div', { className: 'banner' }, 151 | self.createDom('span', { className: 'title' }, "Jasmine "), 152 | self.createDom('span', { className: 'version' }, version)), 153 | 154 | dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}), 155 | dom.alert = self.createDom('div', {className: 'alert'}, 156 | self.createDom('span', { className: 'exceptions' }, 157 | self.createDom('label', { className: 'label', 'for': 'no_try_catch' }, 'No try/catch'), 158 | self.createDom('input', { id: 'no_try_catch', type: 'checkbox' }))), 159 | dom.results = self.createDom('div', {className: 'results'}, 160 | dom.summary = self.createDom('div', { className: 'summary' }), 161 | dom.details = self.createDom('div', { id: 'details' })) 162 | ); 163 | } 164 | 165 | function noTryCatch() { 166 | return window.location.search.match(/catch=false/); 167 | } 168 | 169 | function searchWithCatch() { 170 | var params = jasmine.HtmlReporter.parameters(window.document); 171 | var removed = false; 172 | var i = 0; 173 | 174 | while (!removed && i < params.length) { 175 | if (params[i].match(/catch=/)) { 176 | params.splice(i, 1); 177 | removed = true; 178 | } 179 | i++; 180 | } 181 | if (jasmine.CATCH_EXCEPTIONS) { 182 | params.push("catch=false"); 183 | } 184 | 185 | return params.join("&"); 186 | } 187 | 188 | function setExceptionHandling() { 189 | var chxCatch = document.getElementById('no_try_catch'); 190 | 191 | if (noTryCatch()) { 192 | chxCatch.setAttribute('checked', true); 193 | jasmine.CATCH_EXCEPTIONS = false; 194 | } 195 | chxCatch.onclick = function() { 196 | window.location.search = searchWithCatch(); 197 | }; 198 | } 199 | }; 200 | jasmine.HtmlReporter.parameters = function(doc) { 201 | var paramStr = doc.location.search.substring(1); 202 | var params = []; 203 | 204 | if (paramStr.length > 0) { 205 | params = paramStr.split('&'); 206 | } 207 | return params; 208 | } 209 | jasmine.HtmlReporter.sectionLink = function(sectionName) { 210 | var link = '?'; 211 | var params = []; 212 | 213 | if (sectionName) { 214 | params.push('spec=' + encodeURIComponent(sectionName)); 215 | } 216 | if (!jasmine.CATCH_EXCEPTIONS) { 217 | params.push("catch=false"); 218 | } 219 | if (params.length > 0) { 220 | link += params.join("&"); 221 | } 222 | 223 | return link; 224 | }; 225 | jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter); 226 | jasmine.HtmlReporter.ReporterView = function(dom) { 227 | this.startedAt = new Date(); 228 | this.runningSpecCount = 0; 229 | this.completeSpecCount = 0; 230 | this.passedCount = 0; 231 | this.failedCount = 0; 232 | this.skippedCount = 0; 233 | 234 | this.createResultsMenu = function() { 235 | this.resultsMenu = this.createDom('span', {className: 'resultsMenu bar'}, 236 | this.summaryMenuItem = this.createDom('a', {className: 'summaryMenuItem', href: "#"}, '0 specs'), 237 | ' | ', 238 | this.detailsMenuItem = this.createDom('a', {className: 'detailsMenuItem', href: "#"}, '0 failing')); 239 | 240 | this.summaryMenuItem.onclick = function() { 241 | dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, ''); 242 | }; 243 | 244 | this.detailsMenuItem.onclick = function() { 245 | showDetails(); 246 | }; 247 | }; 248 | 249 | this.addSpecs = function(specs, specFilter) { 250 | this.totalSpecCount = specs.length; 251 | 252 | this.views = { 253 | specs: {}, 254 | suites: {} 255 | }; 256 | 257 | for (var i = 0; i < specs.length; i++) { 258 | var spec = specs[i]; 259 | this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom, this.views); 260 | if (specFilter(spec)) { 261 | this.runningSpecCount++; 262 | } 263 | } 264 | }; 265 | 266 | this.specComplete = function(spec) { 267 | this.completeSpecCount++; 268 | 269 | if (isUndefined(this.views.specs[spec.id])) { 270 | this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom); 271 | } 272 | 273 | var specView = this.views.specs[spec.id]; 274 | 275 | switch (specView.status()) { 276 | case 'passed': 277 | this.passedCount++; 278 | break; 279 | 280 | case 'failed': 281 | this.failedCount++; 282 | break; 283 | 284 | case 'skipped': 285 | this.skippedCount++; 286 | break; 287 | } 288 | 289 | specView.refresh(); 290 | this.refresh(); 291 | }; 292 | 293 | this.suiteComplete = function(suite) { 294 | var suiteView = this.views.suites[suite.id]; 295 | if (isUndefined(suiteView)) { 296 | return; 297 | } 298 | suiteView.refresh(); 299 | }; 300 | 301 | this.refresh = function() { 302 | 303 | if (isUndefined(this.resultsMenu)) { 304 | this.createResultsMenu(); 305 | } 306 | 307 | // currently running UI 308 | if (isUndefined(this.runningAlert)) { 309 | this.runningAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "runningAlert bar" }); 310 | dom.alert.appendChild(this.runningAlert); 311 | } 312 | this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount); 313 | 314 | // skipped specs UI 315 | if (isUndefined(this.skippedAlert)) { 316 | this.skippedAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "skippedAlert bar" }); 317 | } 318 | 319 | this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all"; 320 | 321 | if (this.skippedCount === 1 && isDefined(dom.alert)) { 322 | dom.alert.appendChild(this.skippedAlert); 323 | } 324 | 325 | // passing specs UI 326 | if (isUndefined(this.passedAlert)) { 327 | this.passedAlert = this.createDom('span', { href: jasmine.HtmlReporter.sectionLink(), className: "passingAlert bar" }); 328 | } 329 | this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount); 330 | 331 | // failing specs UI 332 | if (isUndefined(this.failedAlert)) { 333 | this.failedAlert = this.createDom('span', {href: "?", className: "failingAlert bar"}); 334 | } 335 | this.failedAlert.innerHTML = "Failing " + specPluralizedFor(this.failedCount); 336 | 337 | if (this.failedCount === 1 && isDefined(dom.alert)) { 338 | dom.alert.appendChild(this.failedAlert); 339 | dom.alert.appendChild(this.resultsMenu); 340 | } 341 | 342 | // summary info 343 | this.summaryMenuItem.innerHTML = "" + specPluralizedFor(this.runningSpecCount); 344 | this.detailsMenuItem.innerHTML = "" + this.failedCount + " failing"; 345 | }; 346 | 347 | this.complete = function() { 348 | dom.alert.removeChild(this.runningAlert); 349 | 350 | this.skippedAlert.innerHTML = "Ran " + this.runningSpecCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all"; 351 | 352 | if (this.failedCount === 0) { 353 | dom.alert.appendChild(this.createDom('span', {className: 'passingAlert bar'}, "Passing " + specPluralizedFor(this.passedCount))); 354 | } else { 355 | showDetails(); 356 | } 357 | 358 | dom.banner.appendChild(this.createDom('span', {className: 'duration'}, "finished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s")); 359 | }; 360 | 361 | return this; 362 | 363 | function showDetails() { 364 | if (dom.reporter.className.search(/showDetails/) === -1) { 365 | dom.reporter.className += " showDetails"; 366 | } 367 | } 368 | 369 | function isUndefined(obj) { 370 | return typeof obj === 'undefined'; 371 | } 372 | 373 | function isDefined(obj) { 374 | return !isUndefined(obj); 375 | } 376 | 377 | function specPluralizedFor(count) { 378 | var str = count + " spec"; 379 | if (count > 1) { 380 | str += "s" 381 | } 382 | return str; 383 | } 384 | 385 | }; 386 | 387 | jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.ReporterView); 388 | 389 | 390 | jasmine.HtmlReporter.SpecView = function(spec, dom, views) { 391 | this.spec = spec; 392 | this.dom = dom; 393 | this.views = views; 394 | 395 | this.symbol = this.createDom('li', { className: 'pending' }); 396 | this.dom.symbolSummary.appendChild(this.symbol); 397 | 398 | this.summary = this.createDom('div', { className: 'specSummary' }, 399 | this.createDom('a', { 400 | className: 'description', 401 | href: jasmine.HtmlReporter.sectionLink(this.spec.getFullName()), 402 | title: this.spec.getFullName() 403 | }, this.spec.description) 404 | ); 405 | 406 | this.detail = this.createDom('div', { className: 'specDetail' }, 407 | this.createDom('a', { 408 | className: 'description', 409 | href: '?spec=' + encodeURIComponent(this.spec.getFullName()), 410 | title: this.spec.getFullName() 411 | }, this.spec.getFullName()) 412 | ); 413 | }; 414 | 415 | jasmine.HtmlReporter.SpecView.prototype.status = function() { 416 | return this.getSpecStatus(this.spec); 417 | }; 418 | 419 | jasmine.HtmlReporter.SpecView.prototype.refresh = function() { 420 | this.symbol.className = this.status(); 421 | 422 | switch (this.status()) { 423 | case 'skipped': 424 | break; 425 | 426 | case 'passed': 427 | this.appendSummaryToSuiteDiv(); 428 | break; 429 | 430 | case 'failed': 431 | this.appendSummaryToSuiteDiv(); 432 | this.appendFailureDetail(); 433 | break; 434 | } 435 | }; 436 | 437 | jasmine.HtmlReporter.SpecView.prototype.appendSummaryToSuiteDiv = function() { 438 | this.summary.className += ' ' + this.status(); 439 | this.appendToSummary(this.spec, this.summary); 440 | }; 441 | 442 | jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() { 443 | this.detail.className += ' ' + this.status(); 444 | 445 | var resultItems = this.spec.results().getItems(); 446 | var messagesDiv = this.createDom('div', { className: 'messages' }); 447 | 448 | for (var i = 0; i < resultItems.length; i++) { 449 | var result = resultItems[i]; 450 | 451 | if (result.type == 'log') { 452 | messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString())); 453 | } else if (result.type == 'expect' && result.passed && !result.passed()) { 454 | messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message)); 455 | 456 | if (result.trace.stack) { 457 | messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack)); 458 | } 459 | } 460 | } 461 | 462 | if (messagesDiv.childNodes.length > 0) { 463 | this.detail.appendChild(messagesDiv); 464 | this.dom.details.appendChild(this.detail); 465 | } 466 | }; 467 | 468 | jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);jasmine.HtmlReporter.SuiteView = function(suite, dom, views) { 469 | this.suite = suite; 470 | this.dom = dom; 471 | this.views = views; 472 | 473 | this.element = this.createDom('div', { className: 'suite' }, 474 | this.createDom('a', { className: 'description', href: jasmine.HtmlReporter.sectionLink(this.suite.getFullName()) }, this.suite.description) 475 | ); 476 | 477 | this.appendToSummary(this.suite, this.element); 478 | }; 479 | 480 | jasmine.HtmlReporter.SuiteView.prototype.status = function() { 481 | return this.getSpecStatus(this.suite); 482 | }; 483 | 484 | jasmine.HtmlReporter.SuiteView.prototype.refresh = function() { 485 | this.element.className += " " + this.status(); 486 | }; 487 | 488 | jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SuiteView); 489 | 490 | /* @deprecated Use jasmine.HtmlReporter instead 491 | */ 492 | jasmine.TrivialReporter = function(doc) { 493 | this.document = doc || document; 494 | this.suiteDivs = {}; 495 | this.logRunningSpecs = false; 496 | }; 497 | 498 | jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) { 499 | var el = document.createElement(type); 500 | 501 | for (var i = 2; i < arguments.length; i++) { 502 | var child = arguments[i]; 503 | 504 | if (typeof child === 'string') { 505 | el.appendChild(document.createTextNode(child)); 506 | } else { 507 | if (child) { el.appendChild(child); } 508 | } 509 | } 510 | 511 | for (var attr in attrs) { 512 | if (attr == "className") { 513 | el[attr] = attrs[attr]; 514 | } else { 515 | el.setAttribute(attr, attrs[attr]); 516 | } 517 | } 518 | 519 | return el; 520 | }; 521 | 522 | jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) { 523 | var showPassed, showSkipped; 524 | 525 | this.outerDiv = this.createDom('div', { id: 'TrivialReporter', className: 'jasmine_reporter' }, 526 | this.createDom('div', { className: 'banner' }, 527 | this.createDom('div', { className: 'logo' }, 528 | this.createDom('span', { className: 'title' }, "Jasmine"), 529 | this.createDom('span', { className: 'version' }, runner.env.versionString())), 530 | this.createDom('div', { className: 'options' }, 531 | "Show ", 532 | showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }), 533 | this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "), 534 | showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }), 535 | this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped") 536 | ) 537 | ), 538 | 539 | this.runnerDiv = this.createDom('div', { className: 'runner running' }, 540 | this.createDom('a', { className: 'run_spec', href: '?' }, "run all"), 541 | this.runnerMessageSpan = this.createDom('span', {}, "Running..."), 542 | this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, "")) 543 | ); 544 | 545 | this.document.body.appendChild(this.outerDiv); 546 | 547 | var suites = runner.suites(); 548 | for (var i = 0; i < suites.length; i++) { 549 | var suite = suites[i]; 550 | var suiteDiv = this.createDom('div', { className: 'suite' }, 551 | this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"), 552 | this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description)); 553 | this.suiteDivs[suite.id] = suiteDiv; 554 | var parentDiv = this.outerDiv; 555 | if (suite.parentSuite) { 556 | parentDiv = this.suiteDivs[suite.parentSuite.id]; 557 | } 558 | parentDiv.appendChild(suiteDiv); 559 | } 560 | 561 | this.startedAt = new Date(); 562 | 563 | var self = this; 564 | showPassed.onclick = function(evt) { 565 | if (showPassed.checked) { 566 | self.outerDiv.className += ' show-passed'; 567 | } else { 568 | self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, ''); 569 | } 570 | }; 571 | 572 | showSkipped.onclick = function(evt) { 573 | if (showSkipped.checked) { 574 | self.outerDiv.className += ' show-skipped'; 575 | } else { 576 | self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, ''); 577 | } 578 | }; 579 | }; 580 | 581 | jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) { 582 | var results = runner.results(); 583 | var className = (results.failedCount > 0) ? "runner failed" : "runner passed"; 584 | this.runnerDiv.setAttribute("class", className); 585 | //do it twice for IE 586 | this.runnerDiv.setAttribute("className", className); 587 | var specs = runner.specs(); 588 | var specCount = 0; 589 | for (var i = 0; i < specs.length; i++) { 590 | if (this.specFilter(specs[i])) { 591 | specCount++; 592 | } 593 | } 594 | var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s"); 595 | message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s"; 596 | this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild); 597 | 598 | this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString())); 599 | }; 600 | 601 | jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) { 602 | var results = suite.results(); 603 | var status = results.passed() ? 'passed' : 'failed'; 604 | if (results.totalCount === 0) { // todo: change this to check results.skipped 605 | status = 'skipped'; 606 | } 607 | this.suiteDivs[suite.id].className += " " + status; 608 | }; 609 | 610 | jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) { 611 | if (this.logRunningSpecs) { 612 | this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...'); 613 | } 614 | }; 615 | 616 | jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) { 617 | var results = spec.results(); 618 | var status = results.passed() ? 'passed' : 'failed'; 619 | if (results.skipped) { 620 | status = 'skipped'; 621 | } 622 | var specDiv = this.createDom('div', { className: 'spec ' + status }, 623 | this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"), 624 | this.createDom('a', { 625 | className: 'description', 626 | href: '?spec=' + encodeURIComponent(spec.getFullName()), 627 | title: spec.getFullName() 628 | }, spec.description)); 629 | 630 | 631 | var resultItems = results.getItems(); 632 | var messagesDiv = this.createDom('div', { className: 'messages' }); 633 | for (var i = 0; i < resultItems.length; i++) { 634 | var result = resultItems[i]; 635 | 636 | if (result.type == 'log') { 637 | messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString())); 638 | } else if (result.type == 'expect' && result.passed && !result.passed()) { 639 | messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message)); 640 | 641 | if (result.trace.stack) { 642 | messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack)); 643 | } 644 | } 645 | } 646 | 647 | if (messagesDiv.childNodes.length > 0) { 648 | specDiv.appendChild(messagesDiv); 649 | } 650 | 651 | this.suiteDivs[spec.suite.id].appendChild(specDiv); 652 | }; 653 | 654 | jasmine.TrivialReporter.prototype.log = function() { 655 | var console = jasmine.getGlobal().console; 656 | if (console && console.log) { 657 | if (console.log.apply) { 658 | console.log.apply(console, arguments); 659 | } else { 660 | console.log(arguments); // ie fix: console.log.apply doesn't exist on ie 661 | } 662 | } 663 | }; 664 | 665 | jasmine.TrivialReporter.prototype.getLocation = function() { 666 | return this.document.location; 667 | }; 668 | 669 | jasmine.TrivialReporter.prototype.specFilter = function(spec) { 670 | var paramMap = {}; 671 | var params = this.getLocation().search.substring(1).split('&'); 672 | for (var i = 0; i < params.length; i++) { 673 | var p = params[i].split('='); 674 | paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]); 675 | } 676 | 677 | if (!paramMap.spec) { 678 | return true; 679 | } 680 | return spec.getFullName().indexOf(paramMap.spec) === 0; 681 | }; 682 | -------------------------------------------------------------------------------- /browser/jasmine/jasmine.css: -------------------------------------------------------------------------------- 1 | body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; } 2 | 3 | #HTMLReporter { font-size: 11px; font-family: Monaco, "Lucida Console", monospace; line-height: 14px; color: #333333; } 4 | #HTMLReporter a { text-decoration: none; } 5 | #HTMLReporter a:hover { text-decoration: underline; } 6 | #HTMLReporter p, #HTMLReporter h1, #HTMLReporter h2, #HTMLReporter h3, #HTMLReporter h4, #HTMLReporter h5, #HTMLReporter h6 { margin: 0; line-height: 14px; } 7 | #HTMLReporter .banner, #HTMLReporter .symbolSummary, #HTMLReporter .summary, #HTMLReporter .resultMessage, #HTMLReporter .specDetail .description, #HTMLReporter .alert .bar, #HTMLReporter .stackTrace { padding-left: 9px; padding-right: 9px; } 8 | #HTMLReporter #jasmine_content { position: fixed; right: 100%; } 9 | #HTMLReporter .version { color: #aaaaaa; } 10 | #HTMLReporter .banner { margin-top: 14px; } 11 | #HTMLReporter .duration { color: #aaaaaa; float: right; } 12 | #HTMLReporter .symbolSummary { overflow: hidden; *zoom: 1; margin: 14px 0; } 13 | #HTMLReporter .symbolSummary li { display: block; float: left; height: 7px; width: 14px; margin-bottom: 7px; font-size: 16px; } 14 | #HTMLReporter .symbolSummary li.passed { font-size: 14px; } 15 | #HTMLReporter .symbolSummary li.passed:before { color: #5e7d00; content: "\02022"; } 16 | #HTMLReporter .symbolSummary li.failed { line-height: 9px; } 17 | #HTMLReporter .symbolSummary li.failed:before { color: #b03911; content: "x"; font-weight: bold; margin-left: -1px; } 18 | #HTMLReporter .symbolSummary li.skipped { font-size: 14px; } 19 | #HTMLReporter .symbolSummary li.skipped:before { color: #bababa; content: "\02022"; } 20 | #HTMLReporter .symbolSummary li.pending { line-height: 11px; } 21 | #HTMLReporter .symbolSummary li.pending:before { color: #aaaaaa; content: "-"; } 22 | #HTMLReporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; } 23 | #HTMLReporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; } 24 | #HTMLReporter .runningAlert { background-color: #666666; } 25 | #HTMLReporter .skippedAlert { background-color: #aaaaaa; } 26 | #HTMLReporter .skippedAlert:first-child { background-color: #333333; } 27 | #HTMLReporter .skippedAlert:hover { text-decoration: none; color: white; text-decoration: underline; } 28 | #HTMLReporter .passingAlert { background-color: #a6b779; } 29 | #HTMLReporter .passingAlert:first-child { background-color: #5e7d00; } 30 | #HTMLReporter .failingAlert { background-color: #cf867e; } 31 | #HTMLReporter .failingAlert:first-child { background-color: #b03911; } 32 | #HTMLReporter .results { margin-top: 14px; } 33 | #HTMLReporter #details { display: none; } 34 | #HTMLReporter .resultsMenu, #HTMLReporter .resultsMenu a { background-color: #fff; color: #333333; } 35 | #HTMLReporter.showDetails .summaryMenuItem { font-weight: normal; text-decoration: inherit; } 36 | #HTMLReporter.showDetails .summaryMenuItem:hover { text-decoration: underline; } 37 | #HTMLReporter.showDetails .detailsMenuItem { font-weight: bold; text-decoration: underline; } 38 | #HTMLReporter.showDetails .summary { display: none; } 39 | #HTMLReporter.showDetails #details { display: block; } 40 | #HTMLReporter .summaryMenuItem { font-weight: bold; text-decoration: underline; } 41 | #HTMLReporter .summary { margin-top: 14px; } 42 | #HTMLReporter .summary .suite .suite, #HTMLReporter .summary .specSummary { margin-left: 14px; } 43 | #HTMLReporter .summary .specSummary.passed a { color: #5e7d00; } 44 | #HTMLReporter .summary .specSummary.failed a { color: #b03911; } 45 | #HTMLReporter .description + .suite { margin-top: 0; } 46 | #HTMLReporter .suite { margin-top: 14px; } 47 | #HTMLReporter .suite a { color: #333333; } 48 | #HTMLReporter #details .specDetail { margin-bottom: 28px; } 49 | #HTMLReporter #details .specDetail .description { display: block; color: white; background-color: #b03911; } 50 | #HTMLReporter .resultMessage { padding-top: 14px; color: #333333; } 51 | #HTMLReporter .resultMessage span.result { display: block; } 52 | #HTMLReporter .stackTrace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #ddd; background: white; white-space: pre; } 53 | 54 | #TrivialReporter { padding: 8px 13px; position: absolute; top: 0; bottom: 0; left: 0; right: 0; overflow-y: scroll; background-color: white; font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif; /*.resultMessage {*/ /*white-space: pre;*/ /*}*/ } 55 | #TrivialReporter a:visited, #TrivialReporter a { color: #303; } 56 | #TrivialReporter a:hover, #TrivialReporter a:active { color: blue; } 57 | #TrivialReporter .run_spec { float: right; padding-right: 5px; font-size: .8em; text-decoration: none; } 58 | #TrivialReporter .banner { color: #303; background-color: #fef; padding: 5px; } 59 | #TrivialReporter .logo { float: left; font-size: 1.1em; padding-left: 5px; } 60 | #TrivialReporter .logo .version { font-size: .6em; padding-left: 1em; } 61 | #TrivialReporter .runner.running { background-color: yellow; } 62 | #TrivialReporter .options { text-align: right; font-size: .8em; } 63 | #TrivialReporter .suite { border: 1px outset gray; margin: 5px 0; padding-left: 1em; } 64 | #TrivialReporter .suite .suite { margin: 5px; } 65 | #TrivialReporter .suite.passed { background-color: #dfd; } 66 | #TrivialReporter .suite.failed { background-color: #fdd; } 67 | #TrivialReporter .spec { margin: 5px; padding-left: 1em; clear: both; } 68 | #TrivialReporter .spec.failed, #TrivialReporter .spec.passed, #TrivialReporter .spec.skipped { padding-bottom: 5px; border: 1px solid gray; } 69 | #TrivialReporter .spec.failed { background-color: #fbb; border-color: red; } 70 | #TrivialReporter .spec.passed { background-color: #bfb; border-color: green; } 71 | #TrivialReporter .spec.skipped { background-color: #bbb; } 72 | #TrivialReporter .messages { border-left: 1px dashed gray; padding-left: 1em; padding-right: 1em; } 73 | #TrivialReporter .passed { background-color: #cfc; display: none; } 74 | #TrivialReporter .failed { background-color: #fbb; } 75 | #TrivialReporter .skipped { color: #777; background-color: #eee; display: none; } 76 | #TrivialReporter .resultMessage span.result { display: block; line-height: 2em; color: black; } 77 | #TrivialReporter .resultMessage .mismatch { color: black; } 78 | #TrivialReporter .stackTrace { white-space: pre; font-size: .8em; margin-left: 10px; max-height: 5em; overflow: auto; border: 1px inset red; padding: 1em; background: #eef; } 79 | #TrivialReporter .finished-at { padding-left: 1em; font-size: .6em; } 80 | #TrivialReporter.show-passed .passed, #TrivialReporter.show-skipped .skipped { display: block; } 81 | #TrivialReporter #jasmine_content { position: fixed; right: 100%; } 82 | #TrivialReporter .runner { border: 1px solid gray; display: block; margin: 5px 0; padding: 2px 0 2px 10px; } 83 | -------------------------------------------------------------------------------- /browser/object-merge_tests.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | object-merge test suite 6 | 7 | 10 | 13 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 28 | 29 | 30 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /browser/object-merge_web.js: -------------------------------------------------------------------------------- 1 | (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;iMatthew Kastor 16 | * @param {Function} func The function to clone. 17 | * @returns {Function} Returns a clone of the non native function, or a 18 | * reference to the native function. 19 | */ 20 | function cloneFunction(func) { 21 | var out, str; 22 | try { 23 | str = func.toString(); 24 | if (/\[native code\]/.test(str)) { 25 | out = func; 26 | } else { 27 | out = eval('(function(){return ' + str + '}());'); 28 | } 29 | } catch (e) { 30 | throw new Error(e.message + '\r\n\r\n' + str); 31 | } 32 | return out; 33 | } 34 | module.exports = cloneFunction; 35 | },{}],3:[function(require,module,exports){ 36 | /** 37 | * Executes a function on each of an objects own enumerable properties. The 38 | * callback function will receive three arguments: the value of the current 39 | * property, the name of the property, and the object being processed. This is 40 | * roughly equivalent to the signature for callbacks to 41 | * Array.prototype.forEach. 42 | * @param {Object} obj The object to act on. 43 | * @param {Function} callback The function to execute. 44 | * @returns {Object} Returns the given object. 45 | */ 46 | function objectForeach(obj, callback) { 47 | "use strict"; 48 | Object.keys(obj).forEach(function (prop) { 49 | callback(obj[prop], prop, obj); 50 | }); 51 | return obj; 52 | }; 53 | module.exports = objectForeach; 54 | },{}],4:[function(require,module,exports){ 55 | /* 56 | License gpl-3.0 http://www.gnu.org/licenses/gpl-3.0-standalone.html 57 | */ 58 | /*jslint 59 | white: true, 60 | vars: true, 61 | node: true 62 | */ 63 | function ObjectMergeOptions(opts) { 64 | 'use strict'; 65 | opts = opts || {}; 66 | this.depth = opts.depth || false; 67 | // circular ref check is true unless explicitly set to false 68 | // ignore the jslint warning here, it's pointless. 69 | this.throwOnCircularRef = 'throwOnCircularRef' in opts && opts.throwOnCircularRef === false ? false : true; 70 | } 71 | /*jslint unparam:true*/ 72 | /** 73 | * Creates a new options object suitable for use with objectMerge. 74 | * @memberOf objectMerge 75 | * @param {Object} [opts] An object specifying the options. 76 | * @param {Object} [opts.depth = false] Specifies the depth to traverse objects 77 | * during merging. If this is set to false then there will be no depth limit. 78 | * @param {Object} [opts.throwOnCircularRef = true] Set to false to suppress 79 | * errors on circular references. 80 | * @returns {ObjectMergeOptions} Returns an instance of ObjectMergeOptions 81 | * to be used with objectMerge. 82 | * @example 83 | * var opts = objectMerge.createOptions({ 84 | * depth : 2, 85 | * throwOnCircularRef : false 86 | * }); 87 | * var obj1 = { 88 | * a1 : { 89 | * a2 : { 90 | * a3 : {} 91 | * } 92 | * } 93 | * }; 94 | * var obj2 = { 95 | * a1 : { 96 | * a2 : { 97 | * a3 : 'will not be in output' 98 | * }, 99 | * a22 : {} 100 | * } 101 | * }; 102 | * objectMerge(opts, obj1, obj2); 103 | */ 104 | function createOptions(opts) { 105 | 'use strict'; 106 | var argz = Array.prototype.slice.call(arguments, 0); 107 | argz.unshift(null); 108 | var F = ObjectMergeOptions.bind.apply(ObjectMergeOptions, argz); 109 | return new F(); 110 | } 111 | /*jslint unparam:false*/ 112 | /** 113 | * Merges JavaScript objects recursively without altering the objects merged. 114 | * @namespace Merges JavaScript objects recursively without altering the objects merged. 115 | * @author Matthew Kastor 116 | * @param {ObjectMergeOptions} [opts] An options object created by 117 | * objectMerge.createOptions. Options must be specified as the first argument 118 | * and must be an object created with createOptions or else the object will 119 | * not be recognized as an options object and will be merged instead. 120 | * @param {Object} shadows [[shadows]...] One or more objects to merge. Each 121 | * argument given will be treated as an object to merge. Each object 122 | * overwrites the previous objects descendant properties if the property name 123 | * matches. If objects properties are objects they will be merged recursively 124 | * as well. 125 | * @returns {Object} Returns a single merged object composed from clones of the 126 | * input objects. 127 | * @example 128 | * var objectMerge = require('object-merge'); 129 | * var x = { 130 | * a : 'a', 131 | * b : 'b', 132 | * c : { 133 | * d : 'd', 134 | * e : 'e', 135 | * f : { 136 | * g : 'g' 137 | * } 138 | * } 139 | * }; 140 | * var y = { 141 | * a : '`a', 142 | * b : '`b', 143 | * c : { 144 | * d : '`d' 145 | * } 146 | * }; 147 | * var z = { 148 | * a : { 149 | * b : '``b' 150 | * }, 151 | * fun : function foo () { 152 | * return 'foo'; 153 | * }, 154 | * aps : Array.prototype.slice 155 | * }; 156 | * var out = objectMerge(x, y, z); 157 | * // out.a will be { 158 | * // b : '``b' 159 | * // } 160 | * // out.b will be '`b' 161 | * // out.c will be { 162 | * // d : '`d', 163 | * // e : 'e', 164 | * // f : { 165 | * // g : 'g' 166 | * // } 167 | * // } 168 | * // out.fun will be a clone of z.fun 169 | * // out.aps will be equal to z.aps 170 | */ 171 | function objectMerge(shadows) { 172 | 'use strict'; 173 | var objectForeach = require('object-foreach'); 174 | var cloneFunction = require('clone-function'); 175 | // this is the queue of visited objects / properties. 176 | var visited = []; 177 | // various merge options 178 | var options = {}; 179 | // gets the sequential trailing objects from array. 180 | function getShadowObjects(shadows) { 181 | var out = shadows.reduce(function (collector, shadow) { 182 | if (shadow instanceof Object) { 183 | collector.push(shadow); 184 | } else { 185 | collector = []; 186 | } 187 | return collector; 188 | }, []); 189 | return out; 190 | } 191 | // gets either a new object of the proper type or the last primitive value 192 | function getOutputObject(shadows) { 193 | var out; 194 | var lastShadow = shadows[shadows.length - 1]; 195 | if (lastShadow instanceof Array) { 196 | out = []; 197 | } else if (lastShadow instanceof Function) { 198 | try { 199 | out = cloneFunction(lastShadow); 200 | } catch (e) { 201 | throw new Error(e.message); 202 | } 203 | } else if (lastShadow instanceof Object) { 204 | out = {}; 205 | } else { 206 | // lastShadow is a primitive value; 207 | out = lastShadow; 208 | } 209 | return out; 210 | } 211 | // checks for circular references 212 | function circularReferenceCheck(shadows) { 213 | // if any of the current objects to process exist in the queue 214 | // then throw an error. 215 | shadows.forEach(function (item) { 216 | if (item instanceof Object && visited.indexOf(item) > -1) { 217 | throw new Error('Circular reference error'); 218 | } 219 | }); 220 | // if none of the current objects were in the queue 221 | // then add references to the queue. 222 | visited = visited.concat(shadows); 223 | } 224 | function objectMergeRecursor(shadows, currentDepth) { 225 | if (options.depth !== false) { 226 | currentDepth = currentDepth ? currentDepth + 1 : 1; 227 | } else { 228 | currentDepth = 0; 229 | } 230 | if (options.throwOnCircularRef === true) { 231 | circularReferenceCheck(shadows); 232 | } 233 | var out = getOutputObject(shadows); 234 | /*jslint unparam: true */ 235 | function shadowHandler(val, prop, shadow) { 236 | if (out[prop]) { 237 | out[prop] = objectMergeRecursor([ 238 | out[prop], 239 | shadow[prop] 240 | ], currentDepth); 241 | } else { 242 | out[prop] = objectMergeRecursor([shadow[prop]], currentDepth); 243 | } 244 | } 245 | /*jslint unparam:false */ 246 | function shadowMerger(shadow) { 247 | objectForeach(shadow, shadowHandler); 248 | } 249 | // short circuits case where output would be a primitive value 250 | // anyway. 251 | if (out instanceof Object && currentDepth <= options.depth) { 252 | // only merges trailing objects since primitives would wipe out 253 | // previous objects, as in merging {a:'a'}, 'a', and {b:'b'} 254 | // would result in {b:'b'} so the first two arguments 255 | // can be ignored completely. 256 | var relevantShadows = getShadowObjects(shadows); 257 | relevantShadows.forEach(shadowMerger); 258 | } 259 | return out; 260 | } 261 | // determines whether an options object was passed in and 262 | // uses it if present 263 | // ignore the jslint warning here too. 264 | if (arguments[0] instanceof ObjectMergeOptions) { 265 | options = arguments[0]; 266 | shadows = Array.prototype.slice.call(arguments, 1); 267 | } else { 268 | options = createOptions(); 269 | shadows = Array.prototype.slice.call(arguments, 0); 270 | } 271 | return objectMergeRecursor(shadows); 272 | } 273 | objectMerge.createOptions = createOptions; 274 | module.exports = objectMerge; 275 | },{"clone-function":2,"object-foreach":3}]},{},[1]) 276 | //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJkZXYvYnJvd3Nlck1haW4uanMiLCJub2RlX21vZHVsZXMvY2xvbmUtZnVuY3Rpb24vc3JjL2Nsb25lLWZ1bmN0aW9uLmpzIiwibm9kZV9tb2R1bGVzL29iamVjdC1mb3JlYWNoL3NyYy9vYmplY3QtZm9yZWFjaC5qcyIsInNyYy9vYmplY3QtbWVyZ2UuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7QUNBQTtBQUNBOztBQ0RBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTs7QUM3QkE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBOztBQ2pCQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQ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XHJcbiAqICB2YXIgeSA9IHtcclxuICogICAgICBhIDogJ2BhJyxcclxuICogICAgICBiIDogJ2BiJyxcclxuICogICAgICBjIDoge1xyXG4gKiAgICAgICAgICBkIDogJ2BkJ1xyXG4gKiAgICAgIH1cclxuICogIH07XHJcbiAqICB2YXIgeiA9IHtcclxuICogICAgICBhIDoge1xyXG4gKiAgICAgICAgICBiIDogJ2BgYidcclxuICogICAgICB9LFxyXG4gKiAgICAgIGZ1biA6IGZ1bmN0aW9uIGZvbyAoKSB7XHJcbiAqICAgICAgICAgIHJldHVybiAnZm9vJztcclxuICogICAgICB9LFxyXG4gKiAgICAgIGFwcyA6IEFycmF5LnByb3RvdHlwZS5zbGljZVxyXG4gKiAgfTtcclxuICogIHZhciBvdXQgPSBvYmplY3RNZXJnZSh4LCB5LCB6KTtcclxuICogIC8vIG91dC5hIHdpbGwgYmUge1xyXG4gKiAgLy8gICAgICAgICBiIDogJ2BgYidcclxuICogIC8vICAgICB9XHJcbiAqICAvLyBvdXQuYiB3aWxsIGJlICdgYidcclxuICogIC8vIG91dC5jIHdpbGwgYmUge1xyXG4gKiAgLy8gICAgICAgICBkIDogJ2BkJyxcclxuICogIC8vICAgICAgICAgZSA6ICdlJyxcclxuICogIC8vICAgICAgICAgZiA6IHtcclxuICogIC8vICAgICAgICAgICAgIGcgOiAnZydcclxuICogIC8vICAgICAgICAgfVxyXG4gKiAgLy8gICAgIH1cclxuICogIC8vIG91dC5mdW4gd2lsbCBiZSBhIGNsb25lIG9mIHouZnVuXHJcbiAqICAvLyBvdXQuYXBzIHdpbGwgYmUgZXF1YWwgdG8gei5hcHNcclxuICovXHJcbmZ1bmN0aW9uIG9iamVjdE1lcmdlKHNoYWRvd3MpIHtcclxuICAgICd1c2Ugc3RyaWN0JztcclxuICAgIHZhciBvYmplY3RGb3JlYWNoID0gcmVxdWlyZSgnb2JqZWN0LWZvcmVhY2gnKTtcclxuICAgIHZhciBjbG9uZUZ1bmN0aW9uID0gcmVxdWlyZS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TaGFkb3cgaW5zdGFuY2VvZiBBcnJheSkge1xyXG4gICAgICAgICAgICBvdXQgPSBbXTtcclxuICAgICAgICB9IGVsc2UgaWYgKGxhc3RTaGFkb3cgaW5zdGFuY2VvZiBGdW5jdGlvbikge1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgb3V0ID0gY2xvbmVGdW5jdGlvbihsYXN0U2hhZG93KTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGUubWVzc2FnZSk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9IGVsc2UgaWYgKGxhc3RTaGFkb3cgaW5zdGFuY2VvZiBPYmplY3QpIHtcclxuICAgICAgICAgICAgb3V0ID0ge307XHJcbiAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgLy8gbGFzdFNoYWRvdyBpcyBhIHByaW1pdGl2ZSB2YWx1ZTtcclxuICAgICAgICAgICAgb3V0ID0gbGFzdFNoYWRvdztcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIG91dDtcclxuICAgIH1cclxuICAgIC8vIGNoZWNrcyBmb3IgY2lyY3VsYXIgcmVmZXJlbmNlc1xyXG4gICAgZnVuY3Rpb24gY2lyY3VsYXJSZWZlcmVuY2VDaGVjayhzaGFkb3dzKSB7XHJcbiAgICAgICAgLy8gaWYgYW55IG9mIHRoZSBjdXJyZW50IG9iamVjdHMgdG8gcHJvY2VzcyBleGlzdCBpbiB0aGUgcXVldWVcclxuICAgICAgICAvLyB0aGVuIHRocm93IGFuIGVycm9yLlxyXG4gICAgICAgIHNoYWRvd3MuZm9yRWFjaChmdW5jdGlvbiAoaXRlbSkge1xyXG4gICAgICAgICAgICBpZiAoaXRlbSBpbnN0YW5jZW9mIE9iamVjdCAmJiB2aXNpdGVkLmluZGV4T2YoaXRlbSkgPiAtMSkge1xyXG4gICAgICAgICAgICAgICAgdGhyb3cgbm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dFtwcm9wXSxcclxuICAgICAgICAgICAgICAgICAgICBzaGFkb3dbcHJvcF1cclxuICAgICAgICAgICAgICAgIF0sIGN1cnJlbnREZXB0aCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICBvdXRbcHJvcF0gPSBvYmplY3RNZXJnZVJlY3Vyc29yKFtzaGFkb3dbcHJvcF1dLCBjdXJyZW50RGVwdGgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgICAgIC8qanNsaW50IHVucGFyYW06ZmFsc2UgKi9cclxuICAgICAgICBmdW5jdGlvbiBzaGFkb3dNZXJnZXIoc2hhZG93KSB7XHJcbiAgICAgICAgICAgIG9iamVjdEZvcmVhY2goc2hhZG93LCBzaGFkb3dIYW5kbGVyKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgLy8gc2hvcnQgY2lyY3VpdHMgY2FzZSB3aGVyZSBvdXRwdXQgd291bGQgYmUgYSBwcmltaXRpdmUgdmFsdWVcclxuICAgICAgICAvLyBhbnl3YXkuXHJcbiAgICAgICAgaWYgKG91dCBpbnN0YW5jZW9mIE9iamVjdCAmJiBjdXJyZW50RGVwdGggPD0gb3B0aW9ucy5kZXB0aCkge1xyXG4gICAgICAgICAgICAvLyBvbmx5IG1lcmdlcyB0cmFpbGluZyBvYmplY3RzIHNpbmNlIHByaW1pdGl2ZXMgd291bGQgd2lwZSBvdXRcclxuICAgICAgICAgICAgLy8gcHJldmlvdXMgb2JqZWN0cywgYXMgaW4gbWVyZ2luZyB7YTonYSd9LCAnYScsIGFuZCB7YjonYid9XHJcbiAgICAgICAgICAgIC8vIHdvdWxkIHJlc3VsdCBpbiB7YjonYid9IHNvIHRoZSBmaXJzdCB0d28gYXJndW1lbnRzXHJcbiAgICAgICAgICAgIC8vIGNhbiBiZSBpZ25vcmVkIGNvbXBsZXRlbHkuXHJcbiAgICAgICAgICAgIHZhciByZWxldmFudFNoYWRvd3MgPSBnZXRTaGFkb3dPYmplY3RzKHNoYWRvd3MpO1xyXG4gICAgICAgICAgICByZWxldmFudFNoYWRvd3MuZm9yRWFjaChzaGFkb3dNZXJnZXIpO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gb3V0O1xyXG4gICAgfVxyXG4gICAgLy8gZGV0ZXJtaW5lcyB3aGV0aGVyIGFuIG9wdGlvbnMgb2JqZWN0IHdhcyBwYXNzZWQgaW4gYW5kXHJcbiAgICAvLyB1c2VzIGl0IGlmIHByZXNlbnRcclxuICAgIC8vIGlnbm9yZSB0aGUganNsaW50IHdhcm5pbmcgaGVyZSB0b28uXHJcbiAgICBpZiAoYXJndW1lbnRzWzBdIGluc3RhbmNlb2YgT2JqZWN0TWVyZ2VPcHRpb25zKSB7XHJcbiAgICAgICAgb3B0aW9ucyA9IGFyZ3VtZW50c1swXTtcclxuICAgICAgICBzaGFkb3dzID0gQXJyYXkucHJvdG90eXBlLnNsaWNlLmNhbGwoYXJndW1lbnRzLCAxKTtcclxuICAgIH0gZWxzZSB7XHJcbiAgICAgICAgb3B0aW9ucyA9IGNyZWF0ZU9wdGlvbnMoKTtcclxuICAgICAgICBzaGFkb3dzID0gQXJyYXkucHJvdG90eXBlLnNsaWNlLmNhbGwoYXJndW1lbnRzLCAwKTtcclxuICAgIH1cclxuICAgIHJldHVybiBvYmplY3RNZXJnZVJlY3Vyc29yKHNoYWRvd3MpO1xyXG59XHJcbm9iamVjdE1lcmdlLmNyZWF0ZU9wdGlvbnMgPSBjcmVhdGVPcHRpb25zO1xyXG5tb2R1bGUuZXhwb3J0cyA9IG9iamVjdE1lcmdlOyJdfQ== 277 | -------------------------------------------------------------------------------- /browser/tests/object-merge.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | License gpl-3.0 http://www.gnu.org/licenses/gpl-3.0-standalone.html 3 | */ 4 | describe('createOptions', function () { 5 | it('creates an options object with defaults for unspecified values', 6 | function () { 7 | var opts = objectMerge.createOptions(); 8 | expect(opts).toEqual({ 9 | depth : false, 10 | throwOnCircularRef : true 11 | }); 12 | } 13 | ); 14 | it('creates an options object with user specified values', 15 | function () { 16 | var opts = objectMerge.createOptions({ 17 | depth : 9, 18 | throwOnCircularRef : false 19 | }); 20 | expect(opts).toEqual({ 21 | depth : 9, 22 | throwOnCircularRef : false 23 | }); 24 | } 25 | ); 26 | }); 27 | describe('object-merge', function () { 28 | var w = { 29 | a : [ 30 | {b : 'b'}, 31 | {c : 'c'} 32 | ] 33 | }; 34 | var x = { 35 | a : 'a', 36 | b : 'b', 37 | c : { 38 | d : 'd', 39 | e : 'e', 40 | f : { 41 | g : 'g' 42 | } 43 | } 44 | }; 45 | var y = { 46 | a : '`a', 47 | b : '`b', 48 | c : { 49 | d : '`d' 50 | } 51 | }; 52 | var z = { 53 | a : { 54 | b : '``b' 55 | }, 56 | fun : function foo () { 57 | return 'foo'; 58 | }, 59 | aps : Array.prototype.slice 60 | }; 61 | 62 | it('clones non native functions', function () { 63 | var out = objectMerge(x, y, z); 64 | expect(out.fun()).toEqual(z.fun()); 65 | expect(z.fun).not.toEqual(out.fun); 66 | }); 67 | it('clones function properties', function () { 68 | var func = function () { 69 | return null; 70 | }; 71 | var func2 = function () { 72 | return 'hello'; 73 | }; 74 | func.wohoo = 'wohoo'; 75 | func.obj = {a:'a'}; 76 | func2.wee = 'wee'; 77 | func2.obj = {b:'b'}; 78 | func2.obj2 = {a:'a'}; 79 | var out = objectMerge(func, func2); 80 | expect(out.wohoo).toEqual('wohoo'); 81 | expect(out.wee).toEqual('wee'); 82 | expect(out.obj.a).toEqual('a'); 83 | expect(out.obj.b).toEqual('b'); 84 | expect(out.obj2.a).toEqual('a'); 85 | expect(out.obj === func.obj).toEqual(false); 86 | expect(out.obj2 === func2.obj2).toEqual(false); 87 | expect(out() === 'hello').toEqual(true); 88 | }); 89 | it('references native functions', function () { 90 | var out = objectMerge(x, y, z); 91 | expect(out.aps(['a'],0)).toEqual(z.aps(['a'],0)) 92 | expect(out.aps).toEqual(z.aps); 93 | }); 94 | it('preserves array indexes', function () { 95 | var arr = []; 96 | arr[0] = '0'; 97 | arr[5] = '5'; 98 | var obj = { 99 | '0' : '1', 100 | '1' : '1' 101 | }; 102 | var out = objectMerge(obj, arr); 103 | expect(arr.length).toEqual(6); 104 | expect(out.length).toEqual(6); 105 | expect(arr[0]).toEqual(out[0]); 106 | expect(obj[1]).toEqual(out[1]); 107 | expect(out[5]).toEqual(arr[5]); 108 | expect(out instanceof Array).toEqual(true); 109 | }); 110 | it('clones array properties', function () { 111 | var arr = []; 112 | arr[0] = '0'; 113 | var obj = { 114 | 'wee' : 'wee', 115 | 'wohoo' : 'wohoo', 116 | 'obj' : {} 117 | }; 118 | var out = objectMerge(obj, arr); 119 | expect(arr.length).toEqual(out.length); 120 | expect(arr[0]).toEqual(out[0]); 121 | expect(out.wee).toEqual(obj.wee); 122 | expect(arr.wee === undefined).toEqual(true); 123 | expect(out.wohoo).toEqual(obj.wohoo); 124 | expect(out instanceof Array).toEqual(true); 125 | expect(out.obj).toEqual({}); 126 | expect(out.obj === obj.obj).toEqual(false); 127 | }); 128 | it('merges arrays', function () { 129 | var arr1 = ['0','1','2']; 130 | var arr2 = []; 131 | arr2[2] = '`2'; 132 | arr2[3] = '`3'; 133 | var out = objectMerge(arr1, arr2); 134 | expect(arr1.length).toEqual(3); 135 | expect(arr2.length).toEqual(4); 136 | expect(out.length).toEqual(4); 137 | expect(arr1).toEqual(['0','1','2']); 138 | expect(arr2).toEqual([undefined, undefined, '`2','`3']); 139 | expect(out).toEqual(['0','1','`2','`3']); 140 | }); 141 | it('clones array contents', function () { 142 | var out = objectMerge(x, w); 143 | expect(out.a instanceof Array).toEqual(true); 144 | expect(out.a === w.a).toEqual(false); 145 | expect(out.a[0] === w.a[0]).toEqual(false); 146 | expect(out.a[1] === w.a[1]).toEqual(false); 147 | expect(out.a[0].b === w.a[0].b).toEqual(true); 148 | expect(out.a[0].c === w.a[0].c).toEqual(true); 149 | expect(out.a[1].b === w.a[1].b).toEqual(true); 150 | expect(out.a[1].c === w.a[1].c).toEqual(true); 151 | }); 152 | it('merges all objects recursively', function () { 153 | var out = objectMerge(x, y, z); 154 | expect(out.a === z.a).toEqual(false); 155 | expect(out.a).toEqual({'b' : '``b'}); 156 | expect(out.b).toEqual('`b'); 157 | expect(out.c).toEqual({ 158 | 'd' : '`d', 159 | 'e' : 'e', 160 | 'f' : { 161 | 'g' : 'g' 162 | } 163 | }); 164 | expect(out.fun).not.toEqual(z.fun); 165 | expect(out.fun()).toEqual(z.fun()); 166 | expect(out.aps).toEqual(z.aps); 167 | out.c = {a:'wee'}; 168 | expect(out.c.a == 'wee').toEqual(true); 169 | expect(x.c.a == 'wee').toEqual(false); 170 | expect(y.c.a == 'wee').toEqual(false); 171 | }); 172 | it('throws an error on circular references to functions', function () { 173 | var x = { 174 | 'a' : function () {return null}, 175 | }; 176 | x.b = x.a; 177 | function thrower () { 178 | return objectMerge(x); 179 | } 180 | expect(thrower).toThrow(); 181 | }); 182 | it('throws an error on circular references to arrays', function () { 183 | var x = { 184 | 'a' : [], 185 | }; 186 | x.b = x.a; 187 | function thrower () { 188 | return objectMerge(x); 189 | } 190 | expect(thrower).toThrow(); 191 | }); 192 | it('throws an error on circular references to objects', function () { 193 | var x = { 194 | 'a' : {} 195 | }; 196 | x.b = x.a; 197 | function thrower () { 198 | return objectMerge(x); 199 | } 200 | expect(thrower).toThrow(); 201 | }); 202 | it('throws an error on circular references to nested objects', function () { 203 | var x = { 204 | 'a' : {} 205 | }; 206 | x.b = {}; 207 | x.b.c = x.a; 208 | function thrower () { 209 | return objectMerge(x); 210 | } 211 | expect(thrower).toThrow(); 212 | }); 213 | it('throws an error on circular references to string objects', function () { 214 | var x = { 215 | 'a' : new String(), 216 | }; 217 | x.b = x.a; 218 | function thrower () { 219 | return objectMerge(x); 220 | } 221 | expect(thrower).toThrow(); 222 | }); 223 | it('throws an error on circular references to number objects', function () { 224 | var x = { 225 | 'a' : new Number(), 226 | }; 227 | x.b = x.a; 228 | function thrower () { 229 | return objectMerge(x); 230 | } 231 | expect(thrower).toThrow(); 232 | }); 233 | it('does not throw an error on circular references to scalar string', 234 | function () { 235 | var x = { 236 | 'a' : 'x', 237 | }; 238 | x.b = x.a; 239 | function thrower () { 240 | return objectMerge(x); 241 | } 242 | expect(thrower).not.toThrow(); 243 | } 244 | ); 245 | it('does not throw an error on circular references to scalar number', 246 | function () { 247 | var x = { 248 | 'a' : 5, 249 | }; 250 | x.b = x.a; 251 | function thrower () { 252 | return objectMerge(x); 253 | } 254 | expect(thrower).not.toThrow(); 255 | } 256 | ); 257 | it('allows circular reference check to be disabled', function () { 258 | var x = { 259 | 'a' : {} 260 | }; 261 | x.b = x.a; 262 | function thrower () { 263 | var opts = objectMerge.createOptions({throwOnCircularRef : false}); 264 | return objectMerge(opts, x); 265 | } 266 | expect(thrower).not.toThrow(); 267 | }); 268 | it('only considers ObjectMergeOptions obj @ arg[0] to be valid options', 269 | function () { 270 | var x = { 271 | 'a' : {} 272 | }; 273 | x.b = x.a; 274 | function thrower () { 275 | var opts = objectMerge.createOptions({throwOnCircularRef : false}); 276 | return objectMerge(x, opts); 277 | } 278 | function thrower2 () { 279 | return objectMerge({throwOnCircularRef : false}, x); 280 | } 281 | expect(thrower).toThrow(); 282 | expect(thrower2).toThrow(); 283 | } 284 | ); 285 | it('considers depth of false to mean no limit', function () { 286 | var a = { 287 | 'a1' : { 288 | 'a2' : { 289 | 'a3' : {} 290 | } 291 | } 292 | }; 293 | var opts = objectMerge.createOptions({depth : false}); 294 | var res = objectMerge(opts, a); 295 | expect(res).toEqual(a); 296 | }); 297 | it('allows specifying depth of traversal', function () { 298 | var a = { 299 | 'a1' : { 300 | 'a2' : { 301 | 'a3' : {} 302 | } 303 | } 304 | }; 305 | var b = { 306 | 'b1' : { 307 | 'b2' : { 308 | 'b3' : {} 309 | } 310 | } 311 | }; 312 | var opts = objectMerge.createOptions({depth : 2}); 313 | var res = objectMerge(opts, a, b); 314 | expect(res).toEqual({ 315 | 'a1' : { 316 | 'a2' : {} 317 | }, 318 | 'b1' : { 319 | 'b2' : {} 320 | } 321 | }); 322 | }); 323 | }); 324 | -------------------------------------------------------------------------------- /dev/browserMain.js: -------------------------------------------------------------------------------- 1 | objectMerge = require('../src/object-merge.js'); 2 | -------------------------------------------------------------------------------- /dev/browserify.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Options for browserify.bundle 3 | * @namespace 4 | */ 5 | var browserifyBundleOpts = { 6 | /** 7 | * When opts.debug is true, add a source map inline to the end of the 8 | * bundle. This makes debugging easier because you can see all the original 9 | * files if you are in a modern enough browser. 10 | * @type Boolean 11 | * @default false 12 | */ 13 | debug : true, 14 | /** 15 | * When opts.insertGlobals is true, always insert process, global, 16 | * __filename, and __dirname without analyzing the AST for faster builds but 17 | * larger output bundles. Default false. 18 | * @type Boolean 19 | * @default false 20 | */ 21 | insertGlobals : false, 22 | /** 23 | * When opts.detectGlobals is true, scan all files for process, global, 24 | * __filename, and __dirname, defining as necessary. With this option npm 25 | * modules are more likely to work but bundling takes longer. Default true. 26 | * @type Boolean 27 | * @default true 28 | */ 29 | detectGlobals : true, 30 | /** 31 | * When opts.standalone is a non-empty string, a standalone module is 32 | * created with that name and a umd wrapper. 33 | * @type String 34 | */ 35 | standalone : '', 36 | /** 37 | * opts.insertGlobalVars will be passed to insert-module-globals as the 38 | * opts.vars parameter. (it's properties become global properties available 39 | * within the module.) 40 | * @type Object 41 | */ 42 | insertGlobalVars : {} 43 | }; 44 | 45 | var path = require('path'); 46 | var fs = require('fs'); 47 | var browserify = require('browserify'); 48 | var b = browserify(browserifyBundleOpts); 49 | var browserMain = path.resolve(__dirname, 'browserMain.js'); 50 | var outputFile = path.resolve(__dirname, '../browser/object-merge_web.js'); 51 | var writeStream = fs.createWriteStream(outputFile); 52 | 53 | b.add(browserMain); 54 | b.bundle().pipe(writeStream); 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /docs/jsdoc/files.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | JsDoc Reference - File Index 8 | 9 | 10 | 174 | 175 | 176 | 177 | 179 | 180 |
181 | 183 |
184 |

Classes

185 | 192 |
193 |
194 | 195 |
196 |

File Index

197 | 198 | 199 |
200 |

<src/object-merge.js>

201 | 202 |
203 | 204 | 205 | 206 | 207 |
208 |
209 |
210 | 211 | 212 |
213 |
214 | 215 | Documentation generated by JsDoc Toolkit 2.4.0 on Thu Nov 17 2022 18:10:06 GMT-0500 (Eastern Standard Time) 216 |
217 | 218 | -------------------------------------------------------------------------------- /docs/jsdoc/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | JsDoc Reference - Index 8 | 9 | 10 | 174 | 175 | 176 | 177 | 179 | 180 |
181 | 183 |
184 |

Classes

185 | 192 |
193 |
194 | 195 |
196 |

Class Index

197 | 198 | 199 |
200 |

_global_

201 | 202 |
203 |
204 | 205 |
206 |

objectMerge

207 | Merges JavaScript objects recursively without altering the objects merged. 208 |
209 |
210 | 211 | 212 |
213 |
214 | 215 | Documentation generated by JsDoc Toolkit 2.4.0 on Thu Nov 17 2022 18:10:06 GMT-0500 (Eastern Standard Time) 216 |
217 | 218 | -------------------------------------------------------------------------------- /docs/jsdoc/symbols/_global_.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | JsDoc Reference - _global_ 9 | 10 | 174 | 175 | 176 | 177 | 178 | 179 | 181 | 182 | 183 | 184 |
185 | 186 | 188 |
189 |

Classes

190 | 197 |
198 | 199 |
200 | 201 |
202 | 203 |

204 | 205 | Built-In Namespace _global_ 206 |

207 | 208 | 209 |

210 | 211 | 212 | 213 | 214 | 215 | 216 |

217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 |
242 |
243 | 244 | 245 | 246 |
247 | 248 | Documentation generated by JsDoc Toolkit 2.4.0 on Thu Nov 17 2022 18:10:06 GMT-0500 (Eastern Standard Time) 249 |
250 | 251 | 252 | -------------------------------------------------------------------------------- /docs/jsdoc/symbols/objectMerge.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | JsDoc Reference - objectMerge 9 | 10 | 174 | 175 | 176 | 177 | 178 | 179 | 181 | 182 | 183 | 184 |
185 | 186 | 188 |
189 |

Classes

190 | 197 |
198 | 199 |
200 | 201 |
202 | 203 |

204 | 205 | Function Namespace objectMerge 206 |

207 | 208 | 209 |

210 | 211 | 212 | 213 | Merges JavaScript objects recursively without altering the objects merged. 214 | 215 | 216 |
Defined in: <src/object-merge.js>. 217 | 218 |

219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 239 | 240 | 241 |
Function Namespace Summary
Constructor AttributesConstructor Name and Description
  234 |
235 | objectMerge(opts, shadows) 236 |
237 |
Merges JavaScript objects recursively without altering the objects merged.
238 |
242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 268 | 269 | 270 | 271 |
Method Summary
Method AttributesMethod Name and Description
<static>   264 |
objectMerge.createOptions(opts) 265 |
266 |
Creates a new options object suitable for use with objectMerge.
267 |
272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 |
282 |
283 | Function Namespace Detail 284 |
285 | 286 |
287 | objectMerge(opts, shadows) 288 |
289 | 290 |
291 | Merges JavaScript objects recursively without altering the objects merged. 292 |
Author: Matthew Kastor. 293 |
294 | 295 | 296 | 297 |
 var objectMerge = require('object-merge');
 var x = {
     a : 'a',
     b : 'b',
     c : {
         d : 'd',
         e : 'e',
         f : {
             g : 'g'
         }
     }
 };
 var y = {
     a : '`a',
     b : '`b',
     c : {
         d : '`d'
     }
 };
 var z = {
     a : {
         b : '``b'
     },
     fun : function foo () {
         return 'foo';
     },
     aps : Array.prototype.slice
 };
 var out = objectMerge(x, y, z);
 // out.a will be {
 //         b : '``b'
 //     }
 // out.b will be '`b'
 // out.c will be {
 //         d : '`d',
 //         e : 'e',
 //         f : {
 //             g : 'g'
 //         }
 //     }
 // out.fun will be a clone of z.fun
 // out.aps will be equal to z.aps
298 | 299 | 300 | 301 | 302 | 303 |
304 |
Parameters:
305 | 306 |
307 | {ObjectMergeOptions} opts 308 | Optional 309 |
310 |
An options object created by objectMerge.createOptions. Options must be specified as the first argument and must be an object created with createOptions or else the object will not be recognized as an options object and will be merged instead.
311 | 312 |
313 | {Object} shadows 314 | 315 |
316 |
[[shadows]...] One or more objects to merge. Each argument given will be treated as an object to merge. Each object overwrites the previous objects descendant properties if the property name matches. If objects properties are objects they will be merged recursively as well.
317 | 318 |
319 | 320 | 321 | 322 | 323 | 324 |
325 |
Returns:
326 | 327 |
{Object} Returns a single merged object composed from clones of the input objects.
328 | 329 |
330 | 331 | 332 | 333 | 334 |
335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 |
343 | Method Detail 344 |
345 | 346 | 347 |
<static> 348 | 349 | {ObjectMergeOptions} 350 | objectMerge.createOptions(opts) 351 | 352 |
353 |
354 | Creates a new options object suitable for use with objectMerge. 355 | 356 | 357 |
358 | 359 | 360 | 361 |
 var opts = objectMerge.createOptions({
     depth : 2,
     throwOnCircularRef : false
 });
 var obj1 = {
     a1 : {
         a2 : {
             a3 : {}
         }
     }
 };
 var obj2 = {
     a1 : {
         a2 : {
             a3 : 'will not be in output'
         },
         a22 : {}
     }
 };
 objectMerge(opts, obj1, obj2);
362 | 363 | 364 | 365 | 366 |
367 |
Parameters:
368 | 369 |
370 | {Object} opts 371 | Optional 372 |
373 |
An object specifying the options.
374 | 375 |
376 | {Object} opts.depth 377 | Optional, Default: false 378 |
379 |
Specifies the depth to traverse objects during merging. If this is set to false then there will be no depth limit.
380 | 381 |
382 | {Object} opts.throwOnCircularRef 383 | Optional, Default: true 384 |
385 |
Set to false to suppress errors on circular references.
386 | 387 |
388 | 389 | 390 | 391 | 392 | 393 |
394 |
Returns:
395 | 396 |
{ObjectMergeOptions} Returns an instance of ObjectMergeOptions to be used with objectMerge.
397 | 398 |
399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 |
411 |
412 | 413 | 414 | 415 |
416 | 417 | Documentation generated by JsDoc Toolkit 2.4.0 on Thu Nov 17 2022 18:10:06 GMT-0500 (Eastern Standard Time) 418 |
419 | 420 | 421 | -------------------------------------------------------------------------------- /docs/vsdoc/OpenLayersAll.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* vsdoc for _global_ */ 4 | 5 | (function (window) { 6 | 7 | 8 | window._global_ = { 9 | /// 10 | /// 11 | 12 | }; 13 | 14 | var $x = window._global_; 15 | $x.__namespace = "true"; 16 | $x.__typeName = "_global_"; 17 | })(this); 18 | 19 | 20 | 21 | 22 | /* vsdoc for objectMerge */ 23 | 24 | (function (window) { 25 | 26 | 27 | window.objectMerge = { 28 | /// Merges JavaScript objects recursively without altering the objects merged. 29 | /// An options object created by 30 | /// objectMerge.createOptions. Options must be specified as the first argument 31 | /// and must be an object created with createOptions or else the object will 32 | /// not be recognized as an options object and will be merged instead. 33 | /// [[shadows]...] One or more objects to merge. Each 34 | /// argument given will be treated as an object to merge. Each object 35 | /// overwrites the previous objects descendant properties if the property name 36 | /// matches. If objects properties are objects they will be merged recursively 37 | /// as well. 38 | /// 39 | 40 | createOptions: function(opts, opts.depth, opts.throwOnCircularRef) { 41 | /// Creates a new options object suitable for use with objectMerge. 42 | /// An object specifying the options. 43 | /// Specifies the depth to traverse objects 44 | /// during merging. If this is set to false then there will be no depth limit. 45 | /// Set to false to suppress 46 | /// errors on circular references. 47 | /// Returns an instance of ObjectMergeOptions 48 | /// to be used with objectMerge. 49 | } 50 | 51 | }; 52 | 53 | var $x = window.objectMerge; 54 | $x.__namespace = "true"; 55 | $x.__typeName = "objectMerge"; 56 | })(this); 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /docs/vsdoc/OpenLayersReferences.js: -------------------------------------------------------------------------------- 1 | 2 | /// 3 | 4 | -------------------------------------------------------------------------------- /docs/vsdoc/files.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | JsDoc Reference - File Index 8 | 9 | 10 | 174 | 175 | 176 | 177 | 179 | 180 |
181 | 183 |
184 |

Classes

185 | 192 |
193 |
194 | 195 |
196 |

File Index

197 | 198 | 199 |
200 |

<src/object-merge.js>

201 | 202 |
203 | 204 | 205 | 206 | 207 |
208 |
209 |
210 | 211 | 212 |
213 |
214 | 215 | Documentation generated by JsDoc Toolkit 2.4.0 on Thu Nov 17 2022 18:10:05 GMT-0500 (Eastern Standard Time) 216 |
217 | 218 | -------------------------------------------------------------------------------- /docs/vsdoc/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | JsDoc Reference - Index 8 | 9 | 10 | 174 | 175 | 176 | 177 | 179 | 180 |
181 | 183 |
184 |

Classes

185 | 192 |
193 |
194 | 195 |
196 |

Class Index

197 | 198 | 199 |
200 |

_global_

201 |
202 |
203 |
204 | 205 |
206 |

objectMerge

207 | Merges JavaScript objects recursively without altering the objects merged.
208 |
209 |
210 | 211 | 212 |
213 |
214 | 215 | Documentation generated by JsDoc Toolkit 2.4.0 on Thu Nov 17 2022 18:10:05 GMT-0500 (Eastern Standard Time) 216 |
217 | 218 | -------------------------------------------------------------------------------- /docs/vsdoc/symbols/_global_-vsdoc.js: -------------------------------------------------------------------------------- 1 | 2 | /* vsdoc for _global_ */ 3 | 4 | (function (window) { 5 | 6 | 7 | window._global_ = { 8 | /// 9 | /// 10 | 11 | }; 12 | 13 | var $x = window._global_; 14 | $x.__namespace = "true"; 15 | $x.__typeName = "_global_"; 16 | })(this); 17 | -------------------------------------------------------------------------------- /docs/vsdoc/symbols/objectMerge-vsdoc.js: -------------------------------------------------------------------------------- 1 | 2 | /* vsdoc for objectMerge */ 3 | 4 | (function (window) { 5 | 6 | 7 | window.objectMerge = { 8 | /// Merges JavaScript objects recursively without altering the objects merged. 9 | /// An options object created by 10 | /// objectMerge.createOptions. Options must be specified as the first argument 11 | /// and must be an object created with createOptions or else the object will 12 | /// not be recognized as an options object and will be merged instead. 13 | /// [[shadows]...] One or more objects to merge. Each 14 | /// argument given will be treated as an object to merge. Each object 15 | /// overwrites the previous objects descendant properties if the property name 16 | /// matches. If objects properties are objects they will be merged recursively 17 | /// as well. 18 | /// 19 | 20 | createOptions: function(opts, opts.depth, opts.throwOnCircularRef) { 21 | /// Creates a new options object suitable for use with objectMerge. 22 | /// An object specifying the options. 23 | /// Specifies the depth to traverse objects 24 | /// during merging. If this is set to false then there will be no depth limit. 25 | /// Set to false to suppress 26 | /// errors on circular references. 27 | /// Returns an instance of ObjectMergeOptions 28 | /// to be used with objectMerge. 29 | } 30 | 31 | }; 32 | 33 | var $x = window.objectMerge; 34 | $x.__namespace = "true"; 35 | $x.__typeName = "objectMerge"; 36 | })(this); 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "object-merge", 3 | "version": "2022.11.16", 4 | "description": "Merges JavaScript objects recursively without altering the objects merged.", 5 | "main": "./src/object-merge.js", 6 | "directories": { 7 | "lib": "src", 8 | "doc": "docs" 9 | }, 10 | "devDependencies": { 11 | "atropa-jsformatter": "git+https://github.com/matthewkastor/atropa-jsformatter.git#gh-pages", 12 | "atropa-jslint": "git+https://github.com/matthewkastor/atropa-jslint.git#master", 13 | "browserify": ">=17.0.0", 14 | "jasmine-node": ">=1.11.0", 15 | "jsdoc-toolkit": "git+https://github.com/matthewkastor/node-jsdoc-toolkit.git#fix-tests" 16 | }, 17 | "scripts": { 18 | "test": "jasmine-node specs/", 19 | "buildBrowserModule": "node dev/browserify.js", 20 | "buildDocs": "jsdoc-toolkit -v -d=./docs/jsdoc/ -r -s src/", 21 | "buildVsdocs": "jsdoc-toolkit -v -d=./docs/vsdoc/ -t=./node_modules/jsdoc-toolkit/templates/vsdoc/ -r -s src/", 22 | "lint": "atropa-jslint ./src/object-merge.js", 23 | "srcFormat": "atropa-jsformatter ./src/object-merge.js ./src/object-merge.js" 24 | }, 25 | "homepage": "https://github.com/matthewkastor/object-merge/", 26 | "bugs": "https://github.com/matthewkastor/object-merge/issues", 27 | "repository": { 28 | "type": "git", 29 | "url": "git://github.com/matthewkastor/object-merge.git" 30 | }, 31 | "keywords": [ 32 | "object-merge", 33 | "atropa" 34 | ], 35 | "author": { 36 | "name": "Matthew Kastor", 37 | "email": "matthewkastor@gmail.com", 38 | "url": "https://plus.google.com/100898583798552211130" 39 | }, 40 | "licenses": [ 41 | { 42 | "type": "GPL-3.0", 43 | "url": "http://www.gnu.org/licenses/gpl-3.0-standalone.html" 44 | } 45 | ], 46 | "dependencies": { 47 | "clone-function": ">=1.0.1", 48 | "object-foreach": ">=0.1.2" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /rebuild.cmd: -------------------------------------------------------------------------------- 1 | cmd /c npm install 2 | pause 3 | rem cmd /c npm run-script srcFormat 4 | cmd /c npm run-script lint 5 | cmd /c npm run-script test 6 | pause 7 | cmd /c npm run-script buildBrowserModule 8 | pause 9 | cmd /c npm run-script buildVsdocs 10 | cmd /c npm run-script buildDocs 11 | pause -------------------------------------------------------------------------------- /specs/object-merge.Spec.js: -------------------------------------------------------------------------------- 1 | var objectMerge = require('../src/object-merge.js'); 2 | var fs = require('fs'); 3 | var path = require('path'); 4 | var specPath = path.resolve(__dirname, '../browser/tests/object-merge.test.js'); 5 | var specCode = fs.readFileSync(specPath, "utf8"); 6 | eval(specCode); 7 | -------------------------------------------------------------------------------- /src/object-merge.js: -------------------------------------------------------------------------------- 1 | /* 2 | License gpl-3.0 http://www.gnu.org/licenses/gpl-3.0-standalone.html 3 | */ 4 | /*jslint 5 | white: true, 6 | vars: true, 7 | node: true 8 | */ 9 | function ObjectMergeOptions(opts) { 10 | 'use strict'; 11 | opts = opts || {}; 12 | this.depth = opts.depth || false; 13 | // circular ref check is true unless explicitly set to false 14 | // ignore the jslint warning here, it's pointless. 15 | this.throwOnCircularRef = 'throwOnCircularRef' in opts && opts.throwOnCircularRef === false ? false : true; 16 | } 17 | /*jslint unparam:true*/ 18 | /** 19 | * Creates a new options object suitable for use with objectMerge. 20 | * @memberOf objectMerge 21 | * @param {Object} [opts] An object specifying the options. 22 | * @param {Object} [opts.depth = false] Specifies the depth to traverse objects 23 | * during merging. If this is set to false then there will be no depth limit. 24 | * @param {Object} [opts.throwOnCircularRef = true] Set to false to suppress 25 | * errors on circular references. 26 | * @returns {ObjectMergeOptions} Returns an instance of ObjectMergeOptions 27 | * to be used with objectMerge. 28 | * @example 29 | * var opts = objectMerge.createOptions({ 30 | * depth : 2, 31 | * throwOnCircularRef : false 32 | * }); 33 | * var obj1 = { 34 | * a1 : { 35 | * a2 : { 36 | * a3 : {} 37 | * } 38 | * } 39 | * }; 40 | * var obj2 = { 41 | * a1 : { 42 | * a2 : { 43 | * a3 : 'will not be in output' 44 | * }, 45 | * a22 : {} 46 | * } 47 | * }; 48 | * objectMerge(opts, obj1, obj2); 49 | */ 50 | function createOptions(opts) { 51 | 'use strict'; 52 | var argz = Array.prototype.slice.call(arguments, 0); 53 | argz.unshift(null); 54 | var F = ObjectMergeOptions.bind.apply(ObjectMergeOptions, argz); 55 | return new F(); 56 | } 57 | /*jslint unparam:false*/ 58 | /** 59 | * Merges JavaScript objects recursively without altering the objects merged. 60 | * @namespace Merges JavaScript objects recursively without altering the objects merged. 61 | * @author Matthew Kastor 62 | * @param {ObjectMergeOptions} [opts] An options object created by 63 | * objectMerge.createOptions. Options must be specified as the first argument 64 | * and must be an object created with createOptions or else the object will 65 | * not be recognized as an options object and will be merged instead. 66 | * @param {Object} shadows [[shadows]...] One or more objects to merge. Each 67 | * argument given will be treated as an object to merge. Each object 68 | * overwrites the previous objects descendant properties if the property name 69 | * matches. If objects properties are objects they will be merged recursively 70 | * as well. 71 | * @returns {Object} Returns a single merged object composed from clones of the 72 | * input objects. 73 | * @example 74 | * var objectMerge = require('object-merge'); 75 | * var x = { 76 | * a : 'a', 77 | * b : 'b', 78 | * c : { 79 | * d : 'd', 80 | * e : 'e', 81 | * f : { 82 | * g : 'g' 83 | * } 84 | * } 85 | * }; 86 | * var y = { 87 | * a : '`a', 88 | * b : '`b', 89 | * c : { 90 | * d : '`d' 91 | * } 92 | * }; 93 | * var z = { 94 | * a : { 95 | * b : '``b' 96 | * }, 97 | * fun : function foo () { 98 | * return 'foo'; 99 | * }, 100 | * aps : Array.prototype.slice 101 | * }; 102 | * var out = objectMerge(x, y, z); 103 | * // out.a will be { 104 | * // b : '``b' 105 | * // } 106 | * // out.b will be '`b' 107 | * // out.c will be { 108 | * // d : '`d', 109 | * // e : 'e', 110 | * // f : { 111 | * // g : 'g' 112 | * // } 113 | * // } 114 | * // out.fun will be a clone of z.fun 115 | * // out.aps will be equal to z.aps 116 | */ 117 | function objectMerge(shadows) { 118 | 'use strict'; 119 | var objectForeach = require('object-foreach'); 120 | var cloneFunction = require('clone-function'); 121 | // this is the queue of visited objects / properties. 122 | var visited = []; 123 | // various merge options 124 | var options = {}; 125 | // gets the sequential trailing objects from array. 126 | function getShadowObjects(shadows) { 127 | var out = shadows.reduce(function (collector, shadow) { 128 | if (shadow instanceof Object) { 129 | collector.push(shadow); 130 | } else { 131 | collector = []; 132 | } 133 | return collector; 134 | }, []); 135 | return out; 136 | } 137 | // gets either a new object of the proper type or the last primitive value 138 | function getOutputObject(shadows) { 139 | var out; 140 | var lastShadow = shadows[shadows.length - 1]; 141 | if (lastShadow instanceof Array) { 142 | out = []; 143 | } else if (lastShadow instanceof Function) { 144 | try { 145 | out = cloneFunction(lastShadow); 146 | } catch (e) { 147 | throw new Error(e.message); 148 | } 149 | } else if (lastShadow instanceof Object) { 150 | out = {}; 151 | } else { 152 | // lastShadow is a primitive value; 153 | out = lastShadow; 154 | } 155 | return out; 156 | } 157 | // checks for circular references 158 | function circularReferenceCheck(shadows) { 159 | // if any of the current objects to process exist in the queue 160 | // then throw an error. 161 | shadows.forEach(function (item) { 162 | if (item instanceof Object && visited.indexOf(item) > -1) { 163 | throw new Error('Circular reference error'); 164 | } 165 | }); 166 | // if none of the current objects were in the queue 167 | // then add references to the queue. 168 | visited = visited.concat(shadows); 169 | } 170 | function objectMergeRecursor(shadows, currentDepth) { 171 | if (options.depth !== false) { 172 | currentDepth = currentDepth ? currentDepth + 1 : 1; 173 | } else { 174 | currentDepth = 0; 175 | } 176 | if (options.throwOnCircularRef === true) { 177 | circularReferenceCheck(shadows); 178 | } 179 | var out = getOutputObject(shadows); 180 | /*jslint unparam: true */ 181 | function shadowHandler(val, prop, shadow) { 182 | if (out[prop]) { 183 | out[prop] = objectMergeRecursor([ 184 | out[prop], 185 | shadow[prop] 186 | ], currentDepth); 187 | } else { 188 | out[prop] = objectMergeRecursor([shadow[prop]], currentDepth); 189 | } 190 | } 191 | /*jslint unparam:false */ 192 | function shadowMerger(shadow) { 193 | objectForeach(shadow, shadowHandler); 194 | } 195 | // short circuits case where output would be a primitive value 196 | // anyway. 197 | if (out instanceof Object && currentDepth <= options.depth) { 198 | // only merges trailing objects since primitives would wipe out 199 | // previous objects, as in merging {a:'a'}, 'a', and {b:'b'} 200 | // would result in {b:'b'} so the first two arguments 201 | // can be ignored completely. 202 | var relevantShadows = getShadowObjects(shadows); 203 | relevantShadows.forEach(shadowMerger); 204 | } 205 | return out; 206 | } 207 | // determines whether an options object was passed in and 208 | // uses it if present 209 | // ignore the jslint warning here too. 210 | if (arguments[0] instanceof ObjectMergeOptions) { 211 | options = arguments[0]; 212 | shadows = Array.prototype.slice.call(arguments, 1); 213 | } else { 214 | options = createOptions(); 215 | shadows = Array.prototype.slice.call(arguments, 0); 216 | } 217 | return objectMergeRecursor(shadows); 218 | } 219 | objectMerge.createOptions = createOptions; 220 | module.exports = objectMerge; --------------------------------------------------------------------------------