1.3.0 • Published 15 days ago

pidf-lo v1.3.0

Weekly downloads
318
License
MIT
Repository
github
Last release
15 days ago

pidf-lo - PIDF-LO and GEOPRIV handling

This library should simplify handling PIDF-LO GEOPRIV documents as described in https://tools.ietf.org/html/rfc5491.

This README currently only describes simple usage of this library. More elaborate implementation examples will be added by time.

Important Notices

This implemenentation only covers a small portion of the PIDF-LO specification documents and is (by far) not complete. Pull requests are therefore highly honored.

This library requires @xmldom/xmldom as a peer-dependency only in node.js environments! JavaScript browser environments always have a DOM implementation on board, therefore @xmldom/xmldom is not needed there.

Installation

Requires node.js and npm.

npm install pidf-lo

Simplified Usage (WGS84 locations)

PIDF-LO creation

import { 
  LocationMethod, 
  PidfLo, 
  XMLCompat,

  getNodeImpl,
  getWebImpl,
} from 'pidf-lo';

// if xmldom interface is available (e.g. on web browsers)
XMLCompat.initialize(getNodeImpl());
// if xmldom interface is NOT available (e.g. on node environments)
// also don't forget to install required peer dependency @xmldom/xmldom
XMLCompat.initialize(getWebImpl());

const pidf = PidfLo.fromSimpleLocation({
  latitude: 48.123,
  longitude: 14.456,
  radius: 24,
  method: LocationMethod.GPS,
});

if (!pidf)
  throw 'Something is wrong with this location';

const xmlObj = pidf.toXML();
console.log(XMLCompat.toXMLString(xmlObj));

PIDF-LO parsing

import { 
  PidfLo, 
  XMLCompat,

  getNodeImpl,
  getWebImpl,
} from 'pidf-lo';

// if xmldom interface is available (e.g. on web browsers)
XMLCompat.initialize(getNodeImpl());
// if xmldom interface is NOT available (e.g. on node environments)
// also don't forget to install required peer dependency @xmldom/xmldom
XMLCompat.initialize(getWebImpl());

const parsed = PidfLo.fromXML('<xml...>');

if (!parsed || !parsed.simple)
  throw 'Something is wrong with this location';

const simpleLoc = parsed.simple;
console.log(`${simpleLoc.latitude} ${simpleLoc.longitude}`);

Usage (Civic Addresses)

PIDF-LO creation

import { 
  LocationMethod, 
  PidfLo, 

  getNodeImpl,
  getWebImpl,
} from 'pidf-lo';

// if xmldom interface is available (e.g. on web browsers)
XMLCompat.initialize(getNodeImpl());
// if xmldom interface is NOT available (e.g. on node environments)
// also don't forget to install required peer dependency @xmldom/xmldom
XMLCompat.initialize(getWebImpl());

const pidf = PidfLo.fromSimpleLocation({
  civic: {
    country: 'AT',
    A1: 'Upper Austria',
    A4: 'Schärding',
    FLR: '5',
    PC: '4780',
    NAM: 'Hospital',
  },
  method: LocationMethod['AP-802.11'],
}, 'lkh-schaerding.at');

if (!pidf)
  throw 'Something is wrong with this location';

const xmlObj = pidf.toXML();
console.log(XMLCompat.toXMLString(xmlObj));

PIDF-LO parsing

import { 
  PidfLo,
  
  getNodeImpl,
  getWebImpl,
} from 'pidf-lo';

// if xmldom interface is available (e.g. on web browsers)
XMLCompat.initialize(getNodeImpl());
// if xmldom interface is NOT available (e.g. on node environments)
// also don't forget to install required peer dependency @xmldom/xmldom
XMLCompat.initialize(getWebImpl());

const parsed = PidfLo.fromXML('<xml...>');

if (!parsed || !parsed.simple || !parsed.simple.civic)
  throw 'Something is wrong with this location';

const simpleCivic = parsed.simple.civic;
console.log(`${simpleCivic.country} ${simpleCivic.A1}`);

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

Distributed under the MIT License. See LICENSE for more information.

1.3.0

15 days ago

1.2.0

7 months ago

0.9.6

5 months ago

1.2.1

5 months ago

1.1.0

10 months ago

0.9.5

10 months ago

1.0.2

12 months ago

1.0.1

1 year ago

1.0.0

1 year ago

0.9.4

1 year ago

0.9.3

1 year ago

0.9.2

2 years ago

0.9.1

2 years ago

0.9.0

2 years ago

0.8.0

3 years ago

0.7.0

3 years ago

0.5.0

3 years ago

0.6.0

3 years ago

0.5.1

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago