├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── deploy.sh ├── deploy_key.enc ├── jsdoc.json ├── package.json ├── src ├── Base.js ├── atom │ ├── AtomCategory.js │ ├── AtomCommon.js │ ├── AtomContent.js │ ├── AtomEntry.js │ ├── AtomFeed.js │ ├── AtomGenerator.js │ ├── AtomPerson.js │ ├── AtomSource.js │ └── index.js ├── core │ ├── Address.js │ ├── Agent.js │ ├── Attribution.js │ ├── Conclusion.js │ ├── Coverage.js │ ├── Date.js │ ├── Document.js │ ├── Event.js │ ├── EventRole.js │ ├── EvidenceReference.js │ ├── ExtensibleData.js │ ├── Fact.js │ ├── Gender.js │ ├── Identifiers.js │ ├── Name.js │ ├── NameForm.js │ ├── NamePart.js │ ├── Note.js │ ├── OnlineAccount.js │ ├── Person.js │ ├── PlaceDescription.js │ ├── PlaceReference.js │ ├── Qualifier.js │ ├── Relationship.js │ ├── ResourceReference.js │ ├── Root.js │ ├── SourceCitation.js │ ├── SourceDescription.js │ ├── SourceReference.js │ ├── Subject.js │ └── TextValue.js ├── index.js ├── records │ ├── Collection.js │ ├── CollectionContent.js │ ├── Coverage.js │ ├── ExtensibleData.js │ ├── Fact.js │ ├── Field.js │ ├── FieldDescriptor.js │ ├── FieldValue.js │ ├── FieldValueDescriptor.js │ ├── Person.js │ ├── RecordDescriptor.js │ ├── Root.js │ ├── SourceDescription.js │ ├── SourceReference.js │ └── index.js ├── rs │ ├── Conclusion.js │ ├── Date.js │ ├── DisplayProperties.js │ ├── ExtensibleData.js │ ├── FamilyView.js │ ├── Link.js │ ├── Links.js │ ├── Name.js │ ├── Person.js │ ├── PlaceDescription.js │ ├── PlaceDisplayProperties.js │ ├── PlaceReference.js │ ├── ResourceReference.js │ ├── SourceDescription.js │ └── index.js └── utils.js ├── test ├── atom │ ├── AtomCategory.js │ ├── AtomCommon.js │ ├── AtomContent.js │ ├── AtomEntry.js │ ├── AtomFeed.js │ ├── AtomGenerator.js │ ├── AtomPerson.js │ ├── AtomSource.js │ └── index.js ├── core │ ├── Address.js │ ├── Agent.js │ ├── Attribution.js │ ├── Conclusion.js │ ├── Coverage.js │ ├── Date.js │ ├── Document.js │ ├── Event.js │ ├── EventRole.js │ ├── EvidenceReference.js │ ├── ExtensibleData.js │ ├── Fact.js │ ├── Gender.js │ ├── Identifiers.js │ ├── Name.js │ ├── NameForm.js │ ├── NamePart.js │ ├── Note.js │ ├── OnlineAccount.js │ ├── Person.js │ ├── PlaceDescription.js │ ├── PlaceReference.js │ ├── Qualifier.js │ ├── Relationship.js │ ├── ResourceReference.js │ ├── Root.js │ ├── SourceCitation.js │ ├── SourceDescription.js │ ├── SourceReference.js │ ├── Subject.js │ └── TextValue.js ├── index.js ├── mocha.opts ├── records │ ├── Collection.js │ ├── CollectionContent.js │ ├── Coverage.js │ ├── ExtensibleData.js │ ├── Fact.js │ ├── Field.js │ ├── FieldDescriptor.js │ ├── FieldValue.js │ ├── FieldValueDescriptor.js │ ├── Person.js │ ├── RecordDescriptor.js │ ├── Root.js │ ├── SourceDescription.js │ ├── SourceReference.js │ └── index.js ├── rs │ ├── Conclusion.js │ ├── Date.js │ ├── DisplayProperties.js │ ├── ExtensibleData.js │ ├── FamilyView.js │ ├── Link.js │ ├── Links.js │ ├── Name.js │ ├── Person.js │ ├── PlaceDescription.js │ ├── PlaceDisplayProperties.js │ ├── PlaceReference.js │ ├── ResourceReference.js │ ├── SourceDescription.js │ └── index.js └── utils.js └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | out 3 | npm-debug.log 4 | coverage 5 | dist -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '4.0' 4 | - '5.0' 5 | - '6.0' 6 | script: 7 | - 'npm run coverage' 8 | after_success: 9 | - if [ "$TRAVIS_NODE_VERSION" == "6.0" ]; then bash ./deploy.sh; fi 10 | env: 11 | global: 12 | - ENCRYPTION_LABEL: "26b4962af0e7" 13 | - COMMIT_AUTHOR_EMAIL: "justincyork@gmail.com" 14 | notifications: 15 | email: 16 | on_success: never 17 | on_failure: always -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 rootsdev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Crazy gh-pages deploy script that avoids potentially faulty github tokens 4 | # 5 | # https://gist.github.com/domenic/ec8b0fc8ab45f39403dd 6 | 7 | set -e # Exit with nonzero exit code if anything fails 8 | 9 | SOURCE_BRANCH="master" 10 | TARGET_BRANCH="gh-pages" 11 | 12 | function doCompile { 13 | npm run docs 14 | } 15 | 16 | # Pull requests and commits to other branches shouldn't try to deploy, just build to verify 17 | if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then 18 | echo "Skipping deploy; just doing a build." 19 | doCompile 20 | exit 0 21 | fi 22 | 23 | # Save some useful information 24 | REPO=`git config remote.origin.url` 25 | SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:} 26 | SHA=`git rev-parse --verify HEAD` 27 | 28 | # Clone the existing gh-pages for this repo into out/ 29 | # Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deply) 30 | git clone $REPO out 31 | cd out 32 | git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH 33 | cd .. 34 | 35 | # Clean out existing contents 36 | rm -rf out/**/* || exit 0 37 | 38 | # Run our compile script 39 | doCompile 40 | 41 | # Now let's go have some fun with the cloned repo 42 | cd out 43 | git config user.name "Travis CI" 44 | git config user.email "$COMMIT_AUTHOR_EMAIL" 45 | 46 | # If there are no changes to the compiled out (e.g. this is a README update) then just bail. 47 | if [ -z `git diff --exit-code` ]; then 48 | echo "No changes to the output on this push; exiting." 49 | exit 0 50 | fi 51 | 52 | # Commit the "changes", i.e. the new version. 53 | # The delta will show diffs between new and old versions. 54 | git add . 55 | git commit -m "Deploy to GitHub Pages: ${SHA}" 56 | 57 | # Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc 58 | ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key" 59 | ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv" 60 | ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR} 61 | ENCRYPTED_IV=${!ENCRYPTED_IV_VAR} 62 | openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in deploy_key.enc -out deploy_key -d 63 | chmod 600 deploy_key 64 | eval `ssh-agent -s` 65 | ssh-add deploy_key 66 | 67 | # Now that we're all set up, we can push. 68 | git push $SSH_REPO $TARGET_BRANCH -------------------------------------------------------------------------------- /deploy_key.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rootsdev/gedcomx-js/08b2fcde96f1e301c78561bfb7a8b0cac606e26e/deploy_key.enc -------------------------------------------------------------------------------- /jsdoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "source": { 3 | "include": [ 4 | "src" 5 | ] 6 | }, 7 | "opts": { 8 | "recurse": true, 9 | "readme": "README.md", 10 | "template": "node_modules/ink-docstrap/template" 11 | }, 12 | "templates": { 13 | "includeDate": false, 14 | "systemName": "GedcomX JS", 15 | "theme": "yeti", 16 | "search": false, 17 | "sort": "name", 18 | "footer": "\"Fork" 19 | } 20 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gedcomx-js", 3 | "version": "2.8.0", 4 | "description": "JavaScript object model for GEDCOM X", 5 | "main": "src/index.js", 6 | "scripts": { 7 | "test": "mocha && npm run test:core && npm run test:rs && npm run test:records && npm run test:atom", 8 | "test:core": "mocha test/core/*.js", 9 | "test:rs": "mocha test/rs/*.js", 10 | "test:records": "mocha test/records/*.js", 11 | "test:atom": "mocha test/atom/*.js", 12 | "docs": "jsdoc -c jsdoc.json", 13 | "prepublish": "npm run build", 14 | "coverage": "istanbul cover --report lcovonly _mocha -- --recursive && codecov", 15 | "build": "mkdir -p dist && npm run build:full && npm run build:min", 16 | "build:full": "webpack --output-filename gedcomx.js", 17 | "build:min": "webpack --output-filename gedcomx.min.js --optimize-minimize" 18 | }, 19 | "devDependencies": { 20 | "chai": "^3.5.0", 21 | "chai-json-schema": "^1.3.0", 22 | "codecov": "^1.0.1", 23 | "gedcomx-json-schema": "^1.5.0", 24 | "ink-docstrap": "^1.3.0", 25 | "istanbul": "^0.4.3", 26 | "jsdoc": "^3.4.0", 27 | "mocha": "^2.4.5", 28 | "webpack": "^1.13.2" 29 | }, 30 | "repository": { 31 | "type": "git", 32 | "url": "git+https://github.com/rootsdev/gedcomx-js.git" 33 | }, 34 | "files": [ 35 | "src", 36 | "dist" 37 | ], 38 | "keywords": [ 39 | "gedcomx", 40 | "genealogy" 41 | ], 42 | "author": "", 43 | "license": "MIT", 44 | "bugs": { 45 | "url": "https://github.com/rootsdev/gedcomx-js/issues" 46 | }, 47 | "homepage": "https://github.com/rootsdev/gedcomx-js#readme" 48 | } 49 | -------------------------------------------------------------------------------- /src/atom/AtomCategory.js: -------------------------------------------------------------------------------- 1 | module.exports = function(GedcomX){ 2 | 3 | var utils = require('../utils'), 4 | AtomCommon = require('./AtomCommon'); 5 | 6 | /** 7 | * Information about a category associated with an atom entry or feed. 8 | * 9 | * @see {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/atom-model-specification.md#atom-json-media-type|GEDCOM X Atom JSON Spec} 10 | * @see {@link https://tools.ietf.org/html/rfc4287#section-4.2.2|RFC 4287} 11 | * 12 | * @class AtomCategory 13 | * @extends AtomCommon 14 | * @param {Object} [json] 15 | */ 16 | var AtomCategory = function(json){ 17 | 18 | // Protect against forgetting the new keyword when calling the constructor 19 | if(!(this instanceof AtomCategory)){ 20 | return new AtomCategory(json); 21 | } 22 | 23 | // If the given object is already an instance then just return it. DON'T copy it. 24 | if(AtomCategory.isInstance(json)){ 25 | return json; 26 | } 27 | 28 | this.init(json); 29 | }; 30 | 31 | AtomCategory.prototype = Object.create(AtomCommon.prototype); 32 | 33 | AtomCategory._gedxClass = AtomCategory.prototype._gedxClass = 'GedcomX.AtomCategory'; 34 | 35 | AtomCategory.jsonProps = [ 36 | 'scheme', 37 | 'term', 38 | 'label' 39 | ]; 40 | 41 | /** 42 | * Check whether the given object is an instance of this class. 43 | * 44 | * @param {Object} obj 45 | * @returns {Boolean} 46 | */ 47 | AtomCategory.isInstance = function(obj){ 48 | return utils.isInstance(obj, this._gedxClass); 49 | }; 50 | 51 | /** 52 | * Initialize from JSON 53 | * 54 | * @param {Object} 55 | * @return {AtomCategory} this 56 | */ 57 | AtomCategory.prototype.init = function(json){ 58 | 59 | AtomCommon.prototype.init.call(this, json); 60 | 61 | if(json){ 62 | this.setScheme(json.scheme); 63 | this.setTerm(json.term); 64 | this.setLabel(json.label); 65 | } 66 | return this; 67 | }; 68 | 69 | /** 70 | * Set the scheme 71 | * 72 | * @param {String} scheme 73 | * @return {AtomCategory} this 74 | */ 75 | AtomCategory.prototype.setScheme = function(scheme){ 76 | this.scheme = scheme; 77 | return this; 78 | }; 79 | 80 | /** 81 | * Get the scheme 82 | * 83 | * @return {AtomCategory} this 84 | */ 85 | AtomCategory.prototype.getScheme = function(){ 86 | return this.scheme; 87 | }; 88 | 89 | /** 90 | * Set the term 91 | * 92 | * @param {String} term 93 | * @return {AtomCategory} this 94 | */ 95 | AtomCategory.prototype.setTerm = function(term){ 96 | this.term = term; 97 | return this; 98 | }; 99 | 100 | /** 101 | * Get the term 102 | * 103 | * @return {AtomCategory} this 104 | */ 105 | AtomCategory.prototype.getTerm = function(){ 106 | return this.term; 107 | }; 108 | 109 | /** 110 | * Set the label 111 | * 112 | * @param {String} label 113 | * @return {AtomCategory} this 114 | */ 115 | AtomCategory.prototype.setLabel = function(label){ 116 | this.label = label; 117 | return this; 118 | }; 119 | 120 | /** 121 | * Get the label 122 | * 123 | * @return {AtomCategory} this 124 | */ 125 | AtomCategory.prototype.getLabel = function(){ 126 | return this.label; 127 | }; 128 | 129 | /** 130 | * Export the object as JSON 131 | * 132 | * @return {Object} JSON object 133 | */ 134 | AtomCategory.prototype.toJSON = function(){ 135 | return this._toJSON(AtomCommon, AtomCategory.jsonProps); 136 | }; 137 | 138 | GedcomX.AtomCategory = AtomCategory; 139 | 140 | }; -------------------------------------------------------------------------------- /src/atom/AtomCommon.js: -------------------------------------------------------------------------------- 1 | var utils = require('../utils'), 2 | Base = require('../Base'); 3 | 4 | /** 5 | * Common attributes for all Atom entities 6 | * 7 | * @see {@link https://tools.ietf.org/html/rfc4287#page-7|RFC 4287} 8 | * 9 | * @class AtomCommon 10 | * @extends Base 11 | * @param {Object} [json] 12 | */ 13 | var AtomCommon = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof AtomCommon)){ 17 | return new AtomCommon(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(AtomCommon.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | AtomCommon.prototype = Object.create(Base.prototype); 29 | 30 | AtomCommon._gedxClass = AtomCommon.prototype._gedxClass = 'GedcomX.AtomCommon'; 31 | 32 | AtomCommon.jsonProps = [ 33 | 'base', 34 | 'lang' 35 | ]; 36 | 37 | /** 38 | * Check whether the given object is an instance of this class. 39 | * 40 | * @param {Object} obj 41 | * @returns {Boolean} 42 | */ 43 | AtomCommon.isInstance = function(obj){ 44 | return utils.isInstance(obj, this._gedxClass); 45 | }; 46 | 47 | /** 48 | * Initialize from JSON 49 | * 50 | * @param {Object} 51 | * @return {AtomCommon} this 52 | */ 53 | AtomCommon.prototype.init = function(json){ 54 | 55 | Base.prototype.init.call(this, json); 56 | 57 | if(json){ 58 | this.setBase(json.base); 59 | this.setLang(json.lang); 60 | } 61 | return this; 62 | }; 63 | 64 | /** 65 | * Set the base attribute 66 | * 67 | * @param {String} base 68 | * @return {AtomCommon} this 69 | */ 70 | AtomCommon.prototype.setBase = function(base){ 71 | this.base = base; 72 | return this; 73 | }; 74 | 75 | /** 76 | * Get the base 77 | * 78 | * @return {String} base 79 | */ 80 | AtomCommon.prototype.getBase = function(base){ 81 | return this.base; 82 | }; 83 | 84 | /** 85 | * Set the lang 86 | * 87 | * @param {String} lang 88 | * @return {AtomCommon} this 89 | */ 90 | AtomCommon.prototype.setLang = function(lang){ 91 | this.lang = lang; 92 | return this; 93 | }; 94 | 95 | /** 96 | * Get the lang 97 | * 98 | * @return {String} lang 99 | */ 100 | AtomCommon.prototype.getLang = function(lang){ 101 | return this.lang; 102 | }; 103 | 104 | /** 105 | * Export the object as JSON 106 | * 107 | * @return {Object} JSON object 108 | */ 109 | AtomCommon.prototype.toJSON = function(){ 110 | return this._toJSON(Base, AtomCommon.jsonProps); 111 | }; 112 | 113 | module.exports = AtomCommon; 114 | -------------------------------------------------------------------------------- /src/atom/AtomContent.js: -------------------------------------------------------------------------------- 1 | module.exports = function(GedcomX){ 2 | 3 | var utils = require('../utils'), 4 | AtomCommon = require('./AtomCommon'); 5 | 6 | /** 7 | * The content of an entry. 8 | * 9 | * @see {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/atom-model-specification.md#atom-json-media-type|GEDCOM X Atom JSON Spec} 10 | * @see {@link https://tools.ietf.org/html/rfc4287#section-4.1.3|RFC 4287} 11 | * 12 | * @class AtomContent 13 | * @extends AtomCommon 14 | * @param {Object} [json] 15 | */ 16 | var AtomContent = function(json){ 17 | 18 | // Protect against forgetting the new keyword when calling the constructor 19 | if(!(this instanceof AtomContent)){ 20 | return new AtomContent(json); 21 | } 22 | 23 | // If the given object is already an instance then just return it. DON'T copy it. 24 | if(AtomContent.isInstance(json)){ 25 | return json; 26 | } 27 | 28 | this.init(json); 29 | }; 30 | 31 | AtomContent.prototype = Object.create(AtomCommon.prototype); 32 | 33 | AtomContent._gedxClass = AtomContent.prototype._gedxClass = 'GedcomX.AtomContent'; 34 | 35 | AtomContent.jsonProps = [ 36 | 'gedcomx' 37 | ]; 38 | 39 | /** 40 | * Check whether the given object is an instance of this class. 41 | * 42 | * @param {Object} obj 43 | * @returns {Boolean} 44 | */ 45 | AtomContent.isInstance = function(obj){ 46 | return utils.isInstance(obj, this._gedxClass); 47 | }; 48 | 49 | /** 50 | * Initialize from JSON 51 | * 52 | * @param {Object} 53 | * @return {AtomContent} this 54 | */ 55 | AtomContent.prototype.init = function(json){ 56 | 57 | AtomCommon.prototype.init.call(this, json); 58 | 59 | if(json){ 60 | this.setGedcomX(json.gedcomx); 61 | } 62 | return this; 63 | }; 64 | 65 | /** 66 | * Set the GedcomX object 67 | * 68 | * @param {GedcomX} gedcomx 69 | * @return {AtomContent} this 70 | */ 71 | AtomContent.prototype.setGedcomX = function(gedcomx){ 72 | if(gedcomx){ 73 | this.gedcomx = GedcomX(gedcomx); 74 | } 75 | return this; 76 | }; 77 | 78 | /** 79 | * Get the GedcomX object 80 | * 81 | * @return {GedcomX} 82 | */ 83 | AtomContent.prototype.getGedcomX = function(){ 84 | return this.gedcomx; 85 | }; 86 | 87 | /** 88 | * Export the object as JSON 89 | * 90 | * @return {Object} JSON object 91 | */ 92 | AtomContent.prototype.toJSON = function(){ 93 | return this._toJSON(AtomCommon, AtomContent.jsonProps); 94 | }; 95 | 96 | GedcomX.AtomContent = AtomContent; 97 | 98 | }; -------------------------------------------------------------------------------- /src/atom/AtomGenerator.js: -------------------------------------------------------------------------------- 1 | module.exports = function(GedcomX){ 2 | 3 | var utils = require('../utils'), 4 | AtomCommon = require('./AtomCommon'); 5 | 6 | /** 7 | * The agent used to generate a feed 8 | * 9 | * @see {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/atom-model-specification.md#atom-json-media-type|GEDCOM X Atom JSON Spec} 10 | * @see {@link https://tools.ietf.org/html/rfc4287#section-4.2.4|RFC 4287} 11 | * 12 | * @class AtomGenerator 13 | * @extends AtomCommon 14 | * @param {Object} [json] 15 | */ 16 | var AtomGenerator = function(json){ 17 | 18 | // Protect against forgetting the new keyword when calling the constructor 19 | if(!(this instanceof AtomGenerator)){ 20 | return new AtomGenerator(json); 21 | } 22 | 23 | // If the given object is already an instance then just return it. DON'T copy it. 24 | if(AtomGenerator.isInstance(json)){ 25 | return json; 26 | } 27 | 28 | this.init(json); 29 | }; 30 | 31 | AtomGenerator.prototype = Object.create(AtomCommon.prototype); 32 | 33 | AtomGenerator._gedxClass = AtomGenerator.prototype._gedxClass = 'GedcomX.AtomGenerator'; 34 | 35 | AtomGenerator.jsonProps = [ 36 | 'uri', 37 | 'version', 38 | 'value' 39 | ]; 40 | 41 | /** 42 | * Check whether the given object is an instance of this class. 43 | * 44 | * @param {Object} obj 45 | * @returns {Boolean} 46 | */ 47 | AtomGenerator.isInstance = function(obj){ 48 | return utils.isInstance(obj, this._gedxClass); 49 | }; 50 | 51 | /** 52 | * Initialize from JSON 53 | * 54 | * @param {Object} 55 | * @return {AtomGenerator} this 56 | */ 57 | AtomGenerator.prototype.init = function(json){ 58 | 59 | AtomCommon.prototype.init.call(this, json); 60 | 61 | if(json){ 62 | this.setUri(json.uri); 63 | this.setVersion(json.version); 64 | this.setValue(json.value); 65 | } 66 | return this; 67 | }; 68 | 69 | /** 70 | * Set the uri 71 | * 72 | * @param {String} uri 73 | * @return {AtomGenerator} this 74 | */ 75 | AtomGenerator.prototype.setUri = function(uri){ 76 | this.uri = uri; 77 | return this; 78 | }; 79 | 80 | /** 81 | * Get the uri 82 | * 83 | * @return {String} this 84 | */ 85 | AtomGenerator.prototype.getUri = function(){ 86 | return this.uri; 87 | }; 88 | 89 | /** 90 | * Set the version 91 | * 92 | * @param {String} version 93 | * @return {AtomGenerator} this 94 | */ 95 | AtomGenerator.prototype.setVersion = function(version){ 96 | this.version = version; 97 | return this; 98 | }; 99 | 100 | /** 101 | * Get the version 102 | * 103 | * @return {String} this 104 | */ 105 | AtomGenerator.prototype.getVersion = function(){ 106 | return this.version; 107 | }; 108 | 109 | /** 110 | * Set the value 111 | * 112 | * @param {String} value 113 | * @return {AtomGenerator} this 114 | */ 115 | AtomGenerator.prototype.setValue = function(value){ 116 | this.value = value; 117 | return this; 118 | }; 119 | 120 | /** 121 | * Get the value 122 | * 123 | * @return {String} this 124 | */ 125 | AtomGenerator.prototype.getValue = function(){ 126 | return this.value; 127 | }; 128 | 129 | /** 130 | * Export the object as JSON 131 | * 132 | * @return {Object} JSON object 133 | */ 134 | AtomGenerator.prototype.toJSON = function(){ 135 | return this._toJSON(AtomCommon, AtomGenerator.jsonProps); 136 | }; 137 | 138 | GedcomX.AtomGenerator = AtomGenerator; 139 | 140 | }; -------------------------------------------------------------------------------- /src/atom/AtomPerson.js: -------------------------------------------------------------------------------- 1 | module.exports = function(GedcomX){ 2 | 3 | var utils = require('../utils'), 4 | AtomCommon = require('./AtomCommon'); 5 | 6 | /** 7 | * Common schema for atom authors and contributors. 8 | * 9 | * @see {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/atom-model-specification.md#atom-json-media-type|GEDCOM X Atom JSON Spec} 10 | * @see {@link https://tools.ietf.org/html/rfc4287#appendix-B|RFC 4287} 11 | * 12 | * @class AtomPerson 13 | * @extends AtomCommon 14 | * @param {Object} [json] 15 | */ 16 | var AtomPerson = function(json){ 17 | 18 | // Protect against forgetting the new keyword when calling the constructor 19 | if(!(this instanceof AtomPerson)){ 20 | return new AtomPerson(json); 21 | } 22 | 23 | // If the given object is already an instance then just return it. DON'T copy it. 24 | if(AtomPerson.isInstance(json)){ 25 | return json; 26 | } 27 | 28 | this.init(json); 29 | }; 30 | 31 | AtomPerson.prototype = Object.create(AtomCommon.prototype); 32 | 33 | AtomPerson._gedxClass = AtomPerson.prototype._gedxClass = 'GedcomX.AtomPerson'; 34 | 35 | AtomPerson.jsonProps = [ 36 | 'uri', 37 | 'name', 38 | 'email' 39 | ]; 40 | 41 | /** 42 | * Check whether the given object is an instance of this class. 43 | * 44 | * @param {Object} obj 45 | * @returns {Boolean} 46 | */ 47 | AtomPerson.isInstance = function(obj){ 48 | return utils.isInstance(obj, this._gedxClass); 49 | }; 50 | 51 | /** 52 | * Initialize from JSON 53 | * 54 | * @param {Object} 55 | * @return {AtomPerson} this 56 | */ 57 | AtomPerson.prototype.init = function(json){ 58 | 59 | AtomCommon.prototype.init.call(this, json); 60 | 61 | if(json){ 62 | this.setUri(json.uri); 63 | this.setName(json.name); 64 | this.setEmail(json.email); 65 | } 66 | return this; 67 | }; 68 | 69 | /** 70 | * Set the uri 71 | * 72 | * @param {String} uri 73 | * @return {AtomPerson} this 74 | */ 75 | AtomPerson.prototype.setUri = function(uri){ 76 | this.uri = uri; 77 | return this; 78 | }; 79 | 80 | /** 81 | * Get the uri 82 | * 83 | * @return {String} this 84 | */ 85 | AtomPerson.prototype.getUri = function(){ 86 | return this.uri; 87 | }; 88 | 89 | /** 90 | * Set the name 91 | * 92 | * @param {String} name 93 | * @return {AtomPerson} this 94 | */ 95 | AtomPerson.prototype.setName = function(name){ 96 | this.name = name; 97 | return this; 98 | }; 99 | 100 | /** 101 | * Get the name 102 | * 103 | * @return {String} this 104 | */ 105 | AtomPerson.prototype.getName = function(){ 106 | return this.name; 107 | }; 108 | 109 | /** 110 | * Set the email 111 | * 112 | * @param {String} email 113 | * @return {AtomPerson} this 114 | */ 115 | AtomPerson.prototype.setEmail = function(email){ 116 | this.email = email; 117 | return this; 118 | }; 119 | 120 | /** 121 | * Get the name 122 | * 123 | * @return {String} this 124 | */ 125 | AtomPerson.prototype.getEmail = function(){ 126 | return this.email; 127 | }; 128 | 129 | /** 130 | * Export the object as JSON 131 | * 132 | * @return {Object} JSON object 133 | */ 134 | AtomPerson.prototype.toJSON = function(){ 135 | return this._toJSON(AtomCommon, AtomPerson.jsonProps); 136 | }; 137 | 138 | GedcomX.AtomPerson = AtomPerson; 139 | 140 | }; -------------------------------------------------------------------------------- /src/atom/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Setup Gedcom X Atom Extensions 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Add new classes 7 | require('./AtomCategory')(GedcomX); 8 | require('./AtomContent')(GedcomX); 9 | require('./AtomFeed')(GedcomX); 10 | require('./AtomGenerator')(GedcomX); 11 | require('./AtomPerson')(GedcomX); 12 | require('./AtomSource')(GedcomX); 13 | require('./AtomEntry')(GedcomX); 14 | 15 | }; -------------------------------------------------------------------------------- /src/core/Coverage.js: -------------------------------------------------------------------------------- 1 | var GedcomX = require('../'), 2 | utils = require('../utils'); 3 | 4 | /** 5 | * A description of the spatial and temporal coverage of a resource. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#coverage|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends ExtensibleData 11 | * @apram {Object} [json] 12 | */ 13 | var Coverage = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof Coverage)){ 17 | return new Coverage(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(Coverage.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | Coverage.prototype = Object.create(GedcomX.ExtensibleData.prototype); 29 | 30 | Coverage._gedxClass = Coverage.prototype._gedxClass = 'GedcomX.Coverage'; 31 | 32 | Coverage.jsonProps = [ 33 | 'spatial', 34 | 'temporal' 35 | ]; 36 | 37 | /** 38 | * Check whether the given object is an instance of this class. 39 | * 40 | * @param {Object} obj 41 | * @returns {Boolean} 42 | */ 43 | Coverage.isInstance = function(obj){ 44 | return utils.isInstance(obj, this._gedxClass); 45 | }; 46 | 47 | /** 48 | * Initialize from JSON 49 | * 50 | * @param {Object} 51 | * @return {Coverage} this 52 | */ 53 | Coverage.prototype.init = function(json){ 54 | 55 | GedcomX.ExtensibleData.prototype.init.call(this, json); 56 | 57 | if(json){ 58 | this.setSpatial(json.spatial); 59 | this.setTemporal(json.temporal); 60 | } 61 | return this; 62 | }; 63 | 64 | /** 65 | * Get the spatial coverage 66 | * 67 | * @returns {PlaceReference} 68 | */ 69 | Coverage.prototype.getSpatial = function(){ 70 | return this.spatial; 71 | }; 72 | 73 | /** 74 | * Set the spatial coverage 75 | * 76 | * @param {PlaceReference} spatial 77 | * @returns {Coverage} 78 | */ 79 | Coverage.prototype.setSpatial = function(spatial){ 80 | if(spatial){ 81 | this.spatial = GedcomX.PlaceReference(spatial); 82 | } 83 | return this; 84 | }; 85 | 86 | /** 87 | * Get the temporal coverage 88 | * 89 | * @returns {Date} 90 | */ 91 | Coverage.prototype.getTemporal = function(){ 92 | return this.temporal; 93 | }; 94 | 95 | /** 96 | * Set the temporal coverage 97 | * 98 | * @param {Date} temporal 99 | * @returns {Coverage} 100 | */ 101 | Coverage.prototype.setTemporal = function(temporal){ 102 | if(temporal){ 103 | this.temporal = GedcomX.Date(temporal); 104 | } 105 | return this; 106 | }; 107 | 108 | /** 109 | * Export the object as JSON 110 | * 111 | * @return {Object} JSON object 112 | */ 113 | Coverage.prototype.toJSON = function(){ 114 | return this._toJSON(GedcomX.ExtensibleData, Coverage.jsonProps); 115 | }; 116 | 117 | module.exports = Coverage; -------------------------------------------------------------------------------- /src/core/Date.js: -------------------------------------------------------------------------------- 1 | var GedcomX = require('../'), 2 | utils = require('../utils'); 3 | 4 | /** 5 | * A date. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#conclusion-date|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends ExtensibleData 11 | * @param {Object} [json] 12 | * @alias Date 13 | */ 14 | var GDate = function(json){ 15 | 16 | // Protect against forgetting the new keyword when calling the constructor 17 | if(!(this instanceof GDate)){ 18 | return new GDate(json); 19 | } 20 | 21 | // If the given object is already an instance then just return it. DON'T copy it. 22 | if(GDate.isInstance(json)){ 23 | return json; 24 | } 25 | 26 | this.init(json); 27 | }; 28 | 29 | GDate.prototype = Object.create(GedcomX.ExtensibleData.prototype); 30 | 31 | GDate._gedxClass = GDate.prototype._gedxClass = 'GedcomX.Date'; 32 | 33 | GDate.jsonProps = [ 34 | 'original', 35 | 'formal' 36 | ]; 37 | 38 | /** 39 | * Check whether the given object is an instance of this class. 40 | * 41 | * @param {Object} obj 42 | * @returns {Boolean} 43 | */ 44 | GDate.isInstance = function(obj){ 45 | return utils.isInstance(obj, this._gedxClass); 46 | }; 47 | 48 | /** 49 | * Initialize from JSON 50 | * 51 | * @param {Object} 52 | * @return {Date} this 53 | */ 54 | GDate.prototype.init = function(json){ 55 | 56 | GedcomX.ExtensibleData.prototype.init.call(this, json); 57 | 58 | if(json){ 59 | this.setOriginal(json.original); 60 | this.setFormal(json.formal); 61 | } 62 | return this; 63 | }; 64 | 65 | /** 66 | * Get the original date value 67 | * 68 | * @returns {String} original 69 | */ 70 | GDate.prototype.getOriginal = function(){ 71 | return this.original; 72 | }; 73 | 74 | /** 75 | * Set the original date value 76 | * 77 | * @param {String} original 78 | * @returns {Date} This instance. 79 | */ 80 | GDate.prototype.setOriginal = function(original){ 81 | this.original = original; 82 | return this; 83 | }; 84 | 85 | /** 86 | * Get the formal date value 87 | * 88 | * @returns {String} 89 | */ 90 | GDate.prototype.getFormal = function(){ 91 | return this.formal; 92 | }; 93 | 94 | /** 95 | * Set the formal date value 96 | * 97 | * @param {String} formal 98 | * @returns {Date} This instance. 99 | */ 100 | GDate.prototype.setFormal = function(formal){ 101 | this.formal = formal; 102 | return this; 103 | }; 104 | 105 | /** 106 | * Export the object as JSON 107 | * 108 | * @return {Object} JSON object 109 | */ 110 | GDate.prototype.toJSON = function(){ 111 | return this._toJSON(GedcomX.ExtensibleData, GDate.jsonProps); 112 | }; 113 | 114 | module.exports = GDate; -------------------------------------------------------------------------------- /src/core/Event.js: -------------------------------------------------------------------------------- 1 | var GedcomX = require('../'), 2 | utils = require('../utils'); 3 | 4 | /** 5 | * An event. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#event|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends Subject 11 | * @param {Object} [json] 12 | */ 13 | var Event = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof Event)){ 17 | return new Event(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(Event.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | Event.prototype = Object.create(GedcomX.Subject.prototype); 29 | 30 | Event._gedxClass = Event.prototype._gedxClass = 'GedcomX.Event'; 31 | 32 | Event.jsonProps = [ 33 | 'type', 34 | 'date', 35 | 'place', 36 | 'roles' 37 | ]; 38 | 39 | /** 40 | * Check whether the given object is an instance of this class. 41 | * 42 | * @param {Object} obj 43 | * @returns {Boolean} 44 | */ 45 | Event.isInstance = function(obj){ 46 | return utils.isInstance(obj, this._gedxClass); 47 | }; 48 | 49 | /** 50 | * Initialize from JSON 51 | * 52 | * @param {Object} 53 | * @return {Event} this 54 | */ 55 | Event.prototype.init = function(json){ 56 | 57 | GedcomX.Subject.prototype.init.call(this, json); 58 | 59 | if(json){ 60 | this.setType(json.type); 61 | this.setDate(json.date); 62 | this.setPlace(json.place); 63 | this.setRoles(json.roles); 64 | } 65 | return this; 66 | }; 67 | 68 | /** 69 | * Get the type 70 | * 71 | * @returns {String} 72 | */ 73 | Event.prototype.getType = function(){ 74 | return this.type; 75 | }; 76 | 77 | /** 78 | * Set the type 79 | * 80 | * @param {String} type 81 | * @returns {Event} 82 | */ 83 | Event.prototype.setType = function(type){ 84 | this.type = type; 85 | return this; 86 | }; 87 | 88 | /** 89 | * Get the date 90 | * 91 | * @returns {Date} 92 | */ 93 | Event.prototype.getDate = function(){ 94 | return this.date; 95 | }; 96 | 97 | /** 98 | * Set the date 99 | * 100 | * @param {Date} date 101 | * @returns {Event} 102 | */ 103 | Event.prototype.setDate = function(date){ 104 | if(date){ 105 | this.date = GedcomX.Date(date); 106 | } 107 | return this; 108 | }; 109 | 110 | /** 111 | * Get the place 112 | * 113 | * @returns {PlaceReference} 114 | */ 115 | Event.prototype.getPlace = function(){ 116 | return this.place; 117 | }; 118 | 119 | /** 120 | * Set the place 121 | * 122 | * @param {PlaceReference} place 123 | * @returns {Event} 124 | */ 125 | Event.prototype.setPlace = function(place){ 126 | if(place){ 127 | this.place = GedcomX.PlaceReference(place); 128 | } 129 | return this; 130 | }; 131 | 132 | /** 133 | * Get the roles 134 | * 135 | * @returns {EventRole[]} 136 | */ 137 | Event.prototype.getRoles = function(){ 138 | return this.roles || []; 139 | }; 140 | 141 | /** 142 | * Set the roles 143 | * 144 | * @param {EventRole[]|Object[]} roles 145 | * @returns {Event} 146 | */ 147 | Event.prototype.setRoles = function(roles){ 148 | return this._setArray(roles, 'roles', 'addRole'); 149 | }; 150 | 151 | /** 152 | * Add a role 153 | * 154 | * @param {EventRole|Object} role 155 | * @returns {Event} 156 | */ 157 | Event.prototype.addRole = function(role){ 158 | return this._arrayPush(role, 'roles', GedcomX.EventRole); 159 | }; 160 | 161 | /** 162 | * Export the object as JSON 163 | * 164 | * @return {Object} JSON object 165 | */ 166 | Event.prototype.toJSON = function(){ 167 | return this._toJSON(GedcomX.Subject, Event.jsonProps); 168 | }; 169 | 170 | module.exports = Event; -------------------------------------------------------------------------------- /src/core/EventRole.js: -------------------------------------------------------------------------------- 1 | var GedcomX = require('../'), 2 | utils = require('../utils'); 3 | 4 | /** 5 | * A role that a specific person plays in an event. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#conclusion-event-role|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends Conclusion 11 | * @param {Object} [json] 12 | */ 13 | var EventRole = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof EventRole)){ 17 | return new EventRole(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(GedcomX.Conclusion.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | EventRole.prototype = Object.create(GedcomX.Conclusion.prototype); 29 | 30 | EventRole._gedxClass = EventRole.prototype._gedxClass = 'GedcomX.Conclusion'; 31 | 32 | EventRole.jsonProps = [ 33 | 'person', 34 | 'type', 35 | 'details' 36 | ]; 37 | 38 | /** 39 | * Check whether the given object is an instance of this class. 40 | * 41 | * @param {Object} obj 42 | * @returns {Boolean} 43 | */ 44 | EventRole.isInstance = function(obj){ 45 | return utils.isInstance(obj, this._gedxClass); 46 | }; 47 | 48 | /** 49 | * Initialize from JSON 50 | * 51 | * @param {Object} 52 | * @return {Conclusion} this 53 | */ 54 | EventRole.prototype.init = function(json){ 55 | 56 | GedcomX.Conclusion.prototype.init.call(this, json); 57 | 58 | if(json){ 59 | this.setPerson(json.person); 60 | this.setType(json.type); 61 | this.setDetails(json.details); 62 | } 63 | return this; 64 | }; 65 | 66 | /** 67 | * Get the person 68 | * 69 | * @returns {ResourceReference} 70 | */ 71 | EventRole.prototype.getPerson = function(){ 72 | return this.person; 73 | }; 74 | 75 | /** 76 | * Set the person 77 | * 78 | * @param {ResourceReference} person 79 | * @returns {EventRole} 80 | */ 81 | EventRole.prototype.setPerson = function(person){ 82 | if(person){ 83 | this.person = GedcomX.ResourceReference(person); 84 | } 85 | return this; 86 | }; 87 | 88 | /** 89 | * Get the type 90 | * 91 | * @returns {String} 92 | */ 93 | EventRole.prototype.getType = function(){ 94 | return this.type; 95 | }; 96 | 97 | /** 98 | * Set the type 99 | * 100 | * @param {String} type 101 | * @returns {EventRole} 102 | */ 103 | EventRole.prototype.setType = function(type){ 104 | this.type = type; 105 | return this; 106 | }; 107 | 108 | /** 109 | * Get the details 110 | * 111 | * @returns {String} 112 | */ 113 | EventRole.prototype.getDetails = function(){ 114 | return this.details; 115 | }; 116 | 117 | /** 118 | * Set the details 119 | * 120 | * @param {String} details 121 | * @returns {EventRole} 122 | */ 123 | EventRole.prototype.setDetails = function(details){ 124 | this.details = details; 125 | return this; 126 | }; 127 | 128 | /** 129 | * Export the object as JSON 130 | * 131 | * @return {Object} JSON object 132 | */ 133 | EventRole.prototype.toJSON = function(){ 134 | return this._toJSON(GedcomX.Conclusion, EventRole.jsonProps); 135 | }; 136 | 137 | module.exports = EventRole; -------------------------------------------------------------------------------- /src/core/EvidenceReference.js: -------------------------------------------------------------------------------- 1 | var GedcomX = require('../'), 2 | utils = require('../utils'); 3 | 4 | /** 5 | * A generic reference to a resource. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#evidence-reference|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends ResourceReference 11 | * @param {Object} [json] 12 | */ 13 | var EvidenceReference = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof EvidenceReference)){ 17 | return new EvidenceReference(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(GedcomX.ResourceReference.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | EvidenceReference.prototype = Object.create(GedcomX.ResourceReference.prototype); 29 | 30 | EvidenceReference._gedxClass = EvidenceReference.prototype._gedxClass = 'GedcomX.ResourceReference'; 31 | 32 | EvidenceReference.jsonProps = [ 33 | 'attribution' 34 | ]; 35 | 36 | /** 37 | * Check whether the given object is an instance of this class. 38 | * 39 | * @param {Object} obj 40 | * @returns {Boolean} 41 | */ 42 | EvidenceReference.isInstance = function(obj){ 43 | return utils.isInstance(obj, this._gedxClass); 44 | }; 45 | 46 | /** 47 | * Initialize from JSON 48 | * 49 | * @param {Object} 50 | * @return {EvidenceReference} this 51 | */ 52 | EvidenceReference.prototype.init = function(json){ 53 | 54 | GedcomX.ResourceReference.prototype.init.call(this, json); 55 | 56 | if(json){ 57 | this.setAttribution(json.attribution); 58 | } 59 | return this; 60 | }; 61 | 62 | /** 63 | * Get the attribution. 64 | * 65 | * @returns {Attribution} 66 | */ 67 | EvidenceReference.prototype.getAttribution = function(){ 68 | return this.attribution; 69 | }; 70 | 71 | /** 72 | * Set the attribution 73 | * 74 | * @param {Object|Attribution} attribution 75 | * @returns {EvidenceReference} This instance. 76 | */ 77 | EvidenceReference.prototype.setAttribution = function(attribution){ 78 | if(attribution){ 79 | this.attribution = new GedcomX.Attribution(attribution); 80 | } 81 | return this; 82 | }; 83 | 84 | /** 85 | * Export the object as JSON 86 | * 87 | * @return {Object} JSON object 88 | */ 89 | EvidenceReference.prototype.toJSON = function(){ 90 | return this._toJSON(GedcomX.ResourceReference, EvidenceReference.jsonProps); 91 | }; 92 | 93 | module.exports = EvidenceReference; -------------------------------------------------------------------------------- /src/core/ExtensibleData.js: -------------------------------------------------------------------------------- 1 | var utils = require('../utils'), 2 | Base = require('../Base'); 3 | 4 | /** 5 | * A set of data that supports extension elements. 6 | * 7 | * @class 8 | * @extends Base 9 | * @param {Object} [json] 10 | */ 11 | var ExtensibleData = function(json){ 12 | 13 | // Protect against forgetting the new keyword when calling the constructor 14 | if(!(this instanceof ExtensibleData)){ 15 | return new ExtensibleData(json); 16 | } 17 | 18 | // If the given object is already an instance then just return it. DON'T copy it. 19 | if(ExtensibleData.isInstance(json)){ 20 | return json; 21 | } 22 | 23 | this.init(json); 24 | }; 25 | 26 | ExtensibleData.prototype = Object.create(Base.prototype); 27 | 28 | ExtensibleData._gedxClass = ExtensibleData.prototype._gedxClass = 'GedcomX.ExtensibleData'; 29 | 30 | ExtensibleData.jsonProps = ['id']; 31 | 32 | /** 33 | * Check whether the given object is an instance of this class. 34 | * 35 | * @param {Object} obj 36 | * @returns {Boolean} 37 | */ 38 | ExtensibleData.isInstance = function(obj){ 39 | return utils.isInstance(obj, this._gedxClass); 40 | }; 41 | 42 | /** 43 | * Initialize from JSON 44 | * 45 | * @param {Object} 46 | * @return {ExtensibleData} this 47 | */ 48 | ExtensibleData.prototype.init = function(json){ 49 | 50 | Base.prototype.init.call(this, json); 51 | 52 | if(json){ 53 | this.setId(json.id); 54 | } 55 | return this; 56 | }; 57 | 58 | /** 59 | * Get the object's id. 60 | * 61 | * @returns {String} Id 62 | */ 63 | ExtensibleData.prototype.getId = function(){ 64 | return this.id; 65 | }; 66 | 67 | /** 68 | * Set the object's id. 69 | * 70 | * @param {String} id 71 | * @return {ExtensibleData} This object, for chaining. 72 | */ 73 | ExtensibleData.prototype.setId = function(id){ 74 | this.id = id; 75 | return this; 76 | }; 77 | 78 | /** 79 | * Export the object as JSON 80 | * 81 | * @return {Object} JSON object 82 | */ 83 | ExtensibleData.prototype.toJSON = function(){ 84 | return this._toJSON(Base, ExtensibleData.jsonProps); 85 | }; 86 | 87 | module.exports = ExtensibleData; -------------------------------------------------------------------------------- /src/core/Gender.js: -------------------------------------------------------------------------------- 1 | var GedcomX = require('../'), 2 | utils = require('../utils'); 3 | 4 | /** 5 | * A gender conclusion. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#gender-conclusion|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends Conclusion 11 | * @param {Object} [json] 12 | */ 13 | var Gender = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof Gender)){ 17 | return new Gender(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(Gender.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | Gender.prototype = Object.create(GedcomX.Conclusion.prototype); 29 | 30 | Gender._gedxClass = Gender.prototype._gedxClass = 'GedcomX.Gender'; 31 | 32 | Gender.jsonProps = ['type']; 33 | 34 | /** 35 | * Check whether the given object is an instance of this class. 36 | * 37 | * @param {Object} obj 38 | * @returns {Boolean} 39 | */ 40 | Gender.isInstance = function(obj){ 41 | return utils.isInstance(obj, this._gedxClass); 42 | }; 43 | 44 | /** 45 | * Initialize from JSON 46 | * 47 | * @param {Object} 48 | * @return {Gender} this 49 | */ 50 | Gender.prototype.init = function(json){ 51 | 52 | GedcomX.Conclusion.prototype.init.call(this, json); 53 | 54 | if(json){ 55 | this.setType(json.type); 56 | } 57 | return this; 58 | }; 59 | 60 | /** 61 | * Get the gender type 62 | * 63 | * @returns {String} gender 64 | */ 65 | Gender.prototype.getType = function(){ 66 | return this.type; 67 | }; 68 | 69 | /** 70 | * Set the gender type 71 | * 72 | * @param {String} gender 73 | * @returns {Gender} This instance 74 | */ 75 | Gender.prototype.setType = function(gender){ 76 | this.type = gender; 77 | return this; 78 | }; 79 | 80 | /** 81 | * Export the object as JSON 82 | * 83 | * @return {Object} JSON object 84 | */ 85 | Gender.prototype.toJSON = function(){ 86 | return this._toJSON(GedcomX.Conclusion, Gender.jsonProps); 87 | }; 88 | 89 | module.exports = Gender; -------------------------------------------------------------------------------- /src/core/Identifiers.js: -------------------------------------------------------------------------------- 1 | var utils = require('../utils'), 2 | Base = require('../Base'); 3 | 4 | /** 5 | * Manage the set of identifers for an object. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#identifier-type|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends Base 11 | * @param {Object} [json] 12 | */ 13 | var Identifiers = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof Identifiers)){ 17 | return new Identifiers(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(Identifiers.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | Base.prototype = Object.create(Base.prototype); 29 | 30 | Identifiers._gedxClass = Identifiers.prototype._gedxClass = 'GedcomX.Identifiers'; 31 | 32 | /** 33 | * Check whether the given object is an instance of this class. 34 | * 35 | * @param {Object} obj 36 | * @returns {Boolean} 37 | */ 38 | Identifiers.isInstance = function(obj){ 39 | return utils.isInstance(obj, this._gedxClass); 40 | }; 41 | 42 | /** 43 | * Initialize from JSON 44 | * 45 | * @param {Object} 46 | * @return {Identifiers} this 47 | */ 48 | Identifiers.prototype.init = function(json){ 49 | 50 | Base.prototype.init.call(this, json); 51 | 52 | this.identifiers = {}; 53 | 54 | if(json){ 55 | this.identifiers = json; 56 | 57 | // The spec allows for types with single values to "forgo the array and use 58 | // a single string" but that's a pain to keep track of so we're going to 59 | // convert all single strings into arrays 60 | for(var a in this.identifiers){ 61 | if(this.identifiers.hasOwnProperty(a) && !Array.isArray(this.identifiers[a])){ 62 | this.identifiers[a] = [ this.identifiers[a] ]; 63 | } 64 | } 65 | } 66 | return this; 67 | }; 68 | 69 | /** 70 | * Get the values for a given type 71 | * 72 | * @param {String=} type If not specified then values with no associated type 73 | * are returned. 74 | * @return {String[]} 75 | */ 76 | Identifiers.prototype.getValues = function(type){ 77 | if(typeof type === 'undefined'){ 78 | type = '$'; 79 | } 80 | return this.identifiers[type] || []; 81 | }; 82 | 83 | /** 84 | * Set the values for a given type 85 | * 86 | * @param {String[]} values 87 | * @param {String=} type 88 | */ 89 | Identifiers.prototype.setValues = function(values, type){ 90 | if(typeof type === 'undefined'){ 91 | type = '$'; 92 | } 93 | if(Array.isArray(values)){ 94 | this.identifiers[type] = values; 95 | } 96 | return this; 97 | }; 98 | 99 | /** 100 | * Add a value for a given type 101 | * 102 | * @param {String} value 103 | * @param {String=} type 104 | */ 105 | Identifiers.prototype.addValue = function(value, type){ 106 | if(typeof type === 'undefined'){ 107 | type = '$'; 108 | } 109 | if(!Array.isArray(this.identifiers[type])){ 110 | this.identifiers[type] = []; 111 | } 112 | this.identifiers[type].push(value); 113 | return this; 114 | }; 115 | 116 | /** 117 | * Export the object as JSON 118 | * 119 | * @return {Object} JSON object 120 | */ 121 | Identifiers.prototype.toJSON = function(){ 122 | return this.identifiers; 123 | }; 124 | 125 | module.exports = Identifiers; -------------------------------------------------------------------------------- /src/core/Name.js: -------------------------------------------------------------------------------- 1 | var GedcomX = require('../'), 2 | utils = require('../utils'); 3 | 4 | /** 5 | * A name. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#name-conclusion|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends Conclusion 11 | * @param {Object} [json] 12 | */ 13 | var Name = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof Name)){ 17 | return new Name(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(Name.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | Name.prototype = Object.create(GedcomX.Conclusion.prototype); 29 | 30 | Name._gedxClass = Name.prototype._gedxClass = 'GedcomX.Name'; 31 | 32 | Name.jsonProps = [ 33 | 'type', 34 | 'date', 35 | 'nameForms' 36 | ]; 37 | 38 | /** 39 | * Check whether the given object is an instance of this class. 40 | * 41 | * @param {Object} obj 42 | * @returns {Boolean} 43 | */ 44 | Name.isInstance = function(obj){ 45 | return utils.isInstance(obj, this._gedxClass); 46 | }; 47 | 48 | /** 49 | * Initialize from JSON 50 | * 51 | * @param {Object} 52 | * @return {Name} this 53 | */ 54 | Name.prototype.init = function(json){ 55 | 56 | GedcomX.Conclusion.prototype.init.call(this, json); 57 | 58 | if(json){ 59 | this.setType(json.type); 60 | this.setDate(json.date); 61 | this.setNameForms(json.nameForms); 62 | } 63 | return this; 64 | }; 65 | 66 | /** 67 | * Get the name type 68 | * 69 | * @returns {String} type 70 | */ 71 | Name.prototype.getType = function(){ 72 | return this.type; 73 | }; 74 | 75 | /** 76 | * Set the name type 77 | * 78 | * @param {String} type 79 | * @returns {Name} This instance 80 | */ 81 | Name.prototype.setType = function(type){ 82 | this.type = type; 83 | return this; 84 | }; 85 | 86 | /** 87 | * Get the date 88 | * 89 | * @returns {Date} date 90 | */ 91 | Name.prototype.getDate = function(){ 92 | return this.date; 93 | }; 94 | 95 | /** 96 | * Set the date 97 | * 98 | * @param {Date|Object} date 99 | * @returns {Fact} This instance 100 | */ 101 | Name.prototype.setDate = function(date){ 102 | if(date){ 103 | this.date = GedcomX.Date(date); 104 | } 105 | return this; 106 | }; 107 | 108 | /** 109 | * Get the name forms 110 | * 111 | * @return {NameForm[]} 112 | */ 113 | Name.prototype.getNameForms = function(){ 114 | return this.nameForms || []; 115 | }; 116 | 117 | /** 118 | * Set the name forms 119 | * 120 | * @param {NameForm[]|Object[]} nameForms 121 | * @returns {Name} This instance 122 | */ 123 | Name.prototype.setNameForms = function(nameForms){ 124 | return this._setArray(nameForms, 'nameForms', 'addNameForm'); 125 | }; 126 | 127 | /** 128 | * Add a name form 129 | * 130 | * @param {NameForm|Object} nameForm 131 | * @returns {Name} This instance 132 | */ 133 | Name.prototype.addNameForm = function(nameForm){ 134 | return this._arrayPush(nameForm, 'nameForms', GedcomX.NameForm); 135 | }; 136 | 137 | /** 138 | * Export the object as JSON 139 | * 140 | * @return {Object} JSON object 141 | */ 142 | Name.prototype.toJSON = function(){ 143 | return this._toJSON(GedcomX.Conclusion, Name.jsonProps); 144 | }; 145 | 146 | module.exports = Name; -------------------------------------------------------------------------------- /src/core/NamePart.js: -------------------------------------------------------------------------------- 1 | var GedcomX = require('../'), 2 | utils = require('../utils'); 3 | 4 | /** 5 | * A part of a name. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#name-part|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends ExtensibleData 11 | * @param {Object} [json] 12 | */ 13 | var NamePart = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof NamePart)){ 17 | return new NamePart(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(NamePart.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | NamePart.prototype = Object.create(GedcomX.ExtensibleData.prototype); 29 | 30 | NamePart._gedxClass = NamePart.prototype._gedxClass = 'GedcomX.NamePart'; 31 | 32 | NamePart.jsonProps = [ 33 | 'type', 34 | 'value', 35 | 'qualifiers' 36 | ]; 37 | 38 | /** 39 | * Check whether the given object is an instance of this class. 40 | * 41 | * @param {Object} obj 42 | * @returns {Boolean} 43 | */ 44 | NamePart.isInstance = function(obj){ 45 | return utils.isInstance(obj, this._gedxClass); 46 | }; 47 | 48 | /** 49 | * Initialize from JSON 50 | * 51 | * @param {Object} 52 | * @return {NamePart} this 53 | */ 54 | NamePart.prototype.init = function(json){ 55 | 56 | GedcomX.ExtensibleData.prototype.init.call(this, json); 57 | 58 | if(json){ 59 | this.setValue(json.value); 60 | this.setType(json.type); 61 | this.setQualifiers(json.qualifiers); 62 | } 63 | return this; 64 | }; 65 | 66 | /** 67 | * Get the type 68 | * 69 | * @returns {String} type 70 | */ 71 | NamePart.prototype.getType = function(){ 72 | return this.type; 73 | }; 74 | 75 | /** 76 | * Set the type 77 | * 78 | * @param {String} type 79 | * @returns {NamePart} This instance 80 | */ 81 | NamePart.prototype.setType = function(type){ 82 | this.type = type; 83 | return this; 84 | }; 85 | 86 | /** 87 | * Get the value 88 | * 89 | * @returns {String} 90 | */ 91 | NamePart.prototype.getValue = function(){ 92 | return this.value; 93 | }; 94 | 95 | /** 96 | * Set the value 97 | * 98 | * @param {String} value 99 | * @returns {NamePart} This instance 100 | */ 101 | NamePart.prototype.setValue = function(value){ 102 | this.value = value; 103 | return this; 104 | }; 105 | 106 | /** 107 | * Get qualifiers 108 | * 109 | * @return {Qualifer[]} 110 | */ 111 | NamePart.prototype.getQualifiers = function(){ 112 | return this.qualifiers || []; 113 | }; 114 | 115 | /** 116 | * Set the qualifiers 117 | * 118 | * @param {Qualifer[]|Object[]} qualifiers 119 | * @returns {NamePart} This instance 120 | */ 121 | NamePart.prototype.setQualifiers = function(qualifiers){ 122 | return this._setArray(qualifiers, 'qualifiers', 'addQualifier'); 123 | }; 124 | 125 | /** 126 | * Add a qualifier 127 | * 128 | * @param {Qualifier|Object} qualifier 129 | * @returns {NamePart} This instance 130 | */ 131 | NamePart.prototype.addQualifier = function(qualifier){ 132 | return this._arrayPush(qualifier, 'qualifiers', GedcomX.Qualifier); 133 | }; 134 | 135 | /** 136 | * Export the object as JSON 137 | * 138 | * @return {Object} JSON object 139 | */ 140 | NamePart.prototype.toJSON = function(){ 141 | return this._toJSON(GedcomX.ExtensibleData, NamePart.jsonProps); 142 | }; 143 | 144 | module.exports = NamePart; -------------------------------------------------------------------------------- /src/core/Note.js: -------------------------------------------------------------------------------- 1 | var GedcomX = require('../'), 2 | utils = require('../utils'); 3 | 4 | /** 5 | * A note about a resource. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#note|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends ExtensibleData 11 | * @param {Object} [json] 12 | */ 13 | var Note = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof Note)){ 17 | return new Note(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(Note.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | Note.prototype = Object.create(GedcomX.ExtensibleData.prototype); 29 | 30 | Note._gedxClass = Note.prototype._gedxClass = 'GedcomX.Note'; 31 | 32 | Note.jsonProps = [ 33 | 'lang', 34 | 'subject', 35 | 'text', 36 | 'attribution' 37 | ]; 38 | 39 | /** 40 | * Check whether the given object is an instance of this class. 41 | * 42 | * @param {Object} obj 43 | * @returns {Boolean} 44 | */ 45 | Note.isInstance = function(obj){ 46 | return utils.isInstance(obj, this._gedxClass); 47 | }; 48 | 49 | /** 50 | * Initialize from JSON 51 | * 52 | * @param {Object} 53 | * @return {Note} this 54 | */ 55 | Note.prototype.init = function(json){ 56 | 57 | GedcomX.ExtensibleData.prototype.init.call(this, json); 58 | 59 | if(json){ 60 | this.setLang(json.lang); 61 | this.setSubject(json.subject); 62 | this.setText(json.text); 63 | this.setAttribution(json.attribution); 64 | } 65 | return this; 66 | }; 67 | 68 | /** 69 | * Get the language identifier. 70 | * 71 | * @returns {String} lang 72 | */ 73 | Note.prototype.getLang = function(){ 74 | return this.lang; 75 | }; 76 | 77 | /** 78 | * Set the language identifier. 79 | * 80 | * @param {String} lang 81 | * @returns {Note} This instance. 82 | */ 83 | Note.prototype.setLang = function(lang){ 84 | this.lang = lang; 85 | return this; 86 | }; 87 | 88 | /** 89 | * Get the subject. 90 | */ 91 | Note.prototype.getSubject = function(){ 92 | return this.subject; 93 | }; 94 | 95 | /** 96 | * Set the subject. 97 | * 98 | * @param {String} subject 99 | * @returns {Note} This note. 100 | */ 101 | Note.prototype.setSubject = function(subject){ 102 | this.subject = subject; 103 | return this; 104 | }; 105 | 106 | /** 107 | * Get the text. 108 | * 109 | * @returns {String} text 110 | */ 111 | Note.prototype.getText = function(){ 112 | return this.text; 113 | }; 114 | 115 | /** 116 | * Set the text. 117 | * 118 | * @param {String} text 119 | * @returns {Note} This note. 120 | */ 121 | Note.prototype.setText = function(text){ 122 | this.text = text; 123 | return this; 124 | }; 125 | 126 | /** 127 | * Get the attribution. 128 | * 129 | * @returns {Attribution} 130 | */ 131 | Note.prototype.getAttribution = function(){ 132 | return this.attribution; 133 | }; 134 | 135 | /** 136 | * Set the attribution 137 | * 138 | * @param {Object|Attribution} attribution 139 | * @returns {Note} This instance. 140 | */ 141 | Note.prototype.setAttribution = function(attribution){ 142 | if(attribution){ 143 | this.attribution = new GedcomX.Attribution(attribution); 144 | } 145 | return this; 146 | }; 147 | 148 | /** 149 | * Export the object as JSON 150 | * 151 | * @return {Object} JSON object 152 | */ 153 | Note.prototype.toJSON = function(){ 154 | return this._toJSON(GedcomX.ExtensibleData, Note.jsonProps); 155 | }; 156 | 157 | module.exports = Note; -------------------------------------------------------------------------------- /src/core/OnlineAccount.js: -------------------------------------------------------------------------------- 1 | var GedcomX = require('../'), 2 | utils = require('../utils'); 3 | 4 | /** 5 | * An online account for a web application. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#online-account|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends ExtensibleData 11 | * @param {Object} [json] 12 | */ 13 | var OnlineAccount = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof OnlineAccount)){ 17 | return new OnlineAccount(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(OnlineAccount.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | OnlineAccount.prototype = Object.create(GedcomX.ExtensibleData.prototype); 29 | 30 | OnlineAccount._gedxClass = OnlineAccount.prototype._gedxClass = 'GedcomX.OnlineAccount'; 31 | 32 | OnlineAccount.jsonProps = [ 33 | 'serviceHomepage', 34 | 'accountName' 35 | ]; 36 | 37 | /** 38 | * Check whether the given object is an instance of this class. 39 | * 40 | * @param {Object} obj 41 | * @returns {Boolean} 42 | */ 43 | OnlineAccount.isInstance = function(obj){ 44 | return utils.isInstance(obj, this._gedxClass); 45 | }; 46 | 47 | /** 48 | * Initialize from JSON 49 | * 50 | * @param {Object} 51 | * @return {OnlineAccount} this 52 | */ 53 | OnlineAccount.prototype.init = function(json){ 54 | 55 | GedcomX.ExtensibleData.prototype.init.call(this, json); 56 | 57 | if(json){ 58 | this.setAccountName(json.accountName); 59 | this.setServiceHomepage(json.serviceHomepage); 60 | } 61 | return this; 62 | }; 63 | 64 | /** 65 | * Get the service home page 66 | * 67 | * @returns {ResourceReference} 68 | */ 69 | OnlineAccount.prototype.getServiceHomepage = function(){ 70 | return this.serviceHomepage; 71 | }; 72 | 73 | /** 74 | * Set the service home page 75 | * 76 | * @param {ResourceReference} serviceHomepage 77 | * @returns {OnlineAccount} 78 | */ 79 | OnlineAccount.prototype.setServiceHomepage = function(serviceHomepage){ 80 | if(serviceHomepage){ 81 | this.serviceHomepage = GedcomX.ResourceReference(serviceHomepage); 82 | } 83 | return this; 84 | }; 85 | 86 | /** 87 | * Get the account name 88 | * 89 | * @return {String} 90 | */ 91 | OnlineAccount.prototype.getAccountName = function(){ 92 | return this.accountName; 93 | }; 94 | 95 | /** 96 | * Set the account name 97 | * 98 | * @param {String} accountName 99 | * @returns {OnlineAccount} 100 | */ 101 | OnlineAccount.prototype.setAccountName = function(accountName){ 102 | this.accountName = accountName; 103 | return this; 104 | }; 105 | 106 | /** 107 | * Export the object as JSON 108 | * 109 | * @return {Object} JSON object 110 | */ 111 | OnlineAccount.prototype.toJSON = function(){ 112 | return this._toJSON(GedcomX.ExtensibleData, OnlineAccount.jsonProps); 113 | }; 114 | 115 | module.exports = OnlineAccount; -------------------------------------------------------------------------------- /src/core/PlaceReference.js: -------------------------------------------------------------------------------- 1 | var GedcomX = require('../'), 2 | utils = require('../utils'); 3 | 4 | /** 5 | * A reference to a {@link PlaceDescription}. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#conclusion-place-reference|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends ExtensibleData 11 | * @param {Object} [json] 12 | */ 13 | var PlaceReference = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof PlaceReference)){ 17 | return new PlaceReference(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(GedcomX.ExtensibleData.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | PlaceReference.prototype = Object.create(GedcomX.ExtensibleData.prototype); 29 | 30 | PlaceReference._gedxClass = PlaceReference.prototype._gedxClass = 'GedcomX.ExtensibleData'; 31 | 32 | PlaceReference.jsonProps = [ 33 | 'original', 34 | 'description' 35 | ]; 36 | 37 | /** 38 | * Check whether the given object is an instance of this class. 39 | * 40 | * @param {Object} obj 41 | * @returns {Boolean} 42 | */ 43 | PlaceReference.isInstance = function(obj){ 44 | return utils.isInstance(obj, this._gedxClass); 45 | }; 46 | 47 | /** 48 | * Initialize from JSON 49 | * 50 | * @param {Object} 51 | * @return {PlaceReference} this 52 | */ 53 | PlaceReference.prototype.init = function(json){ 54 | 55 | GedcomX.ExtensibleData.prototype.init.call(this, json); 56 | 57 | if(json){ 58 | this.setOriginal(json.original); 59 | this.setDescription(json.description); 60 | } 61 | return this; 62 | }; 63 | 64 | /** 65 | * Get the original text 66 | * 67 | * @returns {String} original 68 | */ 69 | PlaceReference.prototype.getOriginal = function(){ 70 | return this.original; 71 | }; 72 | 73 | /** 74 | * Set the original text 75 | * 76 | * @param {String} original 77 | * @returns {PlaceReference} This instance. 78 | */ 79 | PlaceReference.prototype.setOriginal = function(original){ 80 | this.original = original; 81 | return this; 82 | }; 83 | 84 | /** 85 | * Get the description 86 | * 87 | * @returns {String} 88 | */ 89 | PlaceReference.prototype.getDescription = function(){ 90 | return this.description; 91 | }; 92 | 93 | /** 94 | * Set the description 95 | * 96 | * @param {String} description 97 | * @returns {PlaceReference} This instance. 98 | */ 99 | PlaceReference.prototype.setDescription = function(description){ 100 | this.description = description; 101 | return this; 102 | }; 103 | 104 | /** 105 | * Export the object as JSON 106 | * 107 | * @return {Object} JSON object 108 | */ 109 | PlaceReference.prototype.toJSON = function(){ 110 | return this._toJSON(GedcomX.ExtensibleData, PlaceReference.jsonProps); 111 | }; 112 | 113 | module.exports = PlaceReference; -------------------------------------------------------------------------------- /src/core/Qualifier.js: -------------------------------------------------------------------------------- 1 | var utils = require('../utils'), 2 | Base = require('../Base'); 3 | 4 | /** 5 | * Qualifiers are used to supply additional details about a piece of data. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#qualifier|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends Base 11 | * @param {Object} [json] 12 | */ 13 | var Qualifier = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof Qualifier)){ 17 | return new Qualifier(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(Qualifier.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | Qualifier.prototype = Object.create(Base.prototype); 29 | 30 | Qualifier._gedxClass = Qualifier.prototype._gedxClass = 'GedcomX.Qualifier'; 31 | 32 | Qualifier.jsonProps = [ 33 | 'name', 34 | 'value' 35 | ]; 36 | 37 | /** 38 | * Check whether the given object is an instance of this class. 39 | * 40 | * @param {Object} obj 41 | * @returns {Boolean} 42 | */ 43 | Qualifier.isInstance = function(obj){ 44 | return utils.isInstance(obj, this._gedxClass); 45 | }; 46 | 47 | /** 48 | * Initialize from JSON 49 | * 50 | * @param {Object} 51 | * @return {Qualifier} this 52 | */ 53 | Qualifier.prototype.init = function(json){ 54 | 55 | Base.prototype.init.call(this, json); 56 | 57 | if(json){ 58 | this.setName(json.name); 59 | this.setValue(json.value); 60 | } 61 | return this; 62 | }; 63 | 64 | /** 65 | * Get the name 66 | * 67 | * @returns {String} name 68 | */ 69 | Qualifier.prototype.getName = function(){ 70 | return this.name; 71 | }; 72 | 73 | /** 74 | * Set the name 75 | * 76 | * @param {String} name 77 | * @returns {Qualifier} This instance. 78 | */ 79 | Qualifier.prototype.setName = function(name){ 80 | this.name = name; 81 | return this; 82 | }; 83 | 84 | /** 85 | * Get the value 86 | * 87 | * @returns {String} 88 | */ 89 | Qualifier.prototype.getValue = function(){ 90 | return this.value; 91 | }; 92 | 93 | /** 94 | * Set the value 95 | * 96 | * @param {String} value 97 | * @returns {Qualifier} This instance. 98 | */ 99 | Qualifier.prototype.setValue = function(value){ 100 | this.value = value; 101 | return this; 102 | }; 103 | 104 | /** 105 | * Export the object as JSON 106 | * 107 | * @return {Object} JSON object 108 | */ 109 | Qualifier.prototype.toJSON = function(){ 110 | return this._toJSON(Base, Qualifier.jsonProps); 111 | }; 112 | 113 | module.exports = Qualifier; -------------------------------------------------------------------------------- /src/core/ResourceReference.js: -------------------------------------------------------------------------------- 1 | var utils = require('../utils'), 2 | Base = require('../Base'); 3 | 4 | /** 5 | * A generic reference to a resource. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#resource-reference|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends Base 11 | * @param {Object} [json] 12 | */ 13 | var ResourceReference = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof ResourceReference)){ 17 | return new ResourceReference(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(ResourceReference.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | ResourceReference.prototype = Object.create(Base.prototype); 29 | 30 | ResourceReference._gedxClass = ResourceReference.prototype._gedxClass = 'GedcomX.ResourceReference'; 31 | 32 | ResourceReference.jsonProps = ['resource']; 33 | 34 | /** 35 | * Check whether the given object is an instance of this class. 36 | * 37 | * @param {Object} obj 38 | * @returns {Boolean} 39 | */ 40 | ResourceReference.isInstance = function(obj){ 41 | return utils.isInstance(obj, this._gedxClass); 42 | }; 43 | 44 | /** 45 | * Initialize from JSON 46 | * 47 | * @param {Object} 48 | * @return {ResourceReference} this 49 | */ 50 | ResourceReference.prototype.init = function(json){ 51 | 52 | Base.prototype.init.call(this, json); 53 | 54 | if(json){ 55 | this.setResource(json.resource); 56 | } 57 | return this; 58 | }; 59 | 60 | /** 61 | * Get the resource URI 62 | * 63 | * @returns {String} Resource 64 | */ 65 | ResourceReference.prototype.getResource = function(){ 66 | return this.resource; 67 | }; 68 | 69 | /** 70 | * Set the resource URI 71 | * 72 | * @param {String} uri 73 | * @returns {ResourceReference} this object 74 | */ 75 | ResourceReference.prototype.setResource = function(uri){ 76 | this.resource = uri; 77 | return this; 78 | }; 79 | 80 | /** 81 | * Check whether this reference matches the given resource. 82 | * 83 | * @param {Base} resource Resource or ID 84 | * @return {Boolean} 85 | */ 86 | ResourceReference.prototype.matches = function(resource){ 87 | if(resource === undefined){ 88 | return false; 89 | } 90 | var id = '#' + (typeof resource === 'string' ? resource : resource.getId()); 91 | return this.resource === id; 92 | }; 93 | 94 | /** 95 | * Export the object as JSON 96 | * 97 | * @return {Object} JSON object 98 | */ 99 | ResourceReference.prototype.toJSON = function(){ 100 | return this._toJSON(Base, ResourceReference.jsonProps); 101 | }; 102 | 103 | module.exports = ResourceReference; -------------------------------------------------------------------------------- /src/core/SourceCitation.js: -------------------------------------------------------------------------------- 1 | var GedcomX = require('../'), 2 | utils = require('../utils'); 3 | 4 | /** 5 | * A source citation. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#source-citation|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends ExtensibleData 11 | * @apram {Object} [json] 12 | */ 13 | var SourceCitation = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof SourceCitation)){ 17 | return new SourceCitation(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(SourceCitation.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | SourceCitation.prototype = Object.create(GedcomX.ExtensibleData.prototype); 29 | 30 | SourceCitation._gedxClass = SourceCitation.prototype._gedxClass = 'GedcomX.SourceCitation'; 31 | 32 | SourceCitation.jsonProps = [ 33 | 'lang', 34 | 'value' 35 | ]; 36 | 37 | /** 38 | * Check whether the given object is an instance of this class. 39 | * 40 | * @param {Object} obj 41 | * @returns {Boolean} 42 | */ 43 | SourceCitation.isInstance = function(obj){ 44 | return utils.isInstance(obj, this._gedxClass); 45 | }; 46 | 47 | /** 48 | * Initialize from JSON 49 | * 50 | * @param {Object} 51 | * @return {SourceCitation} this 52 | */ 53 | SourceCitation.prototype.init = function(json){ 54 | 55 | GedcomX.ExtensibleData.prototype.init.call(this, json); 56 | 57 | if(json){ 58 | this.setLang(json.lang); 59 | this.setValue(json.value); 60 | } 61 | return this; 62 | }; 63 | 64 | /** 65 | * Get the lang 66 | * 67 | * @returns {String} lang 68 | */ 69 | SourceCitation.prototype.getLang = function(){ 70 | return this.lang; 71 | }; 72 | 73 | /** 74 | * Set the lang 75 | * 76 | * @param {String} lang 77 | * @returns {SourceCitation} This instance 78 | */ 79 | SourceCitation.prototype.setLang = function(lang){ 80 | this.lang = lang; 81 | return this; 82 | }; 83 | 84 | /** 85 | * Get the value 86 | * 87 | * @returns {String} value 88 | */ 89 | SourceCitation.prototype.getValue = function(){ 90 | return this.value; 91 | }; 92 | 93 | /** 94 | * Set the value 95 | * 96 | * @param {String} value 97 | * @returns {SourceCitation} This instance 98 | */ 99 | SourceCitation.prototype.setValue = function(value){ 100 | this.value = value; 101 | return this; 102 | }; 103 | 104 | /** 105 | * Export the object as JSON 106 | * 107 | * @return {Object} JSON object 108 | */ 109 | SourceCitation.prototype.toJSON = function(){ 110 | return this._toJSON(GedcomX.ExtensibleData, SourceCitation.jsonProps); 111 | }; 112 | 113 | module.exports = SourceCitation; -------------------------------------------------------------------------------- /src/core/SourceReference.js: -------------------------------------------------------------------------------- 1 | var GedcomX = require('../'), 2 | utils = require('../utils'); 3 | 4 | /** 5 | * A reference to a discription of a source. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#source-reference|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends ExtensibleData 11 | * @param {Object} [json] 12 | */ 13 | var SourceReference = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof SourceReference)){ 17 | return new SourceReference(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(SourceReference.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | SourceReference.prototype = Object.create(GedcomX.ExtensibleData.prototype); 29 | 30 | SourceReference._gedxClass = SourceReference.prototype._gedxClass = 'GedcomX.SourceReference'; 31 | 32 | SourceReference.jsonProps = [ 33 | 'description', 34 | 'descriptionId', 35 | 'attribution' 36 | ]; 37 | 38 | /** 39 | * Check whether the given object is an instance of this class. 40 | * 41 | * @param {Object} obj 42 | * @returns {Boolean} 43 | */ 44 | SourceReference.isInstance = function(obj){ 45 | return utils.isInstance(obj, this._gedxClass); 46 | }; 47 | 48 | /** 49 | * Initialize from JSON 50 | * 51 | * @param {Object} 52 | * @return {SourceReference} this 53 | */ 54 | SourceReference.prototype.init = function(json){ 55 | 56 | GedcomX.ExtensibleData.prototype.init.call(this, json); 57 | 58 | if(json){ 59 | this.setDescription(json.description); 60 | this.setDescriptionId(json.descriptionId); 61 | this.setAttribution(json.attribution); 62 | } 63 | return this; 64 | }; 65 | 66 | /** 67 | * Get the description. 68 | * 69 | * @returns {String} 70 | */ 71 | SourceReference.prototype.getDescription = function(){ 72 | return this.description; 73 | }; 74 | 75 | /** 76 | * Set the description. 77 | * 78 | * @param {String} description 79 | * @returns {SourceReference} This instance. 80 | */ 81 | SourceReference.prototype.setDescription = function(description){ 82 | this.description = description; 83 | return this; 84 | }; 85 | 86 | /** 87 | * Get the description id. 88 | * 89 | * @returns {String} 90 | */ 91 | SourceReference.prototype.getDescriptionId = function(){ 92 | return this.descriptionId; 93 | }; 94 | 95 | /** 96 | * Set the description id. 97 | * 98 | * @param {String} descriptionId 99 | * @returns {SourceReference} This instance. 100 | */ 101 | SourceReference.prototype.setDescriptionId = function(descriptionId){ 102 | this.descriptionId = descriptionId; 103 | return this; 104 | }; 105 | 106 | /** 107 | * Get the attribution. 108 | * 109 | * @returns {Attribution} 110 | */ 111 | SourceReference.prototype.getAttribution = function(){ 112 | return this.attribution; 113 | }; 114 | 115 | /** 116 | * Set the attribution 117 | * 118 | * @param {Object|Attribution} attribution 119 | * @returns {SourceReference} This instance. 120 | */ 121 | SourceReference.prototype.setAttribution = function(attribution){ 122 | if(attribution){ 123 | this.attribution = new GedcomX.Attribution(attribution); 124 | } 125 | return this; 126 | }; 127 | 128 | /** 129 | * Export the object as JSON 130 | * 131 | * @return {Object} JSON object 132 | */ 133 | SourceReference.prototype.toJSON = function(){ 134 | return this._toJSON(GedcomX.ExtensibleData, SourceReference.jsonProps); 135 | }; 136 | 137 | module.exports = SourceReference; -------------------------------------------------------------------------------- /src/core/TextValue.js: -------------------------------------------------------------------------------- 1 | var utils = require('../utils'), 2 | Base = require('../Base'); 3 | 4 | /** 5 | * A text value in a specific language. 6 | * 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#text-value|GEDCOM X JSON Spec} 8 | * 9 | * @class 10 | * @extends Base 11 | * @apram {Object} [json] 12 | */ 13 | var TextValue = function(json){ 14 | 15 | // Protect against forgetting the new keyword when calling the constructor 16 | if(!(this instanceof TextValue)){ 17 | return new TextValue(json); 18 | } 19 | 20 | // If the given object is already an instance then just return it. DON'T copy it. 21 | if(TextValue.isInstance(json)){ 22 | return json; 23 | } 24 | 25 | this.init(json); 26 | }; 27 | 28 | TextValue.prototype = Object.create(Base.prototype); 29 | 30 | TextValue._gedxClass = TextValue.prototype._gedxClass = 'GedcomX.TextValue'; 31 | 32 | TextValue.jsonProps = [ 33 | 'lang', 34 | 'value' 35 | ]; 36 | 37 | /** 38 | * Check whether the given object is an instance of this class. 39 | * 40 | * @param {Object} obj 41 | * @returns {Boolean} 42 | */ 43 | TextValue.isInstance = function(obj){ 44 | return utils.isInstance(obj, this._gedxClass); 45 | }; 46 | 47 | /** 48 | * Initialize from JSON 49 | * 50 | * @param {Object} 51 | * @return {Conclusion} this 52 | */ 53 | TextValue.prototype.init = function(json){ 54 | 55 | Base.prototype.init.call(this, json); 56 | 57 | if(json){ 58 | this.setLang(json.lang); 59 | this.setValue(json.value); 60 | } 61 | return this; 62 | }; 63 | 64 | /** 65 | * Get the lang 66 | * 67 | * @returns {String} lang 68 | */ 69 | TextValue.prototype.getLang = function(){ 70 | return this.lang; 71 | }; 72 | 73 | /** 74 | * Set the lang 75 | * 76 | * @param {String} lang 77 | * @returns {TextValue} This instance 78 | */ 79 | TextValue.prototype.setLang = function(lang){ 80 | this.lang = lang; 81 | return this; 82 | }; 83 | 84 | /** 85 | * Get the value 86 | * 87 | * @returns {String} value 88 | */ 89 | TextValue.prototype.getValue = function(){ 90 | return this.value; 91 | }; 92 | 93 | /** 94 | * Set the value 95 | * 96 | * @param {String} value 97 | * @returns {TextValue} This instance 98 | */ 99 | TextValue.prototype.setValue = function(value){ 100 | this.value = value; 101 | return this; 102 | }; 103 | 104 | /** 105 | * Export the object as JSON 106 | * 107 | * @return {Object} JSON object 108 | */ 109 | TextValue.prototype.toJSON = function(){ 110 | return this._toJSON(Base, TextValue.jsonProps); 111 | }; 112 | 113 | module.exports = TextValue; -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A GEDCOM X document. 3 | * 4 | * @constructor 5 | * @param {Object} [json] 6 | */ 7 | var GedcomX = function(json){ 8 | return new GedcomX.Root(json); 9 | }; 10 | 11 | // Export early so that circular dependencies work properly 12 | module.exports = GedcomX; 13 | 14 | // Expose utils so that extension libraries can use them 15 | GedcomX.utils = require('./utils'); 16 | 17 | // Expose all classes. They have to be included in order so that the inheritance 18 | // hierarchy is properly assembled. 19 | GedcomX.Base = require('./Base'); 20 | GedcomX.ExtensibleData = require('./core/ExtensibleData'); 21 | GedcomX.Conclusion = require('./core/Conclusion'); 22 | GedcomX.Subject = require('./core/Subject'); 23 | GedcomX.ResourceReference = require('./core/ResourceReference'); 24 | 25 | // The rest are listed alphabetically because they either extend Base or extend 26 | // one of the classes included above. 27 | GedcomX.Address = require('./core/Address'); 28 | GedcomX.Agent = require('./core/Agent'); 29 | GedcomX.Attribution = require('./core/Attribution'); 30 | GedcomX.Coverage = require('./core/Coverage'); 31 | GedcomX.Date = require('./core/Date'); 32 | GedcomX.Document = require('./core/Document'); 33 | GedcomX.Event = require('./core/Event'); 34 | GedcomX.EventRole = require('./core/EventRole'); 35 | GedcomX.EvidenceReference = require('./core/EvidenceReference'); 36 | GedcomX.Fact = require('./core/Fact'); 37 | GedcomX.Gender = require('./core/Gender'); 38 | GedcomX.Identifiers = require('./core/Identifiers'); 39 | GedcomX.Name = require('./core/Name'); 40 | GedcomX.NameForm = require('./core/NameForm'); 41 | GedcomX.NamePart = require('./core/NamePart'); 42 | GedcomX.Note = require('./core/Note'); 43 | GedcomX.OnlineAccount = require('./core/OnlineAccount'); 44 | GedcomX.Person = require('./core/Person'); 45 | GedcomX.PlaceDescription = require('./core/PlaceDescription'); 46 | GedcomX.PlaceReference = require('./core/PlaceReference'); 47 | GedcomX.Qualifier = require('./core/Qualifier'); 48 | GedcomX.Relationship = require('./core/Relationship'); 49 | GedcomX.Root = require('./core/Root'); 50 | GedcomX.SourceCitation = require('./core/SourceCitation'); 51 | GedcomX.SourceDescription = require('./core/SourceDescription'); 52 | GedcomX.SourceReference = require('./core/SourceReference'); 53 | GedcomX.TextValue = require('./core/TextValue'); 54 | 55 | /** 56 | * Enable a set of extensions 57 | * 58 | * @param {Function} extensions 59 | */ 60 | GedcomX.addExtensions = function(extensions){ 61 | if(typeof extensions === 'function'){ 62 | extensions(this); 63 | } 64 | }; 65 | 66 | /** 67 | * Enable the GedcomX RS Extensions 68 | */ 69 | GedcomX.enableRsExtensions = function(){ 70 | this.addExtensions(require('./rs')); 71 | }; 72 | 73 | /** 74 | * Enable the GedcomX Records Extensions 75 | */ 76 | GedcomX.enableRecordsExtensions = function(){ 77 | this.addExtensions(require('./records')); 78 | }; 79 | 80 | /** 81 | * Enable the GedcomX Atom Extensions. This depends on the RS extensions 82 | * so those will be enabled too. 83 | */ 84 | GedcomX.enableAtomExtensions = function(){ 85 | this.enableRsExtensions(); // depends on RS extensions 86 | this.enableRecordsExtensions(); // depend on Record extensions 87 | this.addExtensions(require('./atom')); 88 | }; -------------------------------------------------------------------------------- /src/records/Coverage.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Record extensions to Coverage 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.Coverage.jsonProps.push('recordType'); 8 | 9 | // Override init() 10 | var oldCoverageInit = GedcomX.Coverage.prototype.init; 11 | GedcomX.Coverage.prototype.init = function(json){ 12 | oldCoverageInit.call(this, json); 13 | if(json){ 14 | this.setRecordType(json.recordType); 15 | } 16 | }; 17 | 18 | /** 19 | * Set the record type 20 | * 21 | * @param {String} recordType 22 | * @return {Coverage} this 23 | */ 24 | GedcomX.Coverage.prototype.setRecordType = function(recordType){ 25 | this.recordType = recordType; 26 | return this; 27 | }; 28 | 29 | /** 30 | * Get the record type 31 | * 32 | * @return {String} recordType 33 | */ 34 | GedcomX.Coverage.prototype.getRecordType = function(){ 35 | return this.recordType; 36 | }; 37 | 38 | }; -------------------------------------------------------------------------------- /src/records/ExtensibleData.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Record extensions to ExtensibleData 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.ExtensibleData.jsonProps.push('fields'); 8 | 9 | // Override init() 10 | var oldExtensibleDataInit = GedcomX.ExtensibleData.prototype.init; 11 | GedcomX.ExtensibleData.prototype.init = function(json){ 12 | oldExtensibleDataInit.call(this, json); 13 | if(json){ 14 | this.setFields(json.fields); 15 | } 16 | }; 17 | 18 | /** 19 | * Set the fields 20 | * 21 | * @function setFields 22 | * @instance 23 | * @memberof ExtensibleData 24 | * @param {Field[]} fields 25 | * @return {ExtensibleData} this 26 | */ 27 | GedcomX.ExtensibleData.prototype.setFields = function(fields){ 28 | return this._setArray(fields, 'fields', 'addField'); 29 | }; 30 | 31 | /** 32 | * Add a field 33 | * 34 | * @function addField 35 | * @instance 36 | * @memberof ExtensibleData 37 | * @param {Field} field 38 | * @return {ExtensibleData} this 39 | */ 40 | GedcomX.ExtensibleData.prototype.addField = function(field){ 41 | return this._arrayPush(field, 'fields', GedcomX.Field); 42 | }; 43 | 44 | /** 45 | * Get the fields 46 | * 47 | * @function getFields 48 | * @instance 49 | * @memberof ExtensibleData 50 | * @return {Field[]} 51 | */ 52 | GedcomX.ExtensibleData.prototype.getFields = function(){ 53 | return this.fields || []; 54 | }; 55 | 56 | }; -------------------------------------------------------------------------------- /src/records/Fact.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Record extensions to Fact 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.Fact.jsonProps.push('primary'); 8 | 9 | // Override init() 10 | var oldFactInit = GedcomX.Fact.prototype.init; 11 | GedcomX.Fact.prototype.init = function(json){ 12 | oldFactInit.call(this, json); 13 | if(json){ 14 | this.setPrimary(json.primary); 15 | } 16 | }; 17 | 18 | /** 19 | * Set the primary flag 20 | * 21 | * @function setPrimary 22 | * @instance 23 | * @memberof Fact 24 | * @param {Boolean} primary 25 | * @return {Fact} this 26 | */ 27 | GedcomX.Fact.prototype.setPrimary = function(primary){ 28 | this.primary = primary; 29 | return this; 30 | }; 31 | 32 | /** 33 | * Get the primary flag 34 | * 35 | * @function getPrimary 36 | * @instance 37 | * @memberof Fact 38 | * @return {Boolean} 39 | */ 40 | GedcomX.Fact.prototype.getPrimary = function(){ 41 | return this.primary; 42 | }; 43 | 44 | }; -------------------------------------------------------------------------------- /src/records/Field.js: -------------------------------------------------------------------------------- 1 | module.exports = function(GedcomX){ 2 | 3 | var utils = require('../utils'); 4 | 5 | /** 6 | * Information about the fields of a record from which genealogical data is extracted. 7 | * 8 | * @see {@link https://github.com/FamilySearch/gedcomx-record/blob/master/specifications/record-specification.md#field|GEDCOM X Records Spec} 9 | * 10 | * @class Field 11 | * @extends ExtensibleData 12 | * @param {Object} [json] 13 | */ 14 | var Field = function(json){ 15 | 16 | // Protect against forgetting the new keyword when calling the constructor 17 | if(!(this instanceof Field)){ 18 | return new Field(json); 19 | } 20 | 21 | // If the given object is already an instance then just return it. DON'T copy it. 22 | if(Field.isInstance(json)){ 23 | return json; 24 | } 25 | 26 | this.init(json); 27 | }; 28 | 29 | Field.prototype = Object.create(GedcomX.ExtensibleData.prototype); 30 | 31 | Field._gedxClass = Field.prototype._gedxClass = 'GedcomX.Field'; 32 | 33 | Field.jsonProps = [ 34 | 'type', 35 | 'values' 36 | ]; 37 | 38 | /** 39 | * Check whether the given object is an instance of this class. 40 | * 41 | * @param {Object} obj 42 | * @returns {Boolean} 43 | */ 44 | Field.isInstance = function(obj){ 45 | return utils.isInstance(obj, this._gedxClass); 46 | }; 47 | 48 | /** 49 | * Initialize from JSON 50 | * 51 | * @param {Object} 52 | * @return {Field} this 53 | */ 54 | Field.prototype.init = function(json){ 55 | 56 | GedcomX.ExtensibleData.prototype.init.call(this, json); 57 | 58 | if(json){ 59 | this.setType(json.type); 60 | this.setValues(json.values); 61 | } 62 | return this; 63 | }; 64 | 65 | /** 66 | * Set the type 67 | * 68 | * @param {String} type 69 | * @return {Field} this 70 | */ 71 | Field.prototype.setType = function(type){ 72 | this.type = type; 73 | return this; 74 | }; 75 | 76 | /** 77 | * Get the type 78 | * 79 | * @return {String} type 80 | */ 81 | Field.prototype.getType = function(){ 82 | return this.type; 83 | }; 84 | 85 | /** 86 | * Set the values 87 | * 88 | * @param {FieldValue[]} values 89 | * @return {Field} this 90 | */ 91 | Field.prototype.setValues = function(values){ 92 | return this._setArray(values, 'values', 'addValue'); 93 | }; 94 | 95 | /** 96 | * Add a value 97 | * 98 | * @param {FieldValue} value 99 | * @return {Field} this 100 | */ 101 | Field.prototype.addValue = function(value){ 102 | return this._arrayPush(value, 'values', GedcomX.FieldValue); 103 | }; 104 | 105 | /** 106 | * Get the values 107 | * 108 | * @return {FieldValue[]} values 109 | */ 110 | Field.prototype.getValues = function(){ 111 | return this.values || []; 112 | }; 113 | 114 | /** 115 | * Export the object as JSON 116 | * 117 | * @return {Object} JSON object 118 | */ 119 | Field.prototype.toJSON = function(){ 120 | return this._toJSON(GedcomX.ExtensibleData, Field.jsonProps); 121 | }; 122 | 123 | GedcomX.Field = Field; 124 | 125 | }; -------------------------------------------------------------------------------- /src/records/Person.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Record extensions to Person 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.Person.jsonProps.push('principal'); 8 | 9 | // Override init() 10 | var oldPersonInit = GedcomX.Person.prototype.init; 11 | GedcomX.Person.prototype.init = function(json){ 12 | oldPersonInit.call(this, json); 13 | if(json){ 14 | this.setPrincipal(json.principal); 15 | } 16 | }; 17 | 18 | /** 19 | * Set the principal flag 20 | * 21 | * @function setPrincipal 22 | * @instance 23 | * @memberof Person 24 | * @param {Boolean} principal 25 | * @return {Person} this 26 | */ 27 | GedcomX.Person.prototype.setPrincipal = function(principal){ 28 | this.principal = principal; 29 | return this; 30 | }; 31 | 32 | /** 33 | * Get the principal flag 34 | * 35 | * @function getPrincipal 36 | * @instance 37 | * @memberof Person 38 | * @return {Boolean} 39 | */ 40 | GedcomX.Person.prototype.getPrincipal = function(){ 41 | return this.principal; 42 | }; 43 | 44 | }; -------------------------------------------------------------------------------- /src/records/RecordDescriptor.js: -------------------------------------------------------------------------------- 1 | module.exports = function(GedcomX){ 2 | 3 | var utils = require('../utils'); 4 | 5 | /** 6 | * Metadata about the structure and layout of a record, as well as the expected 7 | * data to be extracted from a record. 8 | * 9 | * @see {@link https://github.com/FamilySearch/gedcomx-record/blob/master/specifications/record-specification.md#record-descriptor|GEDCOM X Records Spec} 10 | * 11 | * @class RecordDescriptor 12 | * @extends ExtensibleData 13 | * @param {Object} [json] 14 | */ 15 | var RecordDescriptor = function(json){ 16 | 17 | // Protect against forgetting the new keyword when calling the constructor 18 | if(!(this instanceof RecordDescriptor)){ 19 | return new RecordDescriptor(json); 20 | } 21 | 22 | // If the given object is already an instance then just return it. DON'T copy it. 23 | if(RecordDescriptor.isInstance(json)){ 24 | return json; 25 | } 26 | 27 | this.init(json); 28 | }; 29 | 30 | RecordDescriptor.prototype = Object.create(GedcomX.ExtensibleData.prototype); 31 | 32 | RecordDescriptor._gedxClass = RecordDescriptor.prototype._gedxClass = 'GedcomX.RecordDescriptor'; 33 | 34 | RecordDescriptor.jsonProps = [ 35 | 'lang', 36 | 'fields' 37 | ]; 38 | 39 | /** 40 | * Check whether the given object is an instance of this class. 41 | * 42 | * @param {Object} obj 43 | * @returns {Boolean} 44 | */ 45 | RecordDescriptor.isInstance = function(obj){ 46 | return utils.isInstance(obj, this._gedxClass); 47 | }; 48 | 49 | /** 50 | * Initialize from JSON 51 | * 52 | * @param {Object} 53 | * @return {RecordDescriptor} this 54 | */ 55 | RecordDescriptor.prototype.init = function(json){ 56 | 57 | GedcomX.ExtensibleData.prototype.init.call(this, json); 58 | 59 | if(json){ 60 | this.setLang(json.lang); 61 | this.setFields(json.fields); 62 | } 63 | return this; 64 | }; 65 | 66 | /** 67 | * Set the lang 68 | * 69 | * @param {String} lang 70 | * @return {RecordDescriptor} this 71 | */ 72 | RecordDescriptor.prototype.setLang = function(lang){ 73 | this.lang = lang; 74 | return this; 75 | }; 76 | 77 | /** 78 | * Get the lang 79 | * 80 | * @return {String} lang 81 | */ 82 | RecordDescriptor.prototype.getLang = function(){ 83 | return this.lang; 84 | }; 85 | 86 | /** 87 | * Set the fields 88 | * 89 | * @param {FieldDescriptor[]} fields 90 | * @return {RecordDescriptor} this 91 | */ 92 | RecordDescriptor.prototype.setFields = function(fields){ 93 | return this._setArray(fields, 'fields', 'addField'); 94 | }; 95 | 96 | /** 97 | * Add a field 98 | * 99 | * @param {FieldDescriptor} field 100 | * @return {RecordDescriptor} this 101 | */ 102 | RecordDescriptor.prototype.addField = function(field){ 103 | return this._arrayPush(field, 'fields', GedcomX.FieldDescriptor); 104 | }; 105 | 106 | /** 107 | * Get the fields 108 | * 109 | * @return {FieldDescriptor[]} 110 | */ 111 | RecordDescriptor.prototype.getFields = function(){ 112 | return this.fields || []; 113 | }; 114 | 115 | /** 116 | * Export the object as JSON 117 | * 118 | * @return {Object} JSON object 119 | */ 120 | RecordDescriptor.prototype.toJSON = function(){ 121 | return this._toJSON(GedcomX.ExtensibleData, RecordDescriptor.jsonProps); 122 | }; 123 | 124 | GedcomX.RecordDescriptor = RecordDescriptor; 125 | 126 | }; -------------------------------------------------------------------------------- /src/records/Root.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Records extensions to Root 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.Root.jsonProps.push('recordDescriptors', 'collections'); 8 | 9 | // Override init() so that we can deserialize normalized values 10 | var oldInit = GedcomX.Root.prototype.init; 11 | GedcomX.Root.prototype.init = function(json){ 12 | oldInit.call(this, json); 13 | if(json){ 14 | this.setRecordDescriptors(json.recordDescriptors); 15 | this.setCollections(json.collections); 16 | } 17 | }; 18 | 19 | /** 20 | * Set the record descriptors 21 | * 22 | * @function setRecordDescriptors 23 | * @instance 24 | * @memberof Root 25 | * @param {RecordDescriptor[]} recordDescriptors 26 | * @return {Root} this 27 | */ 28 | GedcomX.Root.prototype.setRecordDescriptors = function(recordDescriptors){ 29 | return this._setArray(recordDescriptors, 'recordDescriptors', 'addRecordDescriptor'); 30 | }; 31 | 32 | /** 33 | * Add a record descriptor 34 | * 35 | * @function addRecordDescriptor 36 | * @instance 37 | * @memberof Root 38 | * @param {RecordDescriptor} recordDescriptor 39 | * @return {Root} this 40 | */ 41 | GedcomX.Root.prototype.addRecordDescriptor = function(recordDescriptor){ 42 | return this._arrayPush(recordDescriptor, 'recordDescriptors', GedcomX.RecordDescriptor); 43 | }; 44 | 45 | /** 46 | * Get the recordDescriptors 47 | * 48 | * @function getRecordDescriptors 49 | * @instance 50 | * @memberof Root 51 | * @return {Boolean} recordDescriptors 52 | */ 53 | GedcomX.Root.prototype.getRecordDescriptors = function(){ 54 | return this.recordDescriptors || []; 55 | }; 56 | 57 | /** 58 | * Set the collections 59 | * 60 | * @function setCollections 61 | * @instance 62 | * @memberof Root 63 | * @param {Collection[]} collections 64 | * @return {Root} this 65 | */ 66 | GedcomX.Root.prototype.setCollections = function(collections){ 67 | return this._setArray(collections, 'collections', 'addCollection'); 68 | }; 69 | 70 | /** 71 | * Add a collection 72 | * 73 | * @function addCollection 74 | * @instance 75 | * @memberof Root 76 | * @param {Collection} collection 77 | * @return {Root} this 78 | */ 79 | GedcomX.Root.prototype.addCollection = function(collection){ 80 | return this._arrayPush(collection, 'collections', GedcomX.Collection); 81 | }; 82 | 83 | /** 84 | * Get the collections 85 | * 86 | * @function getCollections 87 | * @instance 88 | * @memberof Root 89 | * @return {Collection[]} collections 90 | */ 91 | GedcomX.Root.prototype.getCollections = function(){ 92 | return this.collections || []; 93 | }; 94 | 95 | /** 96 | * Get the principle person, if one exists. 97 | * 98 | * @function getPrincipalPerson 99 | * @instance 100 | * @memberof Root 101 | * @returns {Person} Principal person if one exists; otherwise undefined. 102 | */ 103 | GedcomX.Root.prototype.getPrincipalPerson = function(){ 104 | return this.getPersons().find(function(p){ 105 | return p.getPrincipal(); 106 | }); 107 | }; 108 | 109 | }; -------------------------------------------------------------------------------- /src/records/SourceDescription.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Record extensions to SourceDescription 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.SourceDescription.jsonProps.push('titleLabel', 'sortKey', 'descriptorRef'); 8 | 9 | // Override init() 10 | var oldSourceDescriptionInit = GedcomX.SourceDescription.prototype.init; 11 | GedcomX.SourceDescription.prototype.init = function(json){ 12 | oldSourceDescriptionInit.call(this, json); 13 | if(json){ 14 | this.setTitleLabel(json.titleLabel); 15 | this.setSortKey(json.sortKey); 16 | this.setDescriptorRef(json.descriptorRef); 17 | } 18 | }; 19 | 20 | /** 21 | * Set the title label 22 | * 23 | * @function setTitleLabel 24 | * @instance 25 | * @memberof SourceDescription 26 | * @param {String} titleLabel 27 | * @return {SourceDescription} this 28 | */ 29 | GedcomX.SourceDescription.prototype.setTitleLabel = function(titleLabel){ 30 | this.titleLabel = titleLabel; 31 | return this; 32 | }; 33 | 34 | /** 35 | * Get the title label 36 | * 37 | * @function getTitleLabel 38 | * @instance 39 | * @memberof SourceDescription 40 | * @return {String} titleLabel 41 | */ 42 | GedcomX.SourceDescription.prototype.getTitleLabel = function(){ 43 | return this.titleLabel; 44 | }; 45 | 46 | /** 47 | * Set the sort key 48 | * 49 | * @function setSortKey 50 | * @instance 51 | * @memberof SourceDescription 52 | * @param {String} sortKey 53 | * @return {SourceDescription} this 54 | */ 55 | GedcomX.SourceDescription.prototype.setSortKey = function(sortKey){ 56 | this.sortKey = sortKey; 57 | return this; 58 | }; 59 | 60 | /** 61 | * Get the sort key 62 | * 63 | * @function getSortKey 64 | * @instance 65 | * @memberof SourceDescription 66 | * @return {String} sortKey 67 | */ 68 | GedcomX.SourceDescription.prototype.getSortKey = function(){ 69 | return this.sortKey; 70 | }; 71 | 72 | /** 73 | * Set the descriptor ref 74 | * 75 | * @function setDescriptorRef 76 | * @instance 77 | * @memberof SourceDescription 78 | * @param {String} descriptorRef 79 | * @return {SourceDescription} this 80 | */ 81 | GedcomX.SourceDescription.prototype.setDescriptorRef = function(descriptorRef){ 82 | this.descriptorRef = descriptorRef; 83 | return this; 84 | }; 85 | 86 | /** 87 | * Get the descriptor ref 88 | * 89 | * @function getDescriptorRef 90 | * @instance 91 | * @memberof SourceDescription 92 | * @return {String} 93 | */ 94 | GedcomX.SourceDescription.prototype.getDescriptorRef = function(){ 95 | return this.descriptorRef; 96 | }; 97 | 98 | }; -------------------------------------------------------------------------------- /src/records/SourceReference.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Record extensions to SourceReference 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.SourceReference.jsonProps.push('qualifiers'); 8 | 9 | // Override init() 10 | var oldSourceReferenceInit = GedcomX.SourceReference.prototype.init; 11 | GedcomX.SourceReference.prototype.init = function(json){ 12 | oldSourceReferenceInit.call(this, json); 13 | if(json){ 14 | this.setQualifiers(json.qualifiers); 15 | } 16 | }; 17 | 18 | /** 19 | * Set the qualifiers 20 | * 21 | * @function setQualifiers 22 | * @instance 23 | * @memberof SourceReference 24 | * @param {Qualifier[]} qualifiers 25 | * @return {SourceReference} this 26 | */ 27 | GedcomX.SourceReference.prototype.setQualifiers = function(qualifiers){ 28 | return this._setArray(qualifiers, 'qualifiers', 'addQualifier'); 29 | }; 30 | 31 | /** 32 | * Add a qualifier 33 | * 34 | * @function addQualifier 35 | * @instance 36 | * @memberof SourceReference 37 | * @param {Qualifiers} qualifier 38 | * @return {SourceReference} this 39 | */ 40 | GedcomX.SourceReference.prototype.addQualifier = function(qualifier){ 41 | return this._arrayPush(qualifier, 'qualifiers', GedcomX.Qualifier); 42 | }; 43 | 44 | /** 45 | * Get the qualifiers 46 | * 47 | * @function getQualifiers 48 | * @instance 49 | * @memberof SourceReference 50 | * @return {Qualifier[]} qualifiers 51 | */ 52 | GedcomX.SourceReference.prototype.getQualifiers = function(){ 53 | return this.qualifiers || []; 54 | }; 55 | 56 | }; -------------------------------------------------------------------------------- /src/records/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Setup Gedcom X Records Extensions 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Add new classes 7 | require('./FieldValueDescriptor')(GedcomX); 8 | require('./FieldDescriptor')(GedcomX); 9 | require('./RecordDescriptor')(GedcomX); 10 | require('./FieldValue')(GedcomX); 11 | require('./Field')(GedcomX); 12 | require('./CollectionContent')(GedcomX); 13 | require('./Collection')(GedcomX); 14 | 15 | // Extend existing classes 16 | require('./Root')(GedcomX); 17 | require('./ExtensibleData')(GedcomX); 18 | require('./Fact')(GedcomX); 19 | require('./Person')(GedcomX); 20 | require('./SourceDescription')(GedcomX); 21 | require('./SourceReference')(GedcomX); 22 | require('./Coverage')(GedcomX); 23 | }; -------------------------------------------------------------------------------- /src/rs/Conclusion.js: -------------------------------------------------------------------------------- 1 | /** 2 | * RS extensions to Conclusion 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.Conclusion.jsonProps.push('sortKey'); 8 | 9 | // Override init() so that we can deserialize normalized values 10 | var oldInit = GedcomX.Conclusion.prototype.init; 11 | GedcomX.Conclusion.prototype.init = function(json){ 12 | oldInit.call(this, json); 13 | if(json){ 14 | this.setSortKey(json.sortKey); 15 | } 16 | }; 17 | 18 | /** 19 | * Set the sortKey 20 | * 21 | * @function setSortKey 22 | * @instance 23 | * @memberof Conclusion 24 | * @param {Boolean} sortKey 25 | * @return {Conclusion} this 26 | */ 27 | GedcomX.Conclusion.prototype.setSortKey = function(sortKey){ 28 | this.sortKey = sortKey; 29 | return this; 30 | }; 31 | 32 | /** 33 | * Get the sortKey 34 | * 35 | * @function getSortKey 36 | * @instance 37 | * @memberof Conclusion 38 | * @return {Boolean} sortKey 39 | */ 40 | GedcomX.Conclusion.prototype.getSortKey = function(){ 41 | return this.sortKey; 42 | }; 43 | 44 | }; -------------------------------------------------------------------------------- /src/rs/Date.js: -------------------------------------------------------------------------------- 1 | /** 2 | * RS extensions to Date 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.Date.jsonProps.push('normalized'); 8 | 9 | // Override init() so that we can deserialize normalized values 10 | var oldInit = GedcomX.Date.prototype.init; 11 | GedcomX.Date.prototype.init = function(json){ 12 | oldInit.call(this, json); 13 | if(json){ 14 | this.setNormalized(json.normalized); 15 | } 16 | }; 17 | 18 | /** 19 | * Set the normalized values 20 | * 21 | * @function setNormalized 22 | * @instance 23 | * @memberof Date 24 | * @param {TextValue[]} normalized 25 | * @return {Date} this 26 | */ 27 | GedcomX.Date.prototype.setNormalized = function(normalized){ 28 | return this._setArray(normalized, 'normalized', 'addNormalized'); 29 | }; 30 | 31 | /** 32 | * Add a normalized value 33 | * 34 | * @function addNormalized 35 | * @instance 36 | * @memberof Date 37 | * @param {TextValue} normalized 38 | * @return {Date} this 39 | */ 40 | GedcomX.Date.prototype.addNormalized = function(normalized){ 41 | return this._arrayPush(normalized, 'normalized', GedcomX.TextValue); 42 | }; 43 | 44 | /** 45 | * Get the normalized values 46 | * 47 | * @function getNormalized 48 | * @instance 49 | * @memberof Date 50 | * @return {TextValue[]} 51 | */ 52 | GedcomX.Date.prototype.getNormalized = function(){ 53 | return this.normalized || []; 54 | }; 55 | 56 | }; -------------------------------------------------------------------------------- /src/rs/ExtensibleData.js: -------------------------------------------------------------------------------- 1 | /** 2 | * RS extensions to ExtensibleData 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.ExtensibleData.jsonProps.push('links'); 8 | 9 | // Override init() 10 | var oldExtensibleDataInit = GedcomX.ExtensibleData.prototype.init; 11 | GedcomX.ExtensibleData.prototype.init = function(json){ 12 | oldExtensibleDataInit.call(this, json); 13 | if(json){ 14 | this.setLinks(json.links); 15 | } 16 | }; 17 | 18 | /** 19 | * Set the links 20 | * 21 | * @function setLinks 22 | * @instance 23 | * @memberof ExtensibleData 24 | * @param {Links} links 25 | * @return {ExtensibleData} this 26 | */ 27 | GedcomX.ExtensibleData.prototype.setLinks = function(links){ 28 | if(links){ 29 | this.links = GedcomX.Links(links); 30 | } 31 | return this; 32 | }; 33 | 34 | /** 35 | * Add a link 36 | * 37 | * @function addLink 38 | * @instance 39 | * @memberof ExtensibleData 40 | * @param {Link} link 41 | * @return {ExtensibleData} this 42 | */ 43 | GedcomX.ExtensibleData.prototype.addLink = function(link){ 44 | if(link){ 45 | if(!this.links){ 46 | this.links = GedcomX.Links(); 47 | } 48 | this.links.addLink(link); 49 | } 50 | return this; 51 | }; 52 | 53 | /** 54 | * Get the links 55 | * 56 | * @function getLinks 57 | * @instance 58 | * @memberof ExtensibleData 59 | * @return {Link[]} 60 | */ 61 | GedcomX.ExtensibleData.prototype.getLinks = function(){ 62 | return this.links ? this.links.getLinks() : []; 63 | }; 64 | 65 | /** 66 | * Get a link 67 | * 68 | * @function getLink 69 | * @instance 70 | * @memberof ExtensibleData 71 | * @param {String} rel 72 | * @return {Link} 73 | */ 74 | GedcomX.ExtensibleData.prototype.getLink = function(rel){ 75 | if(this.links){ 76 | return this.links.getLink(rel); 77 | } 78 | }; 79 | 80 | }; -------------------------------------------------------------------------------- /src/rs/Links.js: -------------------------------------------------------------------------------- 1 | module.exports = function(GedcomX){ 2 | 3 | var utils = require('../utils'), 4 | Base = require('../Base'); 5 | 6 | /** 7 | * A list of Links 8 | * 9 | * {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/rs-specification.md#json-type-member|GEDCOM X RS Spec} 10 | * 11 | * @class Links 12 | * @extends Base 13 | * @param {Object} [json] 14 | */ 15 | var Links = function(json){ 16 | 17 | // Protect against forgetting the new keyword when calling the constructor 18 | if(!(this instanceof Links)){ 19 | return new Links(json); 20 | } 21 | 22 | // If the given object is already an instance then just return it. DON'T copy it. 23 | if(Links.isInstance(json)){ 24 | return json; 25 | } 26 | 27 | this.init(json); 28 | }; 29 | 30 | // There's no value in us extending Base at the moment 31 | Links.prototype = Object.create(Base.prototype); 32 | 33 | Links._gedxClass = Links.prototype._gedxClass = 'GedcomX.Links'; 34 | 35 | /** 36 | * Check whether the given object is an instance of this class. 37 | * 38 | * @param {Object} obj 39 | * @returns {Boolean} 40 | */ 41 | Links.isInstance = function(obj){ 42 | return utils.isInstance(obj, this._gedxClass); 43 | }; 44 | 45 | /** 46 | * Initialize from JSON 47 | * 48 | * @param {Object} 49 | * @return {Link} this 50 | */ 51 | Links.prototype.init = function(json){ 52 | 53 | Base.prototype.init.call(this, json); 54 | 55 | this.links = []; 56 | 57 | if(json){ 58 | this.setLinks(json); 59 | } 60 | return this; 61 | }; 62 | 63 | /** 64 | * Get the list of links 65 | * 66 | * @return {Link[]} links 67 | */ 68 | Links.prototype.getLinks = function(){ 69 | return this.links; 70 | }; 71 | 72 | /** 73 | * Get a link matching a rel 74 | * 75 | * @param {String} rel 76 | * @return {Link} link 77 | */ 78 | Links.prototype.getLink = function(rel){ 79 | return this.links.find(function(link){ 80 | return link.getRel() === rel; 81 | }); 82 | }; 83 | 84 | /** 85 | * Add a link 86 | * 87 | * @param {Link} link 88 | * @return {Links} this 89 | */ 90 | Links.prototype.addLink = function(link){ 91 | // TODO: check for duplicates 92 | this.links.push(GedcomX.Link(link)); 93 | return this; 94 | }; 95 | 96 | /** 97 | * Set the links. May either provide the JSON object structure or an array 98 | * of Link instances 99 | * 100 | * @param {Object|Link[]} links 101 | * @return {Links} this 102 | */ 103 | Links.prototype.setLinks = function(links){ 104 | this.links = []; 105 | if(links){ 106 | 107 | // List of link 108 | if(Array.isArray(links)){ 109 | for(var i = 0; i < links.length; i++){ 110 | this.addLink(links[i]); 111 | } 112 | } 113 | 114 | // JSON object 115 | else { 116 | for(var rel in links){ 117 | this.addLink(new GedcomX.Link(links[rel]).setRel(rel)); 118 | } 119 | } 120 | } 121 | return this; 122 | }; 123 | 124 | /** 125 | * Export the object as JSON 126 | * 127 | * @return {Object} JSON object 128 | */ 129 | Links.prototype.toJSON = function(){ 130 | var links = this.getLinks(), 131 | json = {}, 132 | linkJson, rel; 133 | for(var i = 0; i < links.length; i++){ 134 | linkJson = utils.toJSON(links[i]); 135 | rel = linkJson.rel; 136 | if(rel){ 137 | delete linkJson.rel; 138 | json[rel] = linkJson; 139 | } 140 | } 141 | return json; 142 | }; 143 | 144 | GedcomX.Links = Links; 145 | 146 | }; -------------------------------------------------------------------------------- /src/rs/Name.js: -------------------------------------------------------------------------------- 1 | /** 2 | * RS extensions to Name 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.Name.jsonProps.push('preferred'); 8 | 9 | // Override init() so that we can deserialize normalized values 10 | var oldInit = GedcomX.Name.prototype.init; 11 | GedcomX.Name.prototype.init = function(json){ 12 | oldInit.call(this, json); 13 | if(json){ 14 | this.setPreferred(json.preferred); 15 | } 16 | }; 17 | 18 | /** 19 | * Set the preferred flag 20 | * 21 | * @function setPreferred 22 | * @instance 23 | * @memberof Name 24 | * @param {Boolean} preferred 25 | * @return {Name} this 26 | */ 27 | GedcomX.Name.prototype.setPreferred = function(preferred){ 28 | this.preferred = preferred; 29 | return this; 30 | }; 31 | 32 | /** 33 | * Get the preferred flag 34 | * 35 | * @function getPreferred 36 | * @instance 37 | * @memberof Name 38 | * @return {Boolean} preferred 39 | */ 40 | GedcomX.Name.prototype.getPreferred = function(){ 41 | return this.preferred; 42 | }; 43 | 44 | }; -------------------------------------------------------------------------------- /src/rs/Person.js: -------------------------------------------------------------------------------- 1 | /** 2 | * RS extensions to Person 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.Person.jsonProps.push('living', 'display'); 8 | 9 | // Override init() so that we can deserialize normalized values 10 | var oldInit = GedcomX.Person.prototype.init; 11 | GedcomX.Person.prototype.init = function(json){ 12 | oldInit.call(this, json); 13 | if(json){ 14 | this.setLiving(json.living); 15 | this.setDisplay(json.display); 16 | } 17 | }; 18 | 19 | /** 20 | * Set the living flag 21 | * 22 | * @function setLiving 23 | * @instance 24 | * @memberof Person 25 | * @param {Boolean} living 26 | * @return {Person} this 27 | */ 28 | GedcomX.Person.prototype.setLiving = function(living){ 29 | this.living = living; 30 | return this; 31 | }; 32 | 33 | /** 34 | * Get the living flag 35 | * 36 | * @function getLiving 37 | * @instance 38 | * @memberof Person 39 | * @return {Boolean} living 40 | */ 41 | GedcomX.Person.prototype.getLiving = function(){ 42 | return this.living; 43 | }; 44 | 45 | /** 46 | * Set the display properties 47 | * 48 | * @function setDisplay 49 | * @instance 50 | * @memberof Person 51 | * @param {DisplayProperties} display 52 | * @return {Person} this 53 | */ 54 | GedcomX.Person.prototype.setDisplay = function(display){ 55 | if(display){ 56 | this.display = GedcomX.DisplayProperties(display); 57 | } 58 | return this; 59 | }; 60 | 61 | /** 62 | * Get the display properties 63 | * 64 | * @function getDisplay 65 | * @instance 66 | * @memberof Person 67 | * @return {DisplayProperties} 68 | */ 69 | GedcomX.Person.prototype.getDisplay = function(){ 70 | return this.display; 71 | }; 72 | 73 | /** 74 | * Get a person's preferred name, if one exists. 75 | * 76 | * @function getPreferredName 77 | * @instance 78 | * @memberof Person 79 | * @return {Name} 80 | */ 81 | GedcomX.Person.prototype.getPreferredName = function(){ 82 | return this.getNames().find(function(n){ 83 | return n.getPreferred(); 84 | }); 85 | }; 86 | 87 | }; -------------------------------------------------------------------------------- /src/rs/PlaceDescription.js: -------------------------------------------------------------------------------- 1 | /** 2 | * RS extensions to PlaceDescription 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.PlaceDescription.jsonProps.push('display'); 8 | 9 | // Override init() so that we can deserialize normalized values 10 | var oldInit = GedcomX.PlaceDescription.prototype.init; 11 | GedcomX.PlaceDescription.prototype.init = function(json){ 12 | oldInit.call(this, json); 13 | if(json){ 14 | this.setDisplay(json.display); 15 | } 16 | }; 17 | 18 | /** 19 | * Set the display properties 20 | * 21 | * @function setDisplay 22 | * @instance 23 | * @memberof PlaceDescription 24 | * @param {PlaceDisplayProperties} display 25 | * @return {PlaceDescription} this 26 | */ 27 | GedcomX.PlaceDescription.prototype.setDisplay = function(display){ 28 | if(display){ 29 | this.display = GedcomX.PlaceDisplayProperties(display); 30 | } 31 | return this; 32 | }; 33 | 34 | /** 35 | * Get the display properties 36 | * 37 | * @function getDisplay 38 | * @instance 39 | * @memberof PlaceDescription 40 | * @return {PlaceDisplayProperties} 41 | */ 42 | GedcomX.PlaceDescription.prototype.getDisplay = function(){ 43 | return this.display; 44 | }; 45 | 46 | }; -------------------------------------------------------------------------------- /src/rs/PlaceReference.js: -------------------------------------------------------------------------------- 1 | /** 2 | * RS extensions to PlaceReference 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.PlaceReference.jsonProps.push('normalized'); 8 | 9 | // Override init() so that we can deserialize normalized values 10 | var oldInit = GedcomX.PlaceReference.prototype.init; 11 | GedcomX.PlaceReference.prototype.init = function(json){ 12 | oldInit.call(this, json); 13 | if(json){ 14 | this.setNormalized(json.normalized); 15 | } 16 | }; 17 | 18 | /** 19 | * Set the normalized values 20 | * 21 | * @function setNormalized 22 | * @instance 23 | * @memberof PlaceReference 24 | * @param {TextValue[]} normalized 25 | * @return {PlaceReference} this 26 | */ 27 | GedcomX.PlaceReference.prototype.setNormalized = function(normalized){ 28 | return this._setArray(normalized, 'normalized', 'addNormalized'); 29 | }; 30 | 31 | /** 32 | * Add a normalized value 33 | * 34 | * @function addNormalized 35 | * @instance 36 | * @memberof PlaceReference 37 | * @param {TextValue} normalized 38 | * @return {PlaceReference} this 39 | */ 40 | GedcomX.PlaceReference.prototype.addNormalized = function(normalized){ 41 | return this._arrayPush(normalized, 'normalized', GedcomX.TextValue); 42 | }; 43 | 44 | /** 45 | * Get the normalized values 46 | * 47 | * @function getNormalized 48 | * @instance 49 | * @memberof PlaceReference 50 | * @return {TextValue[]} 51 | */ 52 | GedcomX.PlaceReference.prototype.getNormalized = function(){ 53 | return this.normalized || []; 54 | }; 55 | 56 | }; -------------------------------------------------------------------------------- /src/rs/ResourceReference.js: -------------------------------------------------------------------------------- 1 | /** 2 | * RS extensions to ResourceReference 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.ResourceReference.jsonProps.push('resourceId'); 8 | 9 | // Override init() so that we can deserialize normalized values 10 | var oldInit = GedcomX.ResourceReference.prototype.init; 11 | GedcomX.ResourceReference.prototype.init = function(json){ 12 | oldInit.call(this, json); 13 | if(json){ 14 | this.setResourceId(json.resourceId); 15 | } 16 | }; 17 | 18 | /** 19 | * Set the resourceId 20 | * 21 | * @function setResourceId 22 | * @instance 23 | * @memberof ResourceReference 24 | * @param {Boolean} resourceId 25 | * @return {ResourceReference} this 26 | */ 27 | GedcomX.ResourceReference.prototype.setResourceId = function(resourceId){ 28 | this.resourceId = resourceId; 29 | return this; 30 | }; 31 | 32 | /** 33 | * Get the resourceId 34 | * 35 | * @function getResourceId 36 | * @instance 37 | * @memberof ResourceReference 38 | * @return {Boolean} resourceId 39 | */ 40 | GedcomX.ResourceReference.prototype.getResourceId = function(){ 41 | return this.resourceId; 42 | }; 43 | 44 | }; -------------------------------------------------------------------------------- /src/rs/SourceDescription.js: -------------------------------------------------------------------------------- 1 | /** 2 | * RS extensions to SourceDescription 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Extend serialization properties 7 | GedcomX.SourceDescription.jsonProps.push('sortKey', 'version'); 8 | 9 | // Override init() so that we can deserialize normalized values 10 | var oldInit = GedcomX.SourceDescription.prototype.init; 11 | GedcomX.SourceDescription.prototype.init = function(json){ 12 | oldInit.call(this, json); 13 | if(json){ 14 | this.setSortKey(json.sortKey); 15 | this.setVersion(json.version); 16 | } 17 | }; 18 | 19 | /** 20 | * Set the sortKey 21 | * 22 | * @function setSortKey 23 | * @instance 24 | * @memberof SourceDescription 25 | * @param {Boolean} sortKey 26 | * @return {SourceDescription} this 27 | */ 28 | GedcomX.SourceDescription.prototype.setSortKey = function(sortKey){ 29 | this.sortKey = sortKey; 30 | return this; 31 | }; 32 | 33 | /** 34 | * Get the sortKey 35 | * 36 | * @function getSortKey 37 | * @instance 38 | * @memberof SourceDescription 39 | * @return {Boolean} sortKey 40 | */ 41 | GedcomX.SourceDescription.prototype.getSortKey = function(){ 42 | return this.sortKey; 43 | }; 44 | 45 | /** 46 | * Set the version 47 | * 48 | * @function setVersion 49 | * @instance 50 | * @memberof SourceDescription 51 | * @param {String} version 52 | * @return {SourceDescription} this 53 | */ 54 | GedcomX.SourceDescription.prototype.setVersion = function(version){ 55 | this.version = version; 56 | return this; 57 | }; 58 | 59 | /** 60 | * Get the version 61 | * 62 | * @function getVersion 63 | * @instance 64 | * @memberof SourceDescription 65 | * @return {String} 66 | */ 67 | GedcomX.SourceDescription.prototype.getVersion = function(){ 68 | return this.version; 69 | }; 70 | 71 | }; -------------------------------------------------------------------------------- /src/rs/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Setup Gedcom X RS Extensions 3 | */ 4 | module.exports = function(GedcomX){ 5 | 6 | // Add new classes 7 | require('./Link')(GedcomX); 8 | require('./Links')(GedcomX); 9 | require('./FamilyView')(GedcomX); 10 | require('./DisplayProperties')(GedcomX); 11 | require('./PlaceDisplayProperties')(GedcomX); 12 | 13 | // Extend existing classes 14 | require('./ExtensibleData')(GedcomX); 15 | require('./Date')(GedcomX); 16 | require('./PlaceReference')(GedcomX); 17 | require('./Name')(GedcomX); 18 | require('./Person')(GedcomX); 19 | require('./ResourceReference')(GedcomX); 20 | require('./Conclusion')(GedcomX); 21 | require('./SourceDescription')(GedcomX); 22 | require('./PlaceDescription')(GedcomX); 23 | }; -------------------------------------------------------------------------------- /test/atom/AtomCategory.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('AtomCategory', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.AtomCategory(), GedcomX.AtomCategory, 'An instance of AtomCategory is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.AtomCategory(), GedcomX.AtomCategory, 'An instance of AtomCategory is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var category = GedcomX.AtomCategory({ 13 | scheme: 'scheme', 14 | term: 'term', 15 | label: 'label' 16 | }); 17 | assert.equal(category.getScheme(), 'scheme'); 18 | assert.equal(category.getTerm(), 'term'); 19 | assert.equal(category.getLabel(), 'label'); 20 | }); 21 | 22 | it('Build', function(){ 23 | var category = GedcomX.AtomCategory() 24 | .setScheme('scheme') 25 | .setTerm('term') 26 | .setLabel('label'); 27 | assert.equal(category.getScheme(), 'scheme'); 28 | assert.equal(category.getTerm(), 'term'); 29 | assert.equal(category.getLabel(), 'label'); 30 | }); 31 | 32 | it('toJSON', function(){ 33 | var data = { 34 | scheme: 'scheme', 35 | term: 'term', 36 | label: 'label' 37 | }, category = GedcomX.AtomCategory(data); 38 | assert.deepEqual(category.toJSON(), data); 39 | }); 40 | 41 | it('constructor does not copy instances', function(){ 42 | var obj1 = GedcomX.AtomCategory(); 43 | var obj2 = GedcomX.AtomCategory(obj1); 44 | assert.strictEqual(obj1, obj2); 45 | }); 46 | 47 | }); -------------------------------------------------------------------------------- /test/atom/AtomCommon.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | AtomCommon = require('../../src/atom/AtomCommon'); 3 | 4 | describe('AtomCommon', function(){ 5 | 6 | it('init from JSON', function(){ 7 | var common = AtomCommon({ 8 | base: 'base', 9 | lang: 'lang' 10 | }); 11 | assert.equal(common.getBase(), 'base'); 12 | assert.equal(common.getLang(), 'lang'); 13 | }); 14 | 15 | it('build', function(){ 16 | var common = AtomCommon() 17 | .setBase('base') 18 | .setLang('lang'); 19 | assert.equal(common.getBase(), 'base'); 20 | assert.equal(common.getLang(), 'lang'); 21 | }); 22 | 23 | it('toJSON', function(){ 24 | var data = { 25 | base: 'base', 26 | lang: 'lang' 27 | }; 28 | assert.deepEqual(AtomCommon(data).toJSON(), data); 29 | }); 30 | 31 | }); -------------------------------------------------------------------------------- /test/atom/AtomContent.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('AtomContent', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.AtomContent(), GedcomX.AtomContent, 'An instance of AtomContent is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.AtomContent(), GedcomX.AtomContent, 'An instance of AtomContent is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var content = GedcomX.AtomContent({ 13 | gedcomx: { 14 | description: '#root' 15 | } 16 | }); 17 | assert.equal(content.getGedcomX().getDescription(), '#root'); 18 | }); 19 | 20 | it('Build', function(){ 21 | var content = GedcomX.AtomContent() 22 | .setGedcomX(GedcomX().setDescription('#root')); 23 | assert.equal(content.getGedcomX().getDescription(), '#root'); 24 | }); 25 | 26 | it('toJSON', function(){ 27 | var data = { 28 | gedcomx: { 29 | description: '#root' 30 | } 31 | }, content = GedcomX.AtomContent(data); 32 | assert.deepEqual(content.toJSON(), data); 33 | }); 34 | 35 | it('constructor does not copy instances', function(){ 36 | var obj1 = GedcomX.AtomContent(); 37 | var obj2 = GedcomX.AtomContent(obj1); 38 | assert.strictEqual(obj1, obj2); 39 | }); 40 | 41 | }); -------------------------------------------------------------------------------- /test/atom/AtomGenerator.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('AtomGenerator', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.AtomGenerator(), GedcomX.AtomGenerator, 'An instance of AtomGenerator is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.AtomGenerator(), GedcomX.AtomGenerator, 'An instance of AtomGenerator is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var generator = GedcomX.AtomGenerator({ 13 | uri: 'uri', 14 | version: 'version', 15 | value: 'value' 16 | }); 17 | assert.equal(generator.getUri(), 'uri'); 18 | assert.equal(generator.getVersion(), 'version'); 19 | assert.equal(generator.getValue(), 'value'); 20 | }); 21 | 22 | it('Build', function(){ 23 | var generator = GedcomX.AtomGenerator() 24 | .setUri('uri') 25 | .setVersion('version') 26 | .setValue('value'); 27 | assert.equal(generator.getUri(), 'uri'); 28 | assert.equal(generator.getVersion(), 'version'); 29 | assert.equal(generator.getValue(), 'value'); 30 | }); 31 | 32 | it('toJSON', function(){ 33 | var data = { 34 | uri: 'uri', 35 | version: 'version', 36 | value: 'value' 37 | }, generator = GedcomX.AtomGenerator(data); 38 | assert.deepEqual(generator.toJSON(), data); 39 | }); 40 | 41 | it('constructor does not copy instances', function(){ 42 | var obj1 = GedcomX.AtomGenerator(); 43 | var obj2 = GedcomX.AtomGenerator(obj1); 44 | assert.strictEqual(obj1, obj2); 45 | }); 46 | 47 | }); -------------------------------------------------------------------------------- /test/atom/AtomPerson.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('AtomPerson', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.AtomPerson(), GedcomX.AtomPerson, 'An instance of AtomPerson is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.AtomPerson(), GedcomX.AtomPerson, 'An instance of AtomPerson is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var person = GedcomX.AtomPerson({ 13 | uri: 'uri', 14 | name: 'name', 15 | email: 'email' 16 | }); 17 | assert.equal(person.getUri(), 'uri'); 18 | assert.equal(person.getName(), 'name'); 19 | assert.equal(person.getEmail(), 'email'); 20 | }); 21 | 22 | it('Build', function(){ 23 | var person = GedcomX.AtomPerson() 24 | .setUri('uri') 25 | .setName('name') 26 | .setEmail('email'); 27 | assert.equal(person.getUri(), 'uri'); 28 | assert.equal(person.getName(), 'name'); 29 | assert.equal(person.getEmail(), 'email'); 30 | }); 31 | 32 | it('toJSON', function(){ 33 | var data = { 34 | uri: 'uri', 35 | name: 'name', 36 | email: 'email' 37 | }, person = GedcomX.AtomPerson(data); 38 | assert.deepEqual(person.toJSON(), data); 39 | }); 40 | 41 | it('constructor does not copy instances', function(){ 42 | var obj1 = GedcomX.AtomPerson(); 43 | var obj2 = GedcomX.AtomPerson(obj1); 44 | assert.strictEqual(obj1, obj2); 45 | }); 46 | 47 | }); -------------------------------------------------------------------------------- /test/atom/index.js: -------------------------------------------------------------------------------- 1 | // Enable Atom Extensions so that we can test them 2 | var GedcomX = require('../../'); 3 | GedcomX.enableAtomExtensions(); 4 | 5 | // Call it again to test that it doesn't break/change anything 6 | GedcomX.enableAtomExtensions(); -------------------------------------------------------------------------------- /test/core/Address.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Address', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.Address(), GedcomX.Address, 'An instance of Address is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.Address(), GedcomX.Address, 'An instance of Address is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var address = GedcomX.Address({ 13 | value: 'big\nstreet\naddress', 14 | city: 'big city', 15 | country: 'COUNTRY', 16 | postalCode: '98765', 17 | stateOrProvince: 'ST', 18 | street: 'a street', 19 | street2: '2nd street', 20 | street3: '3rd street', 21 | street4: 'no way', 22 | street5: 'high way', 23 | street6: 'wow' 24 | }); 25 | assert.equal(address.getValue(), 'big\nstreet\naddress'); 26 | assert.equal(address.getCity(), 'big city'); 27 | assert.equal(address.getCountry(), 'COUNTRY'); 28 | assert.equal(address.getPostalCode(), '98765'); 29 | assert.equal(address.getStateOrProvince(), 'ST'); 30 | assert.equal(address.getStreet(), 'a street'); 31 | assert.equal(address.getStreet2(), '2nd street'); 32 | assert.equal(address.getStreet3(), '3rd street'); 33 | assert.equal(address.getStreet4(), 'no way'); 34 | assert.equal(address.getStreet5(), 'high way'); 35 | assert.equal(address.getStreet6(), 'wow'); 36 | }); 37 | 38 | it('Build', function(){ 39 | var address = GedcomX.Address() 40 | .setValue('big\nstreet\naddress') 41 | .setCity('big city') 42 | .setCountry('COUNTRY') 43 | .setPostalCode('98765') 44 | .setStateOrProvince('ST') 45 | .setStreet('a street') 46 | .setStreet2('2nd street') 47 | .setStreet3('3rd street') 48 | .setStreet4('no way') 49 | .setStreet5('high way') 50 | .setStreet6('wow'); 51 | assert.equal(address.getValue(), 'big\nstreet\naddress'); 52 | assert.equal(address.getCity(), 'big city'); 53 | assert.equal(address.getCountry(), 'COUNTRY'); 54 | assert.equal(address.getPostalCode(), '98765'); 55 | assert.equal(address.getStateOrProvince(), 'ST'); 56 | assert.equal(address.getStreet(), 'a street'); 57 | assert.equal(address.getStreet2(), '2nd street'); 58 | assert.equal(address.getStreet3(), '3rd street'); 59 | assert.equal(address.getStreet4(), 'no way'); 60 | assert.equal(address.getStreet5(), 'high way'); 61 | assert.equal(address.getStreet6(), 'wow'); 62 | }); 63 | 64 | it('toJSON', function(){ 65 | var data = { 66 | value: 'big\nstreet\naddress', 67 | city: 'big city', 68 | country: 'COUNTRY', 69 | postalCode: '98765', 70 | stateOrProvince: 'ST', 71 | street: 'a street', 72 | street2: '2nd street', 73 | street3: '3rd street', 74 | street4: 'no way', 75 | street5: 'high way', 76 | street6: 'wow' 77 | }, address = GedcomX.Address(data); 78 | assert.deepEqual(address.toJSON(), data); 79 | }); 80 | 81 | it('constructor does not copy instances', function(){ 82 | var obj1 = GedcomX.Address(); 83 | var obj2 = GedcomX.Address(obj1); 84 | assert.strictEqual(obj1, obj2); 85 | }); 86 | 87 | }); -------------------------------------------------------------------------------- /test/core/Coverage.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Coverage', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.Coverage(), GedcomX.Coverage, 'An instance of Coverage is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.Coverage(), GedcomX.Coverage, 'An instance of Coverage is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var coverage = GedcomX.Coverage({ 13 | spatial: { 14 | original: 'A Place' 15 | }, 16 | temporal: { 17 | formal: '+2015-01-03' 18 | } 19 | }); 20 | assert.equal(coverage.getSpatial().getOriginal(), 'A Place'); 21 | assert.equal(coverage.getTemporal().getFormal(), '+2015-01-03'); 22 | }); 23 | 24 | it('Create with mixed', function(){ 25 | var coverage = GedcomX.Coverage({ 26 | spatial: GedcomX.PlaceReference({ 27 | original: 'A Place' 28 | }), 29 | temporal: GedcomX.Date({ 30 | formal: '+2015-01-03' 31 | }) 32 | }); 33 | assert.equal(coverage.getSpatial().getOriginal(), 'A Place'); 34 | assert.equal(coverage.getTemporal().getFormal(), '+2015-01-03'); 35 | }); 36 | 37 | it('Build', function(){ 38 | var coverage = GedcomX.Coverage() 39 | .setSpatial(GedcomX.PlaceReference().setOriginal('A Place')) 40 | .setTemporal(GedcomX.Date().setFormal('+2015-01-03')); 41 | assert.equal(coverage.getSpatial().getOriginal(), 'A Place'); 42 | assert.equal(coverage.getTemporal().getFormal(), '+2015-01-03'); 43 | }); 44 | 45 | it('toJSON', function(){ 46 | var data = { 47 | spatial: { 48 | original: 'A Place' 49 | }, 50 | temporal: { 51 | formal: '+2015-01-03' 52 | } 53 | }, coverage = GedcomX.Coverage(data); 54 | assert.deepEqual(coverage.toJSON(), data); 55 | }); 56 | 57 | it('constructor does not copy instances', function(){ 58 | var obj1 = GedcomX.Coverage(); 59 | var obj2 = GedcomX.Coverage(obj1); 60 | assert.strictEqual(obj1, obj2); 61 | }); 62 | 63 | }); -------------------------------------------------------------------------------- /test/core/Date.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Date', function(){ 5 | 6 | it('Create plain', function(){ 7 | var newGDate = new GedcomX.Date(), 8 | date = GedcomX.Date(); 9 | assert.instanceOf(newGDate, GedcomX.Date, 'An instance of GedcomX.Date is not returned when calling the constructor with new.'); 10 | assert.instanceOf(date, GedcomX.Date, 'An instance of GedcomX.Date is not returned when calling the constructor without new.'); 11 | }); 12 | 13 | it('Create with JSON', function(){ 14 | var date = GedcomX.Date({ 15 | id: 'date', 16 | original: 'June 24 1899', 17 | formal: '+1899-06-24' 18 | }); 19 | assert.equal(date.getId(), 'date'); 20 | assert.equal(date.getOriginal(), 'June 24 1899'); 21 | assert.equal(date.getFormal(), '+1899-06-24'); 22 | }); 23 | 24 | it('Build', function(){ 25 | var date = GedcomX.Date() 26 | .setId('date') 27 | .setOriginal('June 24 1899') 28 | .setFormal('+1899-06-24'); 29 | assert.equal(date.getId(), 'date'); 30 | assert.equal(date.getOriginal(), 'June 24 1899'); 31 | assert.equal(date.getFormal(), '+1899-06-24'); 32 | }); 33 | 34 | it('toJSON', function(){ 35 | var data = { 36 | id: 'date', 37 | original: 'June 24 1899', 38 | formal: '+1899-06-24' 39 | }, date = GedcomX.Date(data); 40 | assert.deepEqual(date.toJSON(), data); 41 | }); 42 | 43 | it('constructor does not copy instances', function(){ 44 | var obj1 = GedcomX.Date(); 45 | var obj2 = GedcomX.Date(obj1); 46 | assert.strictEqual(obj1, obj2); 47 | }); 48 | 49 | }); -------------------------------------------------------------------------------- /test/core/Document.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Document', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(GedcomX.Document(), GedcomX.Document, 'An instance of Document is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.Document(), GedcomX.Document, 'An instance of Document is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var doc = GedcomX.Document({ 13 | type: 'http://gedcomx.org/Abstract', 14 | extracted: false, 15 | textType: 'plain', 16 | text: 'Lots of text', 17 | attribution: { 18 | created: 123456789 19 | } 20 | }); 21 | assert.equal(doc.getType(), 'http://gedcomx.org/Abstract'); 22 | assert.equal(doc.getExtracted(), false); 23 | assert.equal(doc.getTextType(), 'plain'); 24 | assert.equal(doc.getText(), 'Lots of text'); 25 | assert.equal(doc.getAttribution().getCreated().getTime(), 123456789); 26 | }); 27 | 28 | it('Create with mixed data', function(){ 29 | var doc = GedcomX.Document({ 30 | type: 'http://gedcomx.org/Abstract', 31 | extracted: false, 32 | textType: 'plain', 33 | text: 'Lots of text', 34 | attribution: GedcomX.Attribution({ 35 | created: 123456789 36 | }) 37 | }); 38 | assert.equal(doc.getType(), 'http://gedcomx.org/Abstract'); 39 | assert.equal(doc.getExtracted(), false); 40 | assert.equal(doc.getTextType(), 'plain'); 41 | assert.equal(doc.getText(), 'Lots of text'); 42 | assert.equal(doc.getAttribution().getCreated().getTime(), 123456789); 43 | }); 44 | 45 | it('Build', function(){ 46 | var doc = GedcomX.Document() 47 | .setType('http://gedcomx.org/Abstract') 48 | .setExtracted(false) 49 | .setTextType('plain') 50 | .setText('Lots of text') 51 | .setAttribution(GedcomX.Attribution().setCreated(123456789)); 52 | assert.equal(doc.getType(), 'http://gedcomx.org/Abstract'); 53 | assert.equal(doc.getExtracted(), false); 54 | assert.equal(doc.getTextType(), 'plain'); 55 | assert.equal(doc.getText(), 'Lots of text'); 56 | assert.equal(doc.getAttribution().getCreated().getTime(), 123456789); 57 | }); 58 | 59 | it('toJSON', function(){ 60 | var data = { 61 | type: 'http://gedcomx.org/Abstract', 62 | extracted: false, 63 | textType: 'plain', 64 | text: 'Lots of text', 65 | attribution: { 66 | created: 123456789 67 | } 68 | }, doc = GedcomX.Document(data); 69 | assert.deepEqual(doc.toJSON(), data); 70 | }); 71 | 72 | it('constructor does not copy instances', function(){ 73 | var obj1 = GedcomX.Document(); 74 | var obj2 = GedcomX.Document(obj1); 75 | assert.strictEqual(obj1, obj2); 76 | }); 77 | 78 | }); -------------------------------------------------------------------------------- /test/core/EventRole.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('EventRole', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(GedcomX.EventRole(), GedcomX.EventRole, 'An instance of EventRole is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.EventRole(), GedcomX.EventRole, 'An instance of EventRole is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var role = GedcomX.EventRole({ 13 | person: { 14 | resource: 'http://person' 15 | }, 16 | type: 'http://gedcomx.org/Witness', 17 | details: 'One of two witnesses' 18 | }); 19 | assert.equal(role.getPerson().getResource(), 'http://person'); 20 | assert.equal(role.getType(), 'http://gedcomx.org/Witness'); 21 | assert.equal(role.getDetails(), 'One of two witnesses'); 22 | }); 23 | 24 | it('Create with mixed data', function(){ 25 | var role = GedcomX.EventRole({ 26 | person: GedcomX.ResourceReference({ 27 | resource: 'http://person' 28 | }), 29 | type: 'http://gedcomx.org/Witness', 30 | details: 'One of two witnesses' 31 | }); 32 | assert.equal(role.getPerson().getResource(), 'http://person'); 33 | assert.equal(role.getType(), 'http://gedcomx.org/Witness'); 34 | assert.equal(role.getDetails(), 'One of two witnesses'); 35 | }); 36 | 37 | it('Build', function(){ 38 | var role = GedcomX.EventRole() 39 | .setPerson(GedcomX.ResourceReference().setResource('http://person')) 40 | .setType('http://gedcomx.org/Witness') 41 | .setDetails('One of two witnesses'); 42 | assert.equal(role.getPerson().getResource(), 'http://person'); 43 | assert.equal(role.getType(), 'http://gedcomx.org/Witness'); 44 | assert.equal(role.getDetails(), 'One of two witnesses'); 45 | }); 46 | 47 | it('toJSON', function(){ 48 | var data = { 49 | person: { 50 | resource: 'http://person' 51 | }, 52 | type: 'http://gedcomx.org/Witness', 53 | details: 'One of two witnesses' 54 | }, role = GedcomX.EventRole(data); 55 | assert.deepEqual(role.toJSON(), data); 56 | }); 57 | 58 | it('constructor does not copy instances', function(){ 59 | var obj1 = GedcomX.EventRole(); 60 | var obj2 = GedcomX.EventRole(obj1); 61 | assert.strictEqual(obj1, obj2); 62 | }); 63 | 64 | }); -------------------------------------------------------------------------------- /test/core/EvidenceReference.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('EvidenceReference', function(){ 5 | 6 | it('Create plain', function(){ 7 | var newER = new GedcomX.EvidenceReference(), 8 | er = GedcomX.EvidenceReference(); 9 | assert.instanceOf(newER, GedcomX.EvidenceReference, 'An instance of EvidenceReference is not returned when calling the constructor with new.'); 10 | assert.instanceOf(er, GedcomX.EvidenceReference, 'An instance of EvidenceReference is not returned when calling the constructor without new.'); 11 | }); 12 | 13 | it('Create with JSON', function(){ 14 | var er = GedcomX.EvidenceReference({ 15 | resource: 'http://example.com', 16 | attribution: { 17 | created: 1248942374 18 | } 19 | }); 20 | assert.equal(er.getResource(), 'http://example.com', 'Resource not saved properly when created with JSON'); 21 | assert.equal(er.getAttribution().getCreated().getTime(), 1248942374); 22 | }); 23 | 24 | it('Build', function(){ 25 | var er = GedcomX.EvidenceReference() 26 | .setResource('http://newuri.com') 27 | .setAttribution({ 28 | created: new Date(1248942374) 29 | }); 30 | assert.equal(er.getResource(), 'http://newuri.com'); 31 | assert.equal(er.getAttribution().getCreated().getTime(), 1248942374); 32 | }); 33 | 34 | it('toJSON()', function(){ 35 | var erData = { 36 | resource: 'http://example.com', 37 | attribution: { 38 | created: 1248942374 39 | } 40 | }, 41 | er = GedcomX.EvidenceReference(erData); 42 | assert.deepEqual(er.toJSON(), erData); 43 | }); 44 | 45 | it('constructor does not copy instances', function(){ 46 | var obj1 = GedcomX.EvidenceReference(); 47 | var obj2 = GedcomX.EvidenceReference(obj1); 48 | assert.strictEqual(obj1, obj2); 49 | }); 50 | 51 | }); -------------------------------------------------------------------------------- /test/core/ExtensibleData.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('ExtensibleData', function(){ 5 | 6 | it('Create plain', function(){ 7 | var newEd = new GedcomX.ExtensibleData(), 8 | ed = GedcomX.ExtensibleData(); 9 | assert.instanceOf(newEd, GedcomX.ExtensibleData, 'An instance of ExtensibleData is not returned when calling the constructor with new.'); 10 | assert.instanceOf(ed, GedcomX.ExtensibleData, 'An instance of ExtensibleData is not returned when calling the constructor without new.'); 11 | }); 12 | 13 | it('Create with JSON', function(){ 14 | var ed = GedcomX.ExtensibleData({ id: 'edid' }); 15 | assert.equal(ed.getId(), 'edid', 'ID not saved properly when created with JSON'); 16 | }); 17 | 18 | it('Change ID', function(){ 19 | var ed = GedcomX.ExtensibleData({ id: 'edid' }); 20 | ed.setId('newId'); 21 | assert.equal(ed.getId(), 'newId', 'ID not saved properly when changed with setId()'); 22 | }); 23 | 24 | it('toJSON()', function(){ 25 | var ed = GedcomX.ExtensibleData({ id: 'firstId' }); 26 | ed.setId('newId'); 27 | assert.deepEqual(ed.toJSON(), {id:'newId'}, 'JSON export is incorrect'); 28 | }); 29 | 30 | it('constructor does not copy instances', function(){ 31 | var obj1 = GedcomX.ExtensibleData(); 32 | var obj2 = GedcomX.ExtensibleData(obj1); 33 | assert.strictEqual(obj1, obj2); 34 | }); 35 | 36 | }); -------------------------------------------------------------------------------- /test/core/Gender.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Gender', function(){ 5 | 6 | it('Create plain', function(){ 7 | var newGender = new GedcomX.Gender(), 8 | gender = GedcomX.Gender(); 9 | assert.instanceOf(newGender, GedcomX.Gender, 'An instance of Gender is not returned when calling the constructor with new.'); 10 | assert.instanceOf(gender, GedcomX.Gender, 'An instance of Gender is not returned when calling the constructor without new.'); 11 | }); 12 | 13 | it('Create with JSON', function(){ 14 | var gender = GedcomX.Gender({ 15 | id: 'gender', 16 | type: 'http://gedcomx.org/Male', 17 | confidence: 'http://gedcomx.org/High', 18 | attribution: { 19 | created: 1145667891 20 | } 21 | }); 22 | assert.equal(gender.getId(), 'gender'); 23 | assert.equal(gender.getType(), 'http://gedcomx.org/Male'); 24 | assert.equal(gender.getConfidence(), 'http://gedcomx.org/High'); 25 | assert.equal(gender.getAttribution().getCreated().getTime(), 1145667891); 26 | }); 27 | 28 | it('Build', function(){ 29 | var gender = GedcomX.Gender() 30 | .setId('gender') 31 | .setType('http://gedcomx.org/Female') 32 | .setConfidence('http://gedcomx.org/High') 33 | .setAttribution({ 34 | created: 1145667891 35 | }); 36 | assert.equal(gender.getId(), 'gender'); 37 | assert.equal(gender.getType(), 'http://gedcomx.org/Female'); 38 | assert.equal(gender.getConfidence(), 'http://gedcomx.org/High'); 39 | assert.equal(gender.getAttribution().getCreated().getTime(), 1145667891); 40 | }); 41 | 42 | it('toJSON', function(){ 43 | var genderData = { 44 | id: 'gender', 45 | type: 'http://gedcomx.org/Male', 46 | confidence: 'http://gedcomx.org/High', 47 | attribution: { 48 | created: 1145667891 49 | } 50 | }, gender = GedcomX.Gender(genderData); 51 | assert.deepEqual(gender.toJSON(), genderData); 52 | }); 53 | 54 | it('constructor does not copy instances', function(){ 55 | var obj1 = GedcomX.Gender(); 56 | var obj2 = GedcomX.Gender(obj1); 57 | assert.strictEqual(obj1, obj2); 58 | }); 59 | 60 | }); -------------------------------------------------------------------------------- /test/core/Identifiers.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Identifiers', function(){ 5 | 6 | it('Create plain', function(){ 7 | var newIdent = new GedcomX.Identifiers(), 8 | ident = GedcomX.Identifiers(); 9 | assert.instanceOf(newIdent, GedcomX.Identifiers, 'An instance of Identifiers is not returned when calling the constructor with new.'); 10 | assert.instanceOf(ident, GedcomX.Identifiers, 'An instance of Identifiers is not returned when calling the constructor without new.'); 11 | }); 12 | 13 | it('Create with JSON', function(){ 14 | var ident = GedcomX.Identifiers({ 15 | $: [ 'value_with_no_type' ], 16 | list: [ 'one', 'two' ], 17 | collapse: 'single_value' 18 | }); 19 | assert.deepEqual(ident.getValues(), [ 'value_with_no_type' ]); 20 | assert.deepEqual(ident.getValues('list'), [ 'one', 'two' ]); 21 | assert.deepEqual(ident.getValues('collapse'), [ 'single_value' ]); 22 | }); 23 | 24 | it('Build', function(){ 25 | var ident = GedcomX.Identifiers(); 26 | ident.addValue('value_with_no_type'); 27 | ident.addValue('one', 'list'); 28 | ident.addValue('two', 'list'); 29 | ident.addValue('single_value', 'collapse'); 30 | assert.deepEqual(ident.getValues(), [ 'value_with_no_type' ]); 31 | assert.deepEqual(ident.getValues('list'), [ 'one', 'two' ]); 32 | assert.deepEqual(ident.getValues('collapse'), [ 'single_value' ]); 33 | }); 34 | 35 | it('toJSON() and single string collapsing', function(){ 36 | var ident = GedcomX.Identifiers({ 37 | $: [ 'value_with_no_type' ], 38 | list: [ 'one', 'two' ], 39 | collapse: 'single_value' 40 | }); 41 | assert.deepEqual(ident.toJSON(), { 42 | $: [ 'value_with_no_type' ], 43 | list: [ 'one', 'two' ], 44 | collapse: [ 'single_value' ] 45 | }); 46 | }); 47 | 48 | it('constructor does not copy instances', function(){ 49 | var obj1 = GedcomX.Identifiers(); 50 | var obj2 = GedcomX.Identifiers(obj1); 51 | assert.strictEqual(obj1, obj2); 52 | }); 53 | 54 | }); -------------------------------------------------------------------------------- /test/core/NamePart.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('NamePart', function(){ 5 | 6 | it('Create plain', function(){ 7 | var newNamePart = new GedcomX.NamePart(), 8 | part = GedcomX.NamePart(); 9 | assert.instanceOf(newNamePart, GedcomX.NamePart, 'An instance of NamePart is not returned when calling the constructor with new.'); 10 | assert.instanceOf(part, GedcomX.NamePart, 'An instance of NamePart is not returned when calling the constructor without new.'); 11 | }); 12 | 13 | it('Create with JSON', function(){ 14 | var part = GedcomX.NamePart({ 15 | id: 'namepart', 16 | type: 'http://gedcomx.org/Given', 17 | value: 'Jonathan', 18 | qualifiers: [ 19 | { 20 | name: 'http://gedcomx.org/Primary' 21 | } 22 | ] 23 | }); 24 | assert.equal(part.getId(), 'namepart'); 25 | assert.equal(part.getType(), 'http://gedcomx.org/Given'); 26 | assert.equal(part.getValue(), 'Jonathan'); 27 | assert.equal(part.getQualifiers().length, 1); 28 | assert.equal(part.getQualifiers()[0].getName(), 'http://gedcomx.org/Primary'); 29 | }); 30 | 31 | it('Create with mixed data', function(){ 32 | var part = GedcomX.NamePart({ 33 | id: 'namepart', 34 | type: 'http://gedcomx.org/Given', 35 | value: 'Jonathan', 36 | qualifiers: [ 37 | GedcomX.Qualifier({ 38 | name: 'http://gedcomx.org/Primary' 39 | }) 40 | ] 41 | }); 42 | assert.equal(part.getId(), 'namepart'); 43 | assert.equal(part.getType(), 'http://gedcomx.org/Given'); 44 | assert.equal(part.getValue(), 'Jonathan'); 45 | assert.equal(part.getQualifiers().length, 1); 46 | assert.equal(part.getQualifiers()[0].getName(), 'http://gedcomx.org/Primary'); 47 | }); 48 | 49 | it('Build', function(){ 50 | var part = GedcomX.NamePart() 51 | .setId('namepart') 52 | .setType('http://gedcomx.org/Given') 53 | .setValue('Jonathan') 54 | .addQualifier(GedcomX.Qualifier().setName('http://gedcomx.org/Primary')); 55 | assert.equal(part.getId(), 'namepart'); 56 | assert.equal(part.getType(), 'http://gedcomx.org/Given'); 57 | assert.equal(part.getValue(), 'Jonathan'); 58 | assert.equal(part.getQualifiers().length, 1); 59 | assert.equal(part.getQualifiers()[0].getName(), 'http://gedcomx.org/Primary'); 60 | }); 61 | 62 | it('toJSON', function(){ 63 | var data = { 64 | id: 'namepart', 65 | type: 'http://gedcomx.org/Given', 66 | value: 'Jonathan', 67 | qualifiers: [ 68 | { 69 | name: 'http://gedcomx.org/Primary' 70 | } 71 | ] 72 | }, part = GedcomX.NamePart(data); 73 | assert.deepEqual(part.toJSON(), data); 74 | }); 75 | 76 | it('constructor does not copy instances', function(){ 77 | var obj1 = GedcomX.NamePart(); 78 | var obj2 = GedcomX.NamePart(obj1); 79 | assert.strictEqual(obj1, obj2); 80 | }); 81 | 82 | }); -------------------------------------------------------------------------------- /test/core/Note.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Note', function(){ 5 | 6 | it('Create plain', function(){ 7 | var newNote = new GedcomX.Note(), 8 | note = GedcomX.Note(); 9 | assert.instanceOf(newNote, GedcomX.Note, 'An instance of Note is not returned when calling the constructor with new.'); 10 | assert.instanceOf(note, GedcomX.Note, 'An instance of Note is not returned when calling the constructor without new.'); 11 | }); 12 | 13 | it('Create with JSON', function(){ 14 | var note = GedcomX.Note({ 15 | id: 'note', 16 | lang: 'en', 17 | subject: 'A subject', 18 | text: 'Lots of text', 19 | attribution: { 20 | changeMessage: 'It changed', 21 | contributor: { resource: 'https://myapp.com/contributor'} 22 | } 23 | }); 24 | assert.equal(note.getId(), 'note'); 25 | assert.equal(note.getLang(), 'en'); 26 | assert.equal(note.getSubject(), 'A subject'); 27 | assert.equal(note.getText(), 'Lots of text'); 28 | assert.equal(note.getAttribution().getContributor().getResource(), 'https://myapp.com/contributor'); 29 | }); 30 | 31 | it('Create with mixed data', function(){ 32 | var note = GedcomX.Note({ 33 | id: 'note', 34 | lang: 'en', 35 | subject: 'A subject', 36 | text: 'Lots of text', 37 | attribution: new GedcomX.Attribution({ 38 | changeMessage: 'It changed', 39 | contributor: { resource: 'https://myapp.com/contributor'} 40 | }) 41 | }); 42 | assert.equal(note.getId(), 'note'); 43 | assert.equal(note.getLang(), 'en'); 44 | assert.equal(note.getSubject(), 'A subject'); 45 | assert.equal(note.getText(), 'Lots of text'); 46 | assert.equal(note.getAttribution().getContributor().getResource(), 'https://myapp.com/contributor'); 47 | }); 48 | 49 | it('Build', function(){ 50 | var note = GedcomX.Note() 51 | .setId('note') 52 | .setLang('en') 53 | .setSubject('A subject') 54 | .setText('Lots of text') 55 | .setAttribution({ 56 | changeMessage: 'It changed', 57 | contributor: { resource: 'https://myapp.com/contributor'} 58 | }); 59 | assert.equal(note.getId(), 'note'); 60 | assert.equal(note.getLang(), 'en'); 61 | assert.equal(note.getSubject(), 'A subject'); 62 | assert.equal(note.getText(), 'Lots of text'); 63 | assert.equal(note.getAttribution().getContributor().getResource(), 'https://myapp.com/contributor'); 64 | }); 65 | 66 | it('toJSON', function(){ 67 | var noteData = { 68 | id: 'note', 69 | lang: 'en', 70 | subject: 'A subject', 71 | text: 'Lots of text', 72 | attribution: { 73 | changeMessage: 'It changed', 74 | contributor: { resource: 'https://myapp.com/contributor'} 75 | } 76 | }, 77 | note = GedcomX.Note(noteData); 78 | assert.deepEqual(note.toJSON(), noteData); 79 | }); 80 | 81 | it('constructor does not copy instances', function(){ 82 | var obj1 = GedcomX.Note(); 83 | var obj2 = GedcomX.Note(obj1); 84 | assert.strictEqual(obj1, obj2); 85 | }); 86 | 87 | }); -------------------------------------------------------------------------------- /test/core/OnlineAccount.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('OnlineAccount', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.OnlineAccount(), GedcomX.OnlineAccount, 'An instance of OnlineAccount is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.OnlineAccount(), GedcomX.OnlineAccount, 'An instance of OnlineAccount is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var account = GedcomX.OnlineAccount({ 13 | accountName: 'jimbo', 14 | serviceHomepage: { 15 | resource: 'http://service/home' 16 | } 17 | }); 18 | assert.equal(account.getAccountName(), 'jimbo'); 19 | assert.equal(account.getServiceHomepage().getResource(), 'http://service/home'); 20 | }); 21 | 22 | it('Create with mixed data', function(){ 23 | var account = GedcomX.OnlineAccount({ 24 | accountName: 'jimbo', 25 | serviceHomepage: GedcomX.ResourceReference({ 26 | resource: 'http://service/home' 27 | }) 28 | }); 29 | assert.equal(account.getAccountName(), 'jimbo'); 30 | assert.equal(account.getServiceHomepage().getResource(), 'http://service/home'); 31 | }); 32 | 33 | it('Build', function(){ 34 | var account = GedcomX.OnlineAccount() 35 | .setAccountName('jimbo') 36 | .setServiceHomepage(GedcomX.ResourceReference().setResource('http://service/home')); 37 | assert.equal(account.getAccountName(), 'jimbo'); 38 | assert.equal(account.getServiceHomepage().getResource(), 'http://service/home'); 39 | }); 40 | 41 | it('toJSON', function(){ 42 | var data = { 43 | accountName: 'jimbo', 44 | serviceHomepage: { 45 | resource: 'http://service/home' 46 | } 47 | }, account = GedcomX.OnlineAccount(data); 48 | assert.deepEqual(account.toJSON(), data); 49 | }); 50 | 51 | it('constructor does not copy instances', function(){ 52 | var obj1 = GedcomX.OnlineAccount(); 53 | var obj2 = GedcomX.OnlineAccount(obj1); 54 | assert.strictEqual(obj1, obj2); 55 | }); 56 | 57 | }); -------------------------------------------------------------------------------- /test/core/PlaceReference.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('PlaceReference', function(){ 5 | 6 | it('Create plain', function(){ 7 | var newRef = new GedcomX.PlaceReference(), 8 | ref = GedcomX.PlaceReference(); 9 | assert.instanceOf(newRef, GedcomX.PlaceReference, 'An instance of PlaceReference is not returned when calling the constructor with new.'); 10 | assert.instanceOf(ref, GedcomX.PlaceReference, 'An instance of PlaceReference is not returned when calling the constructor without new.'); 11 | }); 12 | 13 | it('Create with JSON', function(){ 14 | var ref = GedcomX.PlaceReference({ 15 | id: 'ref', 16 | original: 'Miami, Missouri', 17 | description: 'http://place/description' 18 | }); 19 | assert.equal(ref.getId(), 'ref'); 20 | assert.equal(ref.getOriginal(), 'Miami, Missouri'); 21 | assert.equal(ref.getDescription(), 'http://place/description'); 22 | }); 23 | 24 | it('Build', function(){ 25 | var ref = GedcomX.PlaceReference() 26 | .setId('ref') 27 | .setOriginal('Miami, Missouri') 28 | .setDescription('http://place/description'); 29 | assert.equal(ref.getId(), 'ref'); 30 | assert.equal(ref.getOriginal(), 'Miami, Missouri'); 31 | assert.equal(ref.getDescription(), 'http://place/description'); 32 | }); 33 | 34 | it('toJSON', function(){ 35 | var data = { 36 | id: 'ref', 37 | original: 'Miami, Missouri', 38 | description: 'http://place/description' 39 | }, ref = GedcomX.PlaceReference(data); 40 | assert.deepEqual(ref.toJSON(), data); 41 | }); 42 | 43 | it('constructor does not copy instances', function(){ 44 | var obj1 = GedcomX.PlaceReference(); 45 | var obj2 = GedcomX.PlaceReference(obj1); 46 | assert.strictEqual(obj1, obj2); 47 | }); 48 | 49 | }); -------------------------------------------------------------------------------- /test/core/Qualifier.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Qualifier', function(){ 5 | 6 | it('Create plain', function(){ 7 | var newRef = new GedcomX.Qualifier(), 8 | ref = GedcomX.Qualifier(); 9 | assert.instanceOf(newRef, GedcomX.Qualifier, 'An instance of Qualifier is not returned when calling the constructor with new.'); 10 | assert.instanceOf(ref, GedcomX.Qualifier, 'An instance of Qualifier is not returned when calling the constructor without new.'); 11 | }); 12 | 13 | it('Create with JSON', function(){ 14 | var ref = GedcomX.Qualifier({ 15 | name: 'http://gedcomx.org/Age', 16 | value: '37' 17 | }); 18 | assert.equal(ref.getName(), 'http://gedcomx.org/Age'); 19 | assert.equal(ref.getValue(), '37'); 20 | }); 21 | 22 | it('Build', function(){ 23 | var ref = GedcomX.Qualifier() 24 | .setName('http://gedcomx.org/Age') 25 | .setValue('37'); 26 | assert.equal(ref.getName(), 'http://gedcomx.org/Age'); 27 | assert.equal(ref.getValue(), '37'); 28 | }); 29 | 30 | it('toJSON', function(){ 31 | var data = { 32 | name: 'http://gedcomx.org/Age', 33 | value: '37' 34 | }, ref = GedcomX.Qualifier(data); 35 | assert.deepEqual(ref.toJSON(), data); 36 | }); 37 | 38 | it('constructor does not copy instances', function(){ 39 | var obj1 = GedcomX.Qualifier(); 40 | var obj2 = GedcomX.Qualifier(obj1); 41 | assert.strictEqual(obj1, obj2); 42 | }); 43 | 44 | }); -------------------------------------------------------------------------------- /test/core/ResourceReference.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('ResourceReference', function(){ 5 | 6 | it('Create plain', function(){ 7 | var newRR = new GedcomX.ResourceReference(), 8 | rr = GedcomX.ResourceReference(); 9 | assert.instanceOf(newRR, GedcomX.ResourceReference, 'An instance of ResourceReference is not returned when calling the constructor with new.'); 10 | assert.instanceOf(rr, GedcomX.ResourceReference, 'An instance of ResourceReference is not returned when calling the constructor without new.'); 11 | }); 12 | 13 | it('Create with JSON', function(){ 14 | var rr = GedcomX.ResourceReference({ resource: 'http://example.com' }); 15 | assert.equal(rr.getResource(), 'http://example.com', 'Resource not saved properly when created with JSON'); 16 | }); 17 | 18 | it('Change resource', function(){ 19 | var rr = GedcomX.ResourceReference({ resource: 'http://example.com' }); 20 | rr.setResource('http://newuri.com'); 21 | assert.equal(rr.getResource(), 'http://newuri.com', 'Resource not saved properly when changed with setResource()'); 22 | }); 23 | 24 | it('toJSON()', function(){ 25 | var rr = GedcomX.ResourceReference({ resource: 'http://example.com' }); 26 | rr.setResource('http://newuri.com'); 27 | assert.deepEqual(rr.toJSON(), { resource: 'http://newuri.com' }, 'JSON export is incorrect'); 28 | 29 | rr = GedcomX.ResourceReference(); 30 | assert.deepEqual(rr.toJSON(), {}); 31 | }); 32 | 33 | it('constructor does not copy instances', function(){ 34 | var obj1 = GedcomX.ResourceReference(); 35 | var obj2 = GedcomX.ResourceReference(obj1); 36 | assert.strictEqual(obj1, obj2); 37 | }); 38 | 39 | it('matches()', function(){ 40 | var reference = GedcomX.ResourceReference({ resource: '#resource' }); 41 | assert(reference.matches('resource')); 42 | assert(!reference.matches()); 43 | }); 44 | 45 | }); -------------------------------------------------------------------------------- /test/core/SourceCitation.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('SourceCitation', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.SourceCitation(), GedcomX.SourceCitation, 'An instance of SourceCitation is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.SourceCitation(), GedcomX.SourceCitation, 'An instance of SourceCitation is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var citation = GedcomX.SourceCitation({ 13 | lang: 'en', 14 | value: 'a full text citation' 15 | }); 16 | assert.equal(citation.getLang(), 'en'); 17 | assert.equal(citation.getValue(), 'a full text citation'); 18 | }); 19 | 20 | it('Build', function(){ 21 | var citation = GedcomX.SourceCitation() 22 | .setLang('en') 23 | .setValue('a full text citation'); 24 | assert.equal(citation.getLang(), 'en'); 25 | assert.equal(citation.getValue(), 'a full text citation'); 26 | }); 27 | 28 | it('toJSON', function(){ 29 | var data = { 30 | lang: 'en', 31 | value: 'a full text citation' 32 | }, citation = GedcomX.SourceCitation(data); 33 | assert.deepEqual(citation.toJSON(), data); 34 | }); 35 | 36 | it('constructor does not copy instances', function(){ 37 | var obj1 = GedcomX.SourceCitation(); 38 | var obj2 = GedcomX.SourceCitation(obj1); 39 | assert.strictEqual(obj1, obj2); 40 | }); 41 | 42 | }); -------------------------------------------------------------------------------- /test/core/SourceReference.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('SourceReference', function(){ 5 | 6 | it('Create plain', function(){ 7 | var newSourceRef = new GedcomX.SourceReference(), 8 | sourceRef = GedcomX.SourceReference(); 9 | assert.instanceOf(newSourceRef, GedcomX.SourceReference, 'An instance of SourceReference is not returned when calling the constructor with new.'); 10 | assert.instanceOf(sourceRef, GedcomX.SourceReference, 'An instance of SourceReference is not returned when calling the constructor without new.'); 11 | }); 12 | 13 | it('Create with JSON', function(){ 14 | var ref = GedcomX.SourceReference({ 15 | id: 'source-ref', 16 | description: 'http://some/uri', 17 | descriptionId: 'some-id', 18 | attribution: { 19 | created: 11121211112 20 | } 21 | }); 22 | assert.equal(ref.getId(), 'source-ref'); 23 | assert.equal(ref.getDescription(), 'http://some/uri'); 24 | assert.equal(ref.getDescriptionId(), 'some-id'); 25 | assert.equal(ref.getAttribution().getCreated().getTime(), 11121211112); 26 | }); 27 | 28 | it('Create with mixed data', function(){ 29 | var ref = GedcomX.SourceReference({ 30 | id: 'source-ref', 31 | description: 'http://some/uri', 32 | descriptionId: 'some-id', 33 | attribution: GedcomX.Attribution({ 34 | created: 11121211112 35 | }) 36 | }); 37 | assert.equal(ref.getId(), 'source-ref'); 38 | assert.equal(ref.getDescription(), 'http://some/uri'); 39 | assert.equal(ref.getDescriptionId(), 'some-id'); 40 | assert.equal(ref.getAttribution().getCreated().getTime(), 11121211112); 41 | }); 42 | 43 | it('Build', function(){ 44 | var ref = GedcomX.SourceReference() 45 | .setId('source-ref') 46 | .setDescription('http://some/uri') 47 | .setDescriptionId('some-id') 48 | .setAttribution({ created: 11121211112 }); 49 | assert.equal(ref.getId(), 'source-ref'); 50 | assert.equal(ref.getDescription(), 'http://some/uri'); 51 | assert.equal(ref.getDescriptionId(), 'some-id'); 52 | assert.equal(ref.getAttribution().getCreated().getTime(), 11121211112); 53 | }); 54 | 55 | it('toJSON', function(){ 56 | var refData = { 57 | id: 'source-ref', 58 | description: 'http://some/uri', 59 | attribution: { 60 | created: 11121211112 61 | } 62 | }, 63 | ref = GedcomX.SourceReference(refData); 64 | assert.deepEqual(ref.toJSON(), refData); 65 | }); 66 | 67 | it('constructor does not copy instances', function(){ 68 | var obj1 = GedcomX.SourceReference(); 69 | var obj2 = GedcomX.SourceReference(obj1); 70 | assert.strictEqual(obj1, obj2); 71 | }); 72 | 73 | }); -------------------------------------------------------------------------------- /test/core/TextValue.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('TextValue', function(){ 5 | 6 | it('Create plain', function(){ 7 | var newValue = new GedcomX.TextValue(), 8 | value = GedcomX.TextValue(); 9 | assert.instanceOf(newValue, GedcomX.TextValue, 'An instance of TextValue is not returned when calling the constructor with new.'); 10 | assert.instanceOf(value, GedcomX.TextValue, 'An instance of TextValue is not returned when calling the constructor without new.'); 11 | }); 12 | 13 | it('Create with JSON', function(){ 14 | var value = GedcomX.TextValue({ 15 | lang: 'en', 16 | value: 'a full text value' 17 | }); 18 | assert.equal(value.getLang(), 'en'); 19 | assert.equal(value.getValue(), 'a full text value'); 20 | }); 21 | 22 | it('Build', function(){ 23 | var value = GedcomX.TextValue() 24 | .setLang('en') 25 | .setValue('a full text value'); 26 | assert.equal(value.getLang(), 'en'); 27 | assert.equal(value.getValue(), 'a full text value'); 28 | }); 29 | 30 | it('toJSON', function(){ 31 | var data = { 32 | lang: 'en', 33 | value: 'a full text value' 34 | }, value = GedcomX.TextValue(data); 35 | assert.deepEqual(value.toJSON(), data); 36 | }); 37 | 38 | it('constructor does not copy instances', function(){ 39 | var obj1 = GedcomX.TextValue(); 40 | var obj2 = GedcomX.TextValue(obj1); 41 | assert.strictEqual(obj1, obj2); 42 | }); 43 | 44 | }); -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../'); 3 | 4 | describe('GedcomX', function(){ 5 | 6 | it('GedcomX() returns a Root', function(){ 7 | assert(GedcomX.Root.isInstance(GedcomX())); 8 | }); 9 | 10 | it('Base is exposed', function(){ 11 | assert(GedcomX.Base.isInstance(GedcomX.Base())); 12 | }); 13 | 14 | }); -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | -R dot -------------------------------------------------------------------------------- /test/records/Collection.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Collection', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.Collection(), GedcomX.Collection, 'An instance of Collection is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.Collection(), GedcomX.Collection, 'An instance of Collection is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var collection = GedcomX.Collection({ 13 | id: 'collection', 14 | lang: 'en-US', 15 | content: [{ 16 | resourceType: 'http://gedcomx.org/Record', 17 | count: 183429102, 18 | completeness: .8237 19 | }], 20 | title: 'Collection Title', 21 | size: 183429102, 22 | attribution: { 23 | contributor: { resource: 'https://myapp.com/contributor'}, 24 | created: 1111338494969, 25 | creator: { resource: 'https://myapp.com/creator'}, 26 | modified: 1111338494969 27 | } 28 | }); 29 | assert.equal(collection.getId(), 'collection'); 30 | assert.equal(collection.getLang(), 'en-US'); 31 | assert.equal(collection.getContent()[0].getResourceType(), 'http://gedcomx.org/Record'); 32 | assert.equal(collection.getTitle(), 'Collection Title'); 33 | assert.equal(collection.getSize(), 183429102); 34 | assert(GedcomX.Attribution.isInstance(collection.getAttribution())); 35 | }); 36 | 37 | it('Build', function(){ 38 | var collection = GedcomX.Collection() 39 | .setId('collection') 40 | .setLang('en-US') 41 | .addContent({ 42 | resourceType: 'http://gedcomx.org/Record', 43 | count: 183429102, 44 | completeness: .8237 45 | }) 46 | .setTitle('Collection Title') 47 | .setSize(183429102) 48 | .setAttribution({ 49 | contributor: { resource: 'https://myapp.com/contributor'}, 50 | created: 1111338494969, 51 | creator: { resource: 'https://myapp.com/creator'}, 52 | modified: 1111338494969 53 | }); 54 | assert.equal(collection.getId(), 'collection'); 55 | assert.equal(collection.getLang(), 'en-US'); 56 | assert.equal(collection.getContent()[0].getResourceType(), 'http://gedcomx.org/Record'); 57 | assert.equal(collection.getTitle(), 'Collection Title'); 58 | assert.equal(collection.getSize(), 183429102); 59 | assert(GedcomX.Attribution.isInstance(collection.getAttribution())); 60 | }); 61 | 62 | it('toJSON', function(){ 63 | var data = { 64 | id: 'collection', 65 | lang: 'en-US', 66 | content: [{ 67 | resourceType: 'http://gedcomx.org/Record', 68 | count: 183429102, 69 | completeness: .8237 70 | }], 71 | title: 'Collection Title', 72 | size: 183429102, 73 | attribution: { 74 | contributor: { resource: 'https://myapp.com/contributor'}, 75 | created: 1111338494969, 76 | creator: { resource: 'https://myapp.com/creator'}, 77 | modified: 1111338494969 78 | } 79 | }, collection = GedcomX.Collection(data); 80 | assert.deepEqual(collection.toJSON(), data); 81 | }); 82 | 83 | it('constructor does not copy instances', function(){ 84 | var obj1 = GedcomX.Collection(); 85 | var obj2 = GedcomX.Collection(obj1); 86 | assert.strictEqual(obj1, obj2); 87 | }); 88 | 89 | }); -------------------------------------------------------------------------------- /test/records/CollectionContent.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('CollectionContent', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.CollectionContent(), GedcomX.CollectionContent, 'An instance of CollectionContent is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.CollectionContent(), GedcomX.CollectionContent, 'An instance of CollectionContent is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var cc = GedcomX.CollectionContent({ 13 | resourceType: 'http://gedcomx.org/Record', 14 | count: 183429102, 15 | completeness: .8237 16 | }); 17 | assert.equal(cc.getResourceType(), 'http://gedcomx.org/Record'); 18 | assert.equal(cc.getCount(), 183429102); 19 | assert.equal(cc.getCompleteness(), .8237); 20 | }); 21 | 22 | it('Build', function(){ 23 | var cc = GedcomX.CollectionContent() 24 | .setResourceType('http://gedcomx.org/Record') 25 | .setCount(183429102) 26 | .setCompleteness(.8237); 27 | assert.equal(cc.getResourceType(), 'http://gedcomx.org/Record'); 28 | assert.equal(cc.getCount(), 183429102); 29 | assert.equal(cc.getCompleteness(), .8237); 30 | }); 31 | 32 | it('toJSON', function(){ 33 | var data = { 34 | resourceType: 'http://gedcomx.org/Record', 35 | count: 183429102, 36 | completeness: .8237 37 | }, cc = GedcomX.CollectionContent(data); 38 | assert.deepEqual(cc.toJSON(), data); 39 | }); 40 | 41 | it('constructor does not copy instances', function(){ 42 | var obj1 = GedcomX.CollectionContent(); 43 | var obj2 = GedcomX.CollectionContent(obj1); 44 | assert.strictEqual(obj1, obj2); 45 | }); 46 | 47 | }); -------------------------------------------------------------------------------- /test/records/Coverage.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Coverage', function(){ 5 | 6 | it('Create with JSON', function(){ 7 | var coverage = GedcomX.Coverage({ 8 | spatial: { 9 | original: 'A Place' 10 | }, 11 | temporal: { 12 | formal: '+2015-01-03' 13 | }, 14 | recordType: 'http://gedcomx.org/Collection' 15 | }); 16 | assert.equal(coverage.getSpatial().getOriginal(), 'A Place'); 17 | assert.equal(coverage.getTemporal().getFormal(), '+2015-01-03'); 18 | assert.equal(coverage.getRecordType(), 'http://gedcomx.org/Collection'); 19 | }); 20 | 21 | it('Build', function(){ 22 | var coverage = GedcomX.Coverage() 23 | .setSpatial(GedcomX.PlaceReference().setOriginal('A Place')) 24 | .setTemporal(GedcomX.Date().setFormal('+2015-01-03')) 25 | .setRecordType('http://gedcomx.org/Collection'); 26 | assert.equal(coverage.getSpatial().getOriginal(), 'A Place'); 27 | assert.equal(coverage.getTemporal().getFormal(), '+2015-01-03'); 28 | assert.equal(coverage.getRecordType(), 'http://gedcomx.org/Collection'); 29 | }); 30 | 31 | it('toJSON', function(){ 32 | var data = { 33 | spatial: { 34 | original: 'A Place' 35 | }, 36 | temporal: { 37 | formal: '+2015-01-03' 38 | }, 39 | recordType: 'http://gedcomx.org/Collection' 40 | }, coverage = GedcomX.Coverage(data); 41 | assert.deepEqual(coverage.toJSON(), data); 42 | }); 43 | 44 | }); -------------------------------------------------------------------------------- /test/records/ExtensibleData.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('ExtensibleData', function(){ 5 | 6 | it('Create with JSON', function(){ 7 | var ed = GedcomX.ExtensibleData({ 8 | id: 'edid', 9 | fields: [ 10 | { 11 | id: 'nameField', 12 | type: 'http://gedcomx.org/Name', 13 | values: [ 14 | { 15 | type: 'type', 16 | labelId: 'labelId', 17 | text: 'Text', 18 | confidence: 'http://gedcomx.org/High', 19 | datatype: 'data type', 20 | resource: '#resource' 21 | } 22 | ] 23 | } 24 | ] 25 | }); 26 | assert.equal(ed.getId(), 'edid', 'ID not saved properly when created with JSON'); 27 | assert.equal(ed.getFields().length, 1); 28 | var field = ed.getFields()[0]; 29 | assert.equal(field.getId(), 'nameField'); 30 | assert.equal(field.getType(), 'http://gedcomx.org/Name'); 31 | assert.equal(field.getValues().length, 1); 32 | var fieldValue = field.getValues()[0]; 33 | assert.equal(fieldValue.getType(), 'type'); 34 | assert.equal(fieldValue.getLabelId(), 'labelId'); 35 | assert.equal(fieldValue.getText(), 'Text'); 36 | assert.equal(fieldValue.getConfidence(), 'http://gedcomx.org/High'); 37 | assert.equal(fieldValue.getDataType(), 'data type'); 38 | assert.equal(fieldValue.getResource(), '#resource'); 39 | }); 40 | 41 | it('toJSON()', function(){ 42 | var json = { 43 | id: 'edid', 44 | fields: [ 45 | { 46 | id: 'nameField', 47 | type: 'http://gedcomx.org/Name', 48 | values: [ 49 | { 50 | type: 'type', 51 | labelId: 'labelId', 52 | text: 'Text', 53 | confidence: 'http://gedcomx.org/High', 54 | datatype: 'data type', 55 | resource: '#resource' 56 | } 57 | ] 58 | } 59 | ] 60 | }, ed = GedcomX.ExtensibleData(json); 61 | assert.deepEqual(ed.toJSON(), json, 'JSON export is incorrect'); 62 | }); 63 | 64 | }); -------------------------------------------------------------------------------- /test/records/Fact.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Fact', function(){ 5 | 6 | it('Create with JSON', function(){ 7 | var fact = GedcomX.Fact({ 8 | id: 'fact', 9 | primary: true, 10 | type: 'http://gedcomx.org/Birth', 11 | date: { 12 | original: '1845' 13 | }, 14 | place: { 15 | original: 'Casper, Wyoming' 16 | }, 17 | value: 'Birth value', 18 | qualifiers: [ 19 | { 20 | name: 'http://gedcomx.org/Age', 21 | value: '0' 22 | } 23 | ] 24 | }); 25 | assert.equal(fact.getId(), 'fact'); 26 | assert.equal(fact.getPrimary(), true); 27 | assert.equal(fact.getType(), 'http://gedcomx.org/Birth'); 28 | assert.equal(fact.getDate().getOriginal(), '1845'); 29 | assert.equal(fact.getPlace().getOriginal(), 'Casper, Wyoming'); 30 | assert.equal(fact.getValue(), 'Birth value'); 31 | assert.equal(fact.getQualifiers().length, 1); 32 | assert.equal(fact.getQualifiers()[0].getName(), 'http://gedcomx.org/Age'); 33 | assert.equal(fact.getQualifiers()[0].getValue(), '0'); 34 | }); 35 | 36 | it('Build', function(){ 37 | var fact = GedcomX.Fact() 38 | .setId('fact') 39 | .setPrimary(true) 40 | .setType('http://gedcomx.org/Birth') 41 | .setDate(GedcomX.Date().setOriginal('1845')) 42 | .setPlace(GedcomX.PlaceReference().setOriginal('Casper, Wyoming')) 43 | .setValue('Birth value') 44 | .addQualifier(GedcomX.Qualifier().setName('http://gedcomx.org/Age').setValue('0')); 45 | assert.equal(fact.getId(), 'fact'); 46 | assert.equal(fact.getPrimary(), true); 47 | assert.equal(fact.getType(), 'http://gedcomx.org/Birth'); 48 | assert.equal(fact.getDate().getOriginal(), '1845'); 49 | assert.equal(fact.getPlace().getOriginal(), 'Casper, Wyoming'); 50 | assert.equal(fact.getValue(), 'Birth value'); 51 | assert.equal(fact.getQualifiers().length, 1); 52 | assert.equal(fact.getQualifiers()[0].getName(), 'http://gedcomx.org/Age'); 53 | assert.equal(fact.getQualifiers()[0].getValue(), '0'); 54 | }); 55 | 56 | it('toJSON', function(){ 57 | var data = { 58 | id: 'fact', 59 | primary: true, 60 | type: 'http://gedcomx.org/Birth', 61 | date: { 62 | original: '1845' 63 | }, 64 | place: { 65 | original: 'Casper, Wyoming' 66 | }, 67 | value: 'Birth value', 68 | qualifiers: [ 69 | { 70 | name: 'http://gedcomx.org/Age', 71 | value: '0' 72 | } 73 | ] 74 | }, fact = GedcomX.Fact(data); 75 | assert.deepEqual(fact.toJSON(), data); 76 | }); 77 | 78 | }); -------------------------------------------------------------------------------- /test/records/Field.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Field', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.Field(), GedcomX.Field, 'An instance of Field is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.Field(), GedcomX.Field, 'An instance of Field is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var field = GedcomX.Field({ 13 | id: 'nameField', 14 | type: 'http://gedcomx.org/Name', 15 | values: [ 16 | { 17 | type: 'type', 18 | labelId: 'labelId', 19 | text: 'Text', 20 | confidence: 'http://gedcomx.org/High', 21 | datatype: 'data type', 22 | resource: '#resource' 23 | } 24 | ] 25 | }); 26 | assert.equal(field.getId(), 'nameField'); 27 | assert.equal(field.getType(), 'http://gedcomx.org/Name'); 28 | assert.equal(field.getValues().length, 1); 29 | var fieldValue = field.getValues()[0]; 30 | assert.equal(fieldValue.getType(), 'type'); 31 | assert.equal(fieldValue.getLabelId(), 'labelId'); 32 | assert.equal(fieldValue.getText(), 'Text'); 33 | assert.equal(fieldValue.getConfidence(), 'http://gedcomx.org/High'); 34 | assert.equal(fieldValue.getDataType(), 'data type'); 35 | assert.equal(fieldValue.getResource(), '#resource'); 36 | }); 37 | 38 | it('Build', function(){ 39 | var field = GedcomX.Field() 40 | .setId('nameField') 41 | .setType('http://gedcomx.org/Name') 42 | .addValue({ 43 | type: 'type', 44 | labelId: 'labelId', 45 | text: 'Text', 46 | confidence: 'http://gedcomx.org/High', 47 | datatype: 'data type', 48 | resource: '#resource' 49 | }); 50 | assert.equal(field.getId(), 'nameField'); 51 | assert.equal(field.getType(), 'http://gedcomx.org/Name'); 52 | assert.equal(field.getValues().length, 1); 53 | var fieldValue = field.getValues()[0]; 54 | assert.equal(fieldValue.getType(), 'type'); 55 | assert.equal(fieldValue.getLabelId(), 'labelId'); 56 | assert.equal(fieldValue.getText(), 'Text'); 57 | assert.equal(fieldValue.getConfidence(), 'http://gedcomx.org/High'); 58 | assert.equal(fieldValue.getDataType(), 'data type'); 59 | assert.equal(fieldValue.getResource(), '#resource'); 60 | }); 61 | 62 | it('toJSON', function(){ 63 | var data = { 64 | id: 'nameField', 65 | type: 'http://gedcomx.org/Name', 66 | values: [ 67 | { 68 | type: 'type', 69 | labelId: 'labelId', 70 | text: 'Text', 71 | confidence: 'http://gedcomx.org/High', 72 | datatype: 'data type', 73 | resource: '#resource' 74 | } 75 | ] 76 | }, field = GedcomX.Field(data); 77 | assert.deepEqual(field.toJSON(), data); 78 | }); 79 | 80 | it('constructor does not copy instances', function(){ 81 | var obj1 = GedcomX.Field(); 82 | var obj2 = GedcomX.Field(obj1); 83 | assert.strictEqual(obj1, obj2); 84 | }); 85 | 86 | }); -------------------------------------------------------------------------------- /test/records/FieldDescriptor.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('FieldDescriptor', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.FieldDescriptor(), GedcomX.FieldDescriptor, 'An instance of FieldDescriptor is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.FieldDescriptor(), GedcomX.FieldDescriptor, 'An instance of FieldDescriptor is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var fd = GedcomX.FieldDescriptor({ 13 | originalLabel: 'Name', 14 | descriptions: [ 15 | { lang: 'en-US', value: 'Full Name' } 16 | ], 17 | values: [{ 18 | optional: true, 19 | type: 'http://gedcomx.org/Original', 20 | labelId: 'name', 21 | displayLabels: [ 22 | { lang: 'en-US', value: 'Name' } 23 | ] 24 | }] 25 | }); 26 | assert.equal(fd.getOriginalLabel(), 'Name'); 27 | assert.equal(fd.getDescriptions().length, 1); 28 | assert.equal(fd.getDescriptions()[0].getLang(), 'en-US'); 29 | assert.equal(fd.getDescriptions()[0].getValue(), 'Full Name'); 30 | assert.equal(fd.getValues().length, 1); 31 | }); 32 | 33 | it('Build', function(){ 34 | var fd = GedcomX.FieldDescriptor() 35 | .setOriginalLabel('Name') 36 | .addDescription({ lang: 'en-US', value: 'Full Name' }) 37 | .addValue({ 38 | optional: true, 39 | type: 'http://gedcomx.org/Original', 40 | labelId: 'name', 41 | displayLabels: [ 42 | { lang: 'en-US', value: 'Name' } 43 | ] 44 | }); 45 | assert.equal(fd.getOriginalLabel(), 'Name'); 46 | assert.equal(fd.getDescriptions().length, 1); 47 | assert.equal(fd.getDescriptions()[0].getLang(), 'en-US'); 48 | assert.equal(fd.getDescriptions()[0].getValue(), 'Full Name'); 49 | assert.equal(fd.getValues().length, 1); 50 | }); 51 | 52 | it('toJSON', function(){ 53 | var data = { 54 | originalLabel: 'Name', 55 | descriptions: [ 56 | { lang: 'en-US', value: 'Full Name' } 57 | ], 58 | values: [{ 59 | optional: true, 60 | type: 'http://gedcomx.org/Original', 61 | labelId: 'name', 62 | displayLabels: [ 63 | { lang: 'en-US', value: 'Name' } 64 | ] 65 | }] 66 | }, fvd = GedcomX.FieldDescriptor(data); 67 | assert.deepEqual(fvd.toJSON(), data); 68 | }); 69 | 70 | it('constructor does not copy instances', function(){ 71 | var obj1 = GedcomX.FieldDescriptor(); 72 | var obj2 = GedcomX.FieldDescriptor(obj1); 73 | assert.strictEqual(obj1, obj2); 74 | }); 75 | 76 | }); -------------------------------------------------------------------------------- /test/records/FieldValue.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('FieldValue', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.FieldValue(), GedcomX.FieldValue, 'An instance of FieldValue is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.FieldValue(), GedcomX.FieldValue, 'An instance of FieldValue is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var fieldValue = GedcomX.FieldValue({ 13 | type: 'type', 14 | labelId: 'labelId', 15 | text: 'Text', 16 | confidence: 'http://gedcomx.org/High', 17 | datatype: 'data type', 18 | resource: '#resource' 19 | }); 20 | assert.equal(fieldValue.getType(), 'type'); 21 | assert.equal(fieldValue.getLabelId(), 'labelId'); 22 | assert.equal(fieldValue.getText(), 'Text'); 23 | assert.equal(fieldValue.getConfidence(), 'http://gedcomx.org/High'); 24 | assert.equal(fieldValue.getDataType(), 'data type'); 25 | assert.equal(fieldValue.getResource(), '#resource'); 26 | }); 27 | 28 | it('Build', function(){ 29 | var fieldValue = GedcomX.FieldValue() 30 | .setType('type') 31 | .setLabelId('labelId') 32 | .setText('Text') 33 | .setConfidence('http://gedcomx.org/High') 34 | .setDataType('data type') 35 | .setResource('#resource'); 36 | assert.equal(fieldValue.getType(), 'type'); 37 | assert.equal(fieldValue.getLabelId(), 'labelId'); 38 | assert.equal(fieldValue.getText(), 'Text'); 39 | assert.equal(fieldValue.getConfidence(), 'http://gedcomx.org/High'); 40 | assert.equal(fieldValue.getDataType(), 'data type'); 41 | assert.equal(fieldValue.getResource(), '#resource'); 42 | }); 43 | 44 | it('toJSON', function(){ 45 | var data = { 46 | type: 'type', 47 | labelId: 'labelId', 48 | text: 'Text', 49 | confidence: 'http://gedcomx.org/High', 50 | datatype: 'data type', 51 | resource: '#resource' 52 | }, fvd = GedcomX.FieldValue(data); 53 | assert.deepEqual(fvd.toJSON(), data); 54 | }); 55 | 56 | it('constructor does not copy instances', function(){ 57 | var obj1 = GedcomX.FieldValue(); 58 | var obj2 = GedcomX.FieldValue(obj1); 59 | assert.strictEqual(obj1, obj2); 60 | }); 61 | 62 | }); -------------------------------------------------------------------------------- /test/records/FieldValueDescriptor.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('FieldValueDescriptor', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.FieldValueDescriptor(), GedcomX.FieldValueDescriptor, 'An instance of FieldValueDescriptor is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.FieldValueDescriptor(), GedcomX.FieldValueDescriptor, 'An instance of FieldValueDescriptor is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var fvd = GedcomX.FieldValueDescriptor({ 13 | id: 'fvd', 14 | optional: true, 15 | type: 'http://gedcomx.org/Original', 16 | labelId: 'name', 17 | displayLabels: [ 18 | { lang: 'en-US', value: 'Name' } 19 | ] 20 | }); 21 | assert.equal(fvd.getId(), 'fvd'); 22 | assert(fvd.getOptional()); 23 | assert.equal(fvd.getType(), 'http://gedcomx.org/Original'); 24 | assert.equal(fvd.getLabelId(), 'name'); 25 | assert.equal(fvd.getDisplayLabels().length, 1); 26 | assert.equal(fvd.getDisplayLabels()[0].getLang(), 'en-US'); 27 | assert.equal(fvd.getDisplayLabels()[0].getValue(), 'Name'); 28 | }); 29 | 30 | it('Build', function(){ 31 | var fvd = GedcomX.FieldValueDescriptor() 32 | .setId('fvd') 33 | .setOptional(true) 34 | .setType('http://gedcomx.org/Original') 35 | .setLabelId('name') 36 | .addDisplayLabel({ lang: 'en-US', value: 'Name' }); 37 | assert.equal(fvd.getId(), 'fvd'); 38 | assert(fvd.getOptional()); 39 | assert.equal(fvd.getType(), 'http://gedcomx.org/Original'); 40 | assert.equal(fvd.getLabelId(), 'name'); 41 | assert.equal(fvd.getDisplayLabels().length, 1); 42 | assert.equal(fvd.getDisplayLabels()[0].getLang(), 'en-US'); 43 | assert.equal(fvd.getDisplayLabels()[0].getValue(), 'Name'); 44 | }); 45 | 46 | it('toJSON', function(){ 47 | var data = { 48 | id: 'fvd', 49 | optional: true, 50 | type: 'http://gedcomx.org/Original', 51 | labelId: 'name', 52 | displayLabels: [ 53 | { lang: 'en-US', value: 'Name' } 54 | ] 55 | }, fvd = GedcomX.FieldValueDescriptor(data); 56 | assert.deepEqual(fvd.toJSON(), data); 57 | }); 58 | 59 | it('constructor does not copy instances', function(){ 60 | var obj1 = GedcomX.FieldValueDescriptor(); 61 | var obj2 = GedcomX.FieldValueDescriptor(obj1); 62 | assert.strictEqual(obj1, obj2); 63 | }); 64 | 65 | }); -------------------------------------------------------------------------------- /test/records/Person.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Person', function(){ 5 | 6 | it('Create with JSON', function(){ 7 | var person = GedcomX.Person({ 8 | id: 'testPerson', 9 | private: true, 10 | principal: true, 11 | gender: { 12 | type: 'http://gedcomx.org/Female' 13 | }, 14 | names: [ 15 | { 16 | type: 'http://gedcomx.org/BirthName', 17 | nameForms: [ 18 | { 19 | fullText: 'Joanna Hopkins' 20 | } 21 | ] 22 | } 23 | ], 24 | facts: [ 25 | { 26 | type: 'http://gedcomx.org/Birth', 27 | date: { 28 | formal: '+2001-04-09' 29 | }, 30 | place: { 31 | original: 'Farm house' 32 | } 33 | } 34 | ] 35 | }); 36 | assert.equal(person.getId(), 'testPerson'); 37 | assert.equal(person.getPrivate(), true); 38 | assert.equal(person.getPrincipal(), true); 39 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); 40 | assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); 41 | assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); 42 | assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); 43 | }); 44 | 45 | it('Build', function(){ 46 | var person = GedcomX.Person() 47 | .setId('testPerson') 48 | .setPrivate(true) 49 | .setPrincipal(true) 50 | .setGender(GedcomX.Gender().setType('http://gedcomx.org/Female')) 51 | .addName(GedcomX.Name().addNameForm(GedcomX.NameForm().setFullText('Joanna Hopkins'))) 52 | .addFact(GedcomX.Fact().setDate(GedcomX.Date().setFormal('+2001-04-09')).setPlace(GedcomX.PlaceReference().setOriginal('Farm house'))); 53 | assert.equal(person.getId(), 'testPerson'); 54 | assert.equal(person.getPrivate(), true); 55 | assert.equal(person.getPrincipal(), true); 56 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); 57 | assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); 58 | assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); 59 | assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); 60 | }); 61 | 62 | it('toJSON', function(){ 63 | var data = { 64 | id: 'testPerson', 65 | private: true, 66 | principal: true, 67 | gender: { 68 | type: 'http://gedcomx.org/Female' 69 | }, 70 | names: [ 71 | { 72 | type: 'http://gedcomx.org/BirthName', 73 | nameForms: [ 74 | { 75 | fullText: 'Joanna Hopkins' 76 | } 77 | ] 78 | } 79 | ], 80 | facts: [ 81 | { 82 | type: 'http://gedcomx.org/Birth', 83 | date: { 84 | formal: '+2001-04-09' 85 | }, 86 | place: { 87 | original: 'Farm house' 88 | } 89 | } 90 | ] 91 | }, person = GedcomX.Person(data); 92 | assert.deepEqual(person.toJSON(), data); 93 | }); 94 | 95 | }); -------------------------------------------------------------------------------- /test/records/RecordDescriptor.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('RecordDescriptor', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.RecordDescriptor(), GedcomX.RecordDescriptor, 'An instance of RecordDescriptor is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.RecordDescriptor(), GedcomX.RecordDescriptor, 'An instance of RecordDescriptor is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var rd = GedcomX.RecordDescriptor({ 13 | id: 'rd', 14 | lang: 'en-US', 15 | fields: [{ 16 | originalLabel: 'Name', 17 | descriptions: [ 18 | { lang: 'en-US', value: 'Full Name' } 19 | ], 20 | values: [{ 21 | optional: true, 22 | type: 'http://gedcomx.org/Original', 23 | labelId: 'name', 24 | displayLabels: [ 25 | { lang: 'en-US', value: 'Name' } 26 | ] 27 | }] 28 | }] 29 | }); 30 | assert.equal(rd.getId(), 'rd'); 31 | assert.equal(rd.getLang(), 'en-US'); 32 | assert.equal(rd.getFields().length, 1); 33 | assert.equal(rd.getFields()[0].getOriginalLabel(), 'Name'); 34 | assert.equal(rd.getFields()[0].getValues().length, 1); 35 | }); 36 | 37 | it('Build', function(){ 38 | var rd = GedcomX.RecordDescriptor() 39 | .setId('rd') 40 | .setLang('en-US') 41 | .addField({ 42 | originalLabel: 'Name', 43 | descriptions: [ 44 | { lang: 'en-US', value: 'Full Name' } 45 | ], 46 | values: [{ 47 | optional: true, 48 | type: 'http://gedcomx.org/Original', 49 | labelId: 'name', 50 | displayLabels: [ 51 | { lang: 'en-US', value: 'Name' } 52 | ] 53 | }] 54 | }); 55 | assert.equal(rd.getId(), 'rd'); 56 | assert.equal(rd.getLang(), 'en-US'); 57 | assert.equal(rd.getFields().length, 1); 58 | assert.equal(rd.getFields()[0].getOriginalLabel(), 'Name'); 59 | assert.equal(rd.getFields()[0].getValues().length, 1); 60 | }); 61 | 62 | it('toJSON', function(){ 63 | var data = { 64 | id: 'rd', 65 | lang: 'en-US', 66 | fields: [{ 67 | originalLabel: 'Name', 68 | descriptions: [ 69 | { lang: 'en-US', value: 'Full Name' } 70 | ], 71 | values: [{ 72 | optional: true, 73 | type: 'http://gedcomx.org/Original', 74 | labelId: 'name', 75 | displayLabels: [ 76 | { lang: 'en-US', value: 'Name' } 77 | ] 78 | }] 79 | }] 80 | }, rd = GedcomX.RecordDescriptor(data); 81 | assert.deepEqual(rd.toJSON(), data); 82 | }); 83 | 84 | it('constructor does not copy instances', function(){ 85 | var obj1 = GedcomX.RecordDescriptor(); 86 | var obj2 = GedcomX.RecordDescriptor(obj1); 87 | assert.strictEqual(obj1, obj2); 88 | }); 89 | 90 | }); -------------------------------------------------------------------------------- /test/records/SourceReference.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('SourceReference', function(){ 5 | 6 | it('Create with JSON', function(){ 7 | var ref = GedcomX.SourceReference({ 8 | id: 'source-ref', 9 | description: 'http://some/uri', 10 | attribution: { 11 | created: 11121211112 12 | }, 13 | qualifiers: [ 14 | { 15 | name: 'http://gedcomx.org/CharacterRegion', 16 | value: '37' 17 | } 18 | ] 19 | }); 20 | assert.equal(ref.getId(), 'source-ref'); 21 | assert.equal(ref.getDescription(), 'http://some/uri'); 22 | assert.equal(ref.getAttribution().getCreated().getTime(), 11121211112); 23 | assert.equal(ref.getQualifiers().length, 1); 24 | assert.equal(ref.getQualifiers()[0].getName(), 'http://gedcomx.org/CharacterRegion'); 25 | }); 26 | 27 | it('Build', function(){ 28 | var ref = GedcomX.SourceReference() 29 | .setId('source-ref') 30 | .setDescription('http://some/uri') 31 | .setAttribution({ created: 11121211112 }) 32 | .addQualifier( 33 | GedcomX.Qualifier().setName('http://gedcomx.org/CharacterRegion').setValue(37) 34 | ); 35 | assert.equal(ref.getId(), 'source-ref'); 36 | assert.equal(ref.getDescription(), 'http://some/uri'); 37 | assert.equal(ref.getAttribution().getCreated().getTime(), 11121211112); 38 | assert.equal(ref.getQualifiers().length, 1); 39 | assert.equal(ref.getQualifiers()[0].getName(), 'http://gedcomx.org/CharacterRegion'); 40 | }); 41 | 42 | it('toJSON', function(){ 43 | var refData = { 44 | id: 'source-ref', 45 | description: 'http://some/uri', 46 | attribution: { 47 | created: 11121211112 48 | }, 49 | qualifiers: [ 50 | { 51 | name: 'http://gedcomx.org/CharacterRegion', 52 | value: '37' 53 | } 54 | ] 55 | }, 56 | ref = GedcomX.SourceReference(refData); 57 | assert.deepEqual(ref.toJSON(), refData); 58 | }); 59 | 60 | }); -------------------------------------------------------------------------------- /test/records/index.js: -------------------------------------------------------------------------------- 1 | // Enable Records extensions so that we can test them 2 | var GedcomX = require('../../'); 3 | GedcomX.enableRecordsExtensions(); 4 | 5 | // Call it again to test that it doesn't break/change anything 6 | GedcomX.enableRecordsExtensions(); -------------------------------------------------------------------------------- /test/rs/Date.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Date', function(){ 5 | 6 | it('Create with JSON', function(){ 7 | var date = GedcomX.Date({ 8 | "original": "May 4, 1926", 9 | "formal": "+1926-05-04", 10 | "normalized":[ 11 | {"lang": "en-US", "value": "4 May 1926"}, 12 | ] 13 | }); 14 | assert.equal(date.getOriginal(), 'May 4, 1926'); 15 | assert.equal(date.getFormal(), '+1926-05-04'); 16 | assert.equal(date.getNormalized().length, 1); 17 | assert.equal(date.getNormalized()[0].getLang(), 'en-US'); 18 | assert.equal(date.getNormalized()[0].getValue(), '4 May 1926'); 19 | }); 20 | 21 | it('Build', function(){ 22 | var date = GedcomX.Date() 23 | .setOriginal('May 4, 1926') 24 | .setFormal('+1926-05-04') 25 | .addNormalized({"lang": "en-US", "value": "4 May 1926"}); 26 | assert.equal(date.getOriginal(), 'May 4, 1926'); 27 | assert.equal(date.getFormal(), '+1926-05-04'); 28 | assert.equal(date.getNormalized().length, 1); 29 | assert.equal(date.getNormalized()[0].getLang(), 'en-US'); 30 | assert.equal(date.getNormalized()[0].getValue(), '4 May 1926'); 31 | }); 32 | 33 | it('toJSON', function(){ 34 | var data = { 35 | "original": "May 4, 1926", 36 | "formal": "+1926-05-04", 37 | "normalized":[ 38 | {"lang": "en-US", "value": "4 May 1926"}, 39 | ] 40 | }, date = GedcomX.Date(data); 41 | assert.deepEqual(date.toJSON(), data); 42 | }); 43 | 44 | }); -------------------------------------------------------------------------------- /test/rs/ExtensibleData.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('ExtensibleData', function(){ 5 | 6 | it('Create with JSON', function(){ 7 | var ed = GedcomX.ExtensibleData({ 8 | id: 'edid', 9 | links: { 10 | person: { 11 | href: '/person' 12 | } 13 | } 14 | }); 15 | assert.equal(ed.getId(), 'edid', 'ID not saved properly when created with JSON'); 16 | assert.equal(ed.getLinks().length, 1); 17 | assert.equal(ed.getLinks()[0].getHref(), '/person'); 18 | assert.equal(ed.getLink('person').getHref(), '/person'); 19 | }); 20 | 21 | it('toJSON()', function(){ 22 | var json = { 23 | id: 'edid', 24 | links: { 25 | person: { 26 | href: '/person' 27 | } 28 | } 29 | }, ed = GedcomX.ExtensibleData(json); 30 | assert.deepEqual(ed.toJSON(), json, 'JSON export is incorrect'); 31 | }); 32 | 33 | }); -------------------------------------------------------------------------------- /test/rs/FamilyView.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('FamilyView', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.FamilyView(), GedcomX.FamilyView, 'An instance of FamilyView is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.FamilyView(), GedcomX.FamilyView, 'An instance of FamilyView is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var family = GedcomX.FamilyView({ 13 | "parent1" : { 14 | "resource" : "#parent1" 15 | }, 16 | "parent2" : { 17 | "resource" : "#parent2" 18 | }, 19 | "children" : [ 20 | { "resource" : "#child1" }, 21 | { "resource" : "#child2" } 22 | ] 23 | }); 24 | assert.equal(family.getParent1().getResource(), '#parent1'); 25 | assert.equal(family.getParent2().getResource(), '#parent2'); 26 | assert.equal(family.getChildren().length, 2); 27 | assert.equal(family.getChildren()[0].getResource(), '#child1'); 28 | assert.equal(family.getChildren()[1].getResource(), '#child2'); 29 | }); 30 | 31 | it('Build', function(){ 32 | var family = GedcomX.FamilyView() 33 | .setParent1({resource: '#parent1'}) 34 | .setParent2(GedcomX.ResourceReference().setResource('#parent2')) 35 | .addChild({ resource: '#child1'}) 36 | .addChild(GedcomX.ResourceReference().setResource('#child2')); 37 | assert.equal(family.getParent1().getResource(), '#parent1'); 38 | assert.equal(family.getParent2().getResource(), '#parent2'); 39 | assert.equal(family.getChildren().length, 2); 40 | assert.equal(family.getChildren()[0].getResource(), '#child1'); 41 | assert.equal(family.getChildren()[1].getResource(), '#child2'); 42 | }); 43 | 44 | it('toJSON', function(){ 45 | var data = { 46 | "parent1" : { 47 | "resource" : "#parent1" 48 | }, 49 | "parent2" : { 50 | "resource" : "#parent2" 51 | }, 52 | "children" : [ 53 | { "resource" : "#child1" }, 54 | { "resource" : "#child2" } 55 | ] 56 | }, family = GedcomX.FamilyView(data); 57 | assert.deepEqual(family.toJSON(), data); 58 | }); 59 | 60 | it('constructor does not copy instances', function(){ 61 | var obj1 = GedcomX.FamilyView(); 62 | var obj2 = GedcomX.FamilyView(obj1); 63 | assert.strictEqual(obj1, obj2); 64 | }); 65 | 66 | }); -------------------------------------------------------------------------------- /test/rs/Link.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Link', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.Link(), GedcomX.Link, 'An instance of Link is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.Link(), GedcomX.Link, 'An instance of Link is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var link = GedcomX.Link({ 13 | rel: 'relationship', 14 | href: '/relationship', 15 | template: '/relationship/{}', 16 | type: 'application/x-gedcomx-v1+json', 17 | accept: 'application/x-gedcomx-v1+json', 18 | allow: 'GET', 19 | hreflang: 'en', 20 | title: 'Relationship' 21 | }); 22 | assert.equal(link.getRel(), 'relationship'); 23 | assert.equal(link.getHref(), '/relationship'); 24 | assert.equal(link.getTemplate(), '/relationship/{}'); 25 | assert.equal(link.getType(), 'application/x-gedcomx-v1+json'); 26 | assert.equal(link.getAccept(), 'application/x-gedcomx-v1+json'); 27 | assert.equal(link.getAllow(), 'GET'); 28 | assert.equal(link.getHrefLang(), 'en'); 29 | assert.equal(link.getTitle(), 'Relationship'); 30 | }); 31 | 32 | it('Build', function(){ 33 | var link = GedcomX.Link() 34 | .setRel('relationship') 35 | .setHref('/relationship') 36 | .setTemplate('/relationship/{}') 37 | .setType('application/x-gedcomx-v1+json') 38 | .setAccept('application/x-gedcomx-v1+json') 39 | .setAllow('GET') 40 | .setHrefLang('en') 41 | .setTitle('Relationship'); 42 | assert.equal(link.getRel(), 'relationship'); 43 | assert.equal(link.getHref(), '/relationship'); 44 | assert.equal(link.getTemplate(), '/relationship/{}'); 45 | assert.equal(link.getType(), 'application/x-gedcomx-v1+json'); 46 | assert.equal(link.getAccept(), 'application/x-gedcomx-v1+json'); 47 | assert.equal(link.getAllow(), 'GET'); 48 | assert.equal(link.getHrefLang(), 'en'); 49 | assert.equal(link.getTitle(), 'Relationship'); 50 | }); 51 | 52 | it('toJSON', function(){ 53 | var data = { 54 | rel: 'relationship', 55 | href: '/relationship', 56 | template: '/relationship/{}', 57 | type: 'application/x-gedcomx-v1+json', 58 | accept: 'application/x-gedcomx-v1+json', 59 | allow: 'GET', 60 | hreflang: 'en', 61 | title: 'Relationship' 62 | }, link = GedcomX.Link(data); 63 | assert.deepEqual(link.toJSON(), data); 64 | }); 65 | 66 | it('constructor does not copy instances', function(){ 67 | var obj1 = GedcomX.Link(); 68 | var obj2 = GedcomX.Link(obj1); 69 | assert.strictEqual(obj1, obj2); 70 | }); 71 | 72 | }); -------------------------------------------------------------------------------- /test/rs/Links.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Linkss', function(){ 5 | 6 | it('Create plain', function(){ 7 | assert.instanceOf(new GedcomX.Links(), GedcomX.Links, 'An instance of Links is not returned when calling the constructor with new.'); 8 | assert.instanceOf(GedcomX.Links(), GedcomX.Links, 'An instance of Links is not returned when calling the constructor without new.'); 9 | }); 10 | 11 | it('Create with JSON', function(){ 12 | var links = GedcomX.Links({ 13 | person: { 14 | href: '/person' 15 | } 16 | }); 17 | assert.equal(links.getLinks().length, 1); 18 | assert.instanceOf(links.getLink('person'), GedcomX.Link); 19 | assert.equal(links.getLink('person').getHref(), '/person'); 20 | }); 21 | 22 | it('Build', function(){ 23 | var links = GedcomX.Links() 24 | .setLinks([ 25 | new GedcomX.Link() 26 | .setRel('person') 27 | .setHref('/person') 28 | ]); 29 | assert.equal(links.getLinks().length, 1); 30 | assert.instanceOf(links.getLink('person'), GedcomX.Link); 31 | assert.equal(links.getLink('person').getHref(), '/person'); 32 | }); 33 | 34 | it('toJSON', function(){ 35 | var data = { 36 | person: { 37 | href: '/person' 38 | } 39 | }, links = GedcomX.Links(data); 40 | assert.deepEqual(links.toJSON(), data); 41 | }); 42 | 43 | it('constructor does not copy instances', function(){ 44 | var obj1 = GedcomX.Links(); 45 | var obj2 = GedcomX.Links(obj1); 46 | assert.strictEqual(obj1, obj2); 47 | }); 48 | 49 | }); -------------------------------------------------------------------------------- /test/rs/Name.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Name', function(){ 5 | 6 | it('Create with JSON', function(){ 7 | var name = GedcomX.Name({ 8 | preferred: true, 9 | type: 'http://gedcomx.org/BirthName', 10 | date: { 11 | original: '1 June 1567' 12 | }, 13 | nameForms: [ 14 | { 15 | lang: 'en', 16 | fullText: 'Jonathan Burrows', 17 | parts: [ 18 | { 19 | type: 'http://gedcomx.org/Given', 20 | value: 'Jonathan' 21 | }, 22 | { 23 | type: 'http://gedcomx.org/Surname', 24 | value: 'Burrows' 25 | } 26 | ] 27 | } 28 | ] 29 | }); 30 | assert(name.getPreferred()); 31 | assert.equal(name.getType(), 'http://gedcomx.org/BirthName'); 32 | assert.equal(name.getDate().getOriginal(), '1 June 1567'); 33 | assert.equal(name.getNameForms().length, 1); 34 | assert.equal(name.getNameForms()[0].getFullText(), 'Jonathan Burrows'); 35 | assert.equal(name.getNameForms()[0].getParts().length, 2); 36 | assert.equal(name.getNameForms()[0].getParts()[0].getType(), 'http://gedcomx.org/Given'); 37 | assert.equal(name.getNameForms()[0].getParts()[0].getValue(), 'Jonathan'); 38 | assert.equal(name.getNameForms()[0].getParts()[1].getType(), 'http://gedcomx.org/Surname'); 39 | assert.equal(name.getNameForms()[0].getParts()[1].getValue(), 'Burrows'); 40 | }); 41 | 42 | it('Build', function(){ 43 | var name = GedcomX.Name() 44 | .setPreferred(true) 45 | .setType('http://gedcomx.org/BirthName') 46 | .setDate(GedcomX.Date().setOriginal('1 June 1567')) 47 | .addNameForm( 48 | GedcomX.NameForm() 49 | .setFullText('Jonathan Burrows') 50 | .addPart(GedcomX.NamePart().setType('http://gedcomx.org/Given').setValue('Jonathan')) 51 | .addPart(GedcomX.NamePart().setType('http://gedcomx.org/Surname').setValue('Burrows')) 52 | ); 53 | assert(name.getPreferred()); 54 | assert.equal(name.getType(), 'http://gedcomx.org/BirthName'); 55 | assert.equal(name.getDate().getOriginal(), '1 June 1567'); 56 | assert.equal(name.getNameForms().length, 1); 57 | assert.equal(name.getNameForms()[0].getFullText(), 'Jonathan Burrows'); 58 | assert.equal(name.getNameForms()[0].getParts().length, 2); 59 | assert.equal(name.getNameForms()[0].getParts()[0].getType(), 'http://gedcomx.org/Given'); 60 | assert.equal(name.getNameForms()[0].getParts()[0].getValue(), 'Jonathan'); 61 | assert.equal(name.getNameForms()[0].getParts()[1].getType(), 'http://gedcomx.org/Surname'); 62 | assert.equal(name.getNameForms()[0].getParts()[1].getValue(), 'Burrows'); 63 | }); 64 | 65 | it('toJSON', function(){ 66 | var data = { 67 | preferred: true, 68 | type: 'http://gedcomx.org/BirthName', 69 | date: { 70 | original: '1 June 1567' 71 | }, 72 | nameForms: [ 73 | { 74 | lang: 'en', 75 | fullText: 'Jonathan Burrows', 76 | parts: [ 77 | { 78 | type: 'http://gedcomx.org/Given', 79 | value: 'Jonathan' 80 | }, 81 | { 82 | type: 'http://gedcomx.org/Surname', 83 | value: 'Burrows' 84 | } 85 | ] 86 | } 87 | ] 88 | }, name = GedcomX.Name(data); 89 | assert.deepEqual(name.toJSON(), data); 90 | }); 91 | 92 | }); -------------------------------------------------------------------------------- /test/rs/Person.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('Person', function(){ 5 | 6 | var personJSON = { 7 | id: 'testPerson', 8 | private: true, 9 | living: true, 10 | gender: { 11 | type: 'http://gedcomx.org/Female' 12 | }, 13 | names: [ 14 | { 15 | preferred: true, 16 | type: 'http://gedcomx.org/BirthName', 17 | nameForms: [ 18 | { 19 | fullText: 'Joanna Hopkins' 20 | } 21 | ] 22 | } 23 | ], 24 | facts: [ 25 | { 26 | type: 'http://gedcomx.org/Birth', 27 | date: { 28 | formal: '+2001-04-09' 29 | }, 30 | place: { 31 | original: 'Farm house' 32 | } 33 | } 34 | ], 35 | display: { 36 | "name" : "Joanna Hopkins", 37 | "gender" : "Female" 38 | } 39 | }; 40 | 41 | it('Create with JSON', function(){ 42 | var person = GedcomX.Person(personJSON); 43 | assert.equal(person.getLiving(), true); 44 | assert.equal(person.getId(), 'testPerson'); 45 | assert.equal(person.getPrivate(), true); 46 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); 47 | assert.equal(person.getPreferredName().getNameForms()[0].getFullText(), 'Joanna Hopkins'); 48 | assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); 49 | assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); 50 | assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); 51 | assert.equal(person.getDisplay().getName(), 'Joanna Hopkins'); 52 | }); 53 | 54 | it('Build', function(){ 55 | var person = GedcomX.Person() 56 | .setId('testPerson') 57 | .setLiving(true) 58 | .setPrivate(true) 59 | .setGender(GedcomX.Gender().setType('http://gedcomx.org/Female')) 60 | .addName(GedcomX.Name().setPreferred(true).addNameForm(GedcomX.NameForm().setFullText('Joanna Hopkins'))) 61 | .addFact(GedcomX.Fact().setDate(GedcomX.Date().setFormal('+2001-04-09')).setPlace(GedcomX.PlaceReference().setOriginal('Farm house'))) 62 | .setDisplay(GedcomX.DisplayProperties().setName("Joanna Hopkins").setGender("Female")); 63 | assert.equal(person.getLiving(), true); 64 | assert.equal(person.getId(), 'testPerson'); 65 | assert.equal(person.getPrivate(), true); 66 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); 67 | assert.equal(person.getPreferredName().getNameForms()[0].getFullText(), 'Joanna Hopkins'); 68 | assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); 69 | assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); 70 | assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); 71 | assert.equal(person.getDisplay().getName(), 'Joanna Hopkins'); 72 | }); 73 | 74 | it('toJSON', function(){ 75 | var person = GedcomX.Person(personJSON); 76 | assert.deepEqual(person.toJSON(), personJSON); 77 | }); 78 | 79 | }); -------------------------------------------------------------------------------- /test/rs/PlaceDescription.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('PlaceDescription', function(){ 5 | 6 | var json = { 7 | display: { 8 | name: 'place name', 9 | fullName: 'place name, in a place', 10 | type: 'place type' 11 | } 12 | }; 13 | 14 | it('Create with JSON', function(){ 15 | test(GedcomX.PlaceDescription(json)); 16 | }); 17 | 18 | it('Build', function(){ 19 | test(GedcomX.PlaceDescription() 20 | .setDisplay(json.display)); 21 | }); 22 | 23 | it('toJSON', function(){ 24 | assert.deepEqual(GedcomX.PlaceDescription(json).toJSON(), json); 25 | }); 26 | 27 | }); 28 | 29 | function test(description){ 30 | var display = description.getDisplay(); 31 | assert.equal(display.getName(), 'place name'); 32 | assert.equal(display.getFullName(), 'place name, in a place'); 33 | assert.equal(display.getType(), 'place type'); 34 | } -------------------------------------------------------------------------------- /test/rs/PlaceDisplayProperties.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('PlaceDisplayProperties', function(){ 5 | 6 | var json = { 7 | name: 'place name', 8 | fullName: 'place name, in a place', 9 | type: 'place type' 10 | }; 11 | 12 | it('Create plain', function(){ 13 | assert.instanceOf(new GedcomX.PlaceDisplayProperties(), GedcomX.PlaceDisplayProperties, 'An instance of PlaceDisplayProperties is not returned when calling the constructor with new.'); 14 | assert.instanceOf(GedcomX.PlaceDisplayProperties(), GedcomX.PlaceDisplayProperties, 'An instance of PlaceDisplayProperties is not returned when calling the constructor without new.'); 15 | }); 16 | 17 | it('Create with JSON', function(){ 18 | test(GedcomX.PlaceDisplayProperties(json)); 19 | }); 20 | 21 | it('Build', function(){ 22 | test(GedcomX.PlaceDisplayProperties() 23 | .setName(json.name) 24 | .setFullName(json.fullName) 25 | .setType(json.type)); 26 | }); 27 | 28 | it('toJSON', function(){ 29 | assert.deepEqual(GedcomX.PlaceDisplayProperties(json).toJSON(), json); 30 | }); 31 | 32 | it('constructor does not copy instances', function(){ 33 | var obj1 = GedcomX.PlaceDisplayProperties(); 34 | var obj2 = GedcomX.PlaceDisplayProperties(obj1); 35 | assert.strictEqual(obj1, obj2); 36 | }); 37 | 38 | }); 39 | 40 | function test(display){ 41 | assert.equal(display.getName(), 'place name'); 42 | assert.equal(display.getFullName(), 'place name, in a place'); 43 | assert.equal(display.getType(), 'place type'); 44 | } -------------------------------------------------------------------------------- /test/rs/PlaceReference.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('PlaceReference', function(){ 5 | 6 | it('Create with JSON', function(){ 7 | var place = GedcomX.PlaceReference({ 8 | "original": "Mitchel Field, Hempstead, New York, United States", 9 | "normalized":[ 10 | {"lang": "en-US", "value": "Hempstead, Nassau, New York, United States"} 11 | ] 12 | }); 13 | assert.equal(place.getOriginal(), 'Mitchel Field, Hempstead, New York, United States'); 14 | assert.equal(place.getNormalized().length, 1); 15 | assert.equal(place.getNormalized()[0].getLang(), 'en-US'); 16 | assert.equal(place.getNormalized()[0].getValue(), 'Hempstead, Nassau, New York, United States'); 17 | }); 18 | 19 | it('Build', function(){ 20 | var place = GedcomX.PlaceReference() 21 | .setOriginal('Mitchel Field, Hempstead, New York, United States') 22 | .addNormalized({"lang": "en-US", "value": "Hempstead, Nassau, New York, United States"}); 23 | assert.equal(place.getOriginal(), 'Mitchel Field, Hempstead, New York, United States'); 24 | assert.equal(place.getNormalized().length, 1); 25 | assert.equal(place.getNormalized()[0].getLang(), 'en-US'); 26 | assert.equal(place.getNormalized()[0].getValue(), 'Hempstead, Nassau, New York, United States'); 27 | }); 28 | 29 | it('toJSON', function(){ 30 | var data = { 31 | "original": "Mitchel Field, Hempstead, New York, United States", 32 | "normalized":[ 33 | {"lang": "en-US", "value": "Hempstead, Nassau, New York, United States"} 34 | ] 35 | }, place = GedcomX.PlaceReference(data); 36 | assert.deepEqual(place.toJSON(), data); 37 | }); 38 | 39 | }); -------------------------------------------------------------------------------- /test/rs/ResourceReference.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../../'); 3 | 4 | describe('ResourceReference', function(){ 5 | 6 | it('Create with JSON', function(){ 7 | var rr = GedcomX.ResourceReference({ 8 | resource: 'http://example.com', 9 | resourceId: 'rid' 10 | }); 11 | assert.equal(rr.getResource(), 'http://example.com', 'Resource not saved properly when created with JSON'); 12 | assert.equal(rr.getResourceId(), 'rid'); 13 | }); 14 | 15 | it('Build', function(){ 16 | var rr = GedcomX.ResourceReference() 17 | .setResource('http://example.com') 18 | .setResourceId('rid'); 19 | assert.equal(rr.getResource(), 'http://example.com', 'Resource not saved properly when created with JSON'); 20 | assert.equal(rr.getResourceId(), 'rid'); 21 | }); 22 | 23 | it('toJSON()', function(){ 24 | var data = { 25 | resource: 'http://example.com', 26 | resourceId: 'rid' 27 | }, rr = GedcomX.ResourceReference(data); 28 | assert.deepEqual(rr.toJSON(), data); 29 | }); 30 | 31 | }); -------------------------------------------------------------------------------- /test/rs/index.js: -------------------------------------------------------------------------------- 1 | // Enable RS Extensions so that we can test them 2 | var GedcomX = require('../../'); 3 | GedcomX.enableRsExtensions(); 4 | 5 | // Call it again to test that it doesn't break/change anything 6 | GedcomX.enableRsExtensions(); -------------------------------------------------------------------------------- /test/utils.js: -------------------------------------------------------------------------------- 1 | var assert = require('chai').assert, 2 | GedcomX = require('../'); 3 | 4 | describe('utils', function(){ 5 | 6 | it('removeEmpty', function(){ 7 | assert.deepEqual( 8 | GedcomX.utils.removeEmpty({ 9 | a: undefined, 10 | b: 0, 11 | c: false, 12 | d: null, 13 | e: '' 14 | }), 15 | { 16 | b: 0, 17 | c: false, 18 | d: null, 19 | e: '' 20 | } 21 | ); 22 | }); 23 | 24 | it('pick', function(){ 25 | assert.deepEqual( 26 | GedcomX.utils.pick({ 27 | a: '1', 28 | b: 2, 29 | c: undefined, 30 | d: null 31 | }, ['a','c']), 32 | { 33 | a: '1', 34 | c: undefined 35 | } 36 | ); 37 | }); 38 | 39 | describe('merge', function(){ 40 | 41 | it('objects', function(){ 42 | var dest = {}, 43 | merged = GedcomX.utils.merge( 44 | dest, 45 | { 46 | a: 1, 47 | b: { 48 | b1: 'foo' 49 | } 50 | }, 51 | { 52 | a: 2, 53 | b: { 54 | b2: 'bar' 55 | } 56 | } 57 | ); 58 | assert.strictEqual(dest, merged); 59 | assert.deepEqual( 60 | dest, 61 | { 62 | a: 2, 63 | b: { 64 | b1: 'foo', 65 | b2: 'bar' 66 | } 67 | } 68 | ); 69 | }); 70 | 71 | it('arrays', function(){ 72 | var dest = {}, 73 | merged = GedcomX.utils.merge( 74 | dest, 75 | { 76 | facts: [ 77 | { 78 | date: { 79 | formal: '+2001' 80 | } 81 | } 82 | ] 83 | } 84 | ); 85 | assert.strictEqual(dest, merged); 86 | assert.deepEqual(dest, { 87 | facts: [ 88 | { 89 | date: { 90 | formal: '+2001' 91 | } 92 | } 93 | ] 94 | }); 95 | }); 96 | 97 | }); 98 | 99 | describe('toJSON', function(){ 100 | 101 | it('arrays', function(){ 102 | assert.deepEqual( 103 | GedcomX.utils.toJSON({ 104 | facts: [ 105 | GedcomX.Fact({ 106 | date: { 107 | formal: '+2001' 108 | } 109 | }) 110 | ] 111 | }), 112 | { 113 | facts: [ 114 | { 115 | date: { 116 | formal: '+2001' 117 | } 118 | } 119 | ] 120 | } 121 | ); 122 | }); 123 | 124 | }); 125 | 126 | }); -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | entry: [__dirname + "/src/index.js"], 3 | output: { 4 | path: __dirname + "/dist", 5 | library: 'GedcomX' 6 | } 7 | }; --------------------------------------------------------------------------------