Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

geojsonjs

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geojsonjs - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

src/functions.d.ts

2

package.json
{
"name": "geojsonjs",
"version": "0.0.6",
"version": "0.0.7",
"description": "Build and validate GeoJSON",

@@ -5,0 +5,0 @@ "main": "./src/index.js",

@@ -31,4 +31,2 @@ # Build and validate GeoJSON with Node.js

```js
import geojson from 'geojsonjs';
const geom = {

@@ -47,9 +45,441 @@ type: 'FeatureCollection',

const valid = geojson(geom).isValid;
import { toFeatureCollection } from 'geojsonjs';
const featureCollection = toFeatureCollection(geom);
const result = validate(featureCollection);
// TypeScript
import {
toFeatureCollection,
FeatureCollection,
ValidationResult,
} from 'geojsonjs';
const featureCollection: FeatureCollection = toFeatureCollection(geom);
const result: ValidationResult = validate(featureCollection);
```
## Documentation
# Documentation
Documentation can be found [here](/docs/readme.md)
## Global functions
| Name | Returns | |
| ---------------------- | ------------------- | ---------------------------------- |
| `parse` | `FeatureCollection` | [More info](#parse) |
| `getGeometries` | `Geometry[]` | [More info](#getgeometries) |
| `getFeatures` | `Feature[]` | [More info](#getfeatures) |
| `getFeatureCollection` | `FeatureCollection` | [More info](#getfeaturecollection) |
### parse
Accepts array or object of `type`, `coordinates` and `properties` (optional)
Returns [feature collection](#feature-collection)
**Example:**
```js
import { parse } from 'geojsonjs';
const featureCollection = parse({ type: 'Point', coordinates: [11, 22] });
const featureCollection2 = parse([
{ type: 'Point', coordinates: [11, 22], properties: { prop1: 'prop1' } },
]);
// TypeScript
import { parse, FeatureCollection } from 'geojsonjs';
const featureCollection: FeatureCollection = parse({
type: 'Point',
coordinates: [11, 22],
});
const featureCollection2: FeatureCollection = parse([
{ type: 'Point', coordinates: [11, 22], properties: { prop1: 'prop1' } },
]);
```
### getGeometries
Finds and returns all geometries from data.
Supports [all geometry types](#supported-types).
Returns [array of geometries](#geometries-array)
**Example:**
```js
import { getGeometries } from 'geojson';
const geometries = getGeometries(geom);
// TypeScript
import { getGeometries, Geometry } from 'geojson';
const geometries: Geometry[] = getGeometries(geom);
```
### getFeatures
Finds and returns all features from data.
Supports [all geometry types](#supported-types).
Returns [array of features](#features-array)
**Example:**
```js
import { getFeatures } from 'geojson';
const features = getFeatures(geom);
// TypeScript
import { getFeatures, Feature } from 'geojson';
const features: Feature[] = getFeatures(geom);
```
### getFeatureCollection
Finds and returns feature collection from data.
Supports [all geometry types](#supported-types).
Returns [feature collection](#feature-collection)
**Example:**
```js
import { getFeatureCollection } from 'geojson';
const featureCollection = getFeatureCollection(geom);
// TypeScript
import { getFeatureCollection, FeatureCollection } from 'geojson';
const featureCollection: FeatureCollection = getFeatureCollection(geom);
```
## Validation
Each validation returns
[Validation Result](#validation-result) response
| Name | Params | |
| --------------------------- | --------------------------------------------- | --------------------------------------- |
| `validateCoordinates` | `type: string, coordinates: CoordinatesTypes` | [More info](#validatecoordinates) |
| `validateGeometry` | `geometry: Geometry` | [More info](#validategeometry) |
| `validateFeature` | `feature: Feature` | [More info](#validatefeature) |
| `validateFeatures` | `features: Feature[]` | [More info](#validatefeatures) |
| `validateFeatureCollection` | `collection: FeatureCollection` | [More info](#validatefeaturecollection) |
| `validateGeometryTypes` | `types: string \| string [], geom: AllTypes` | [More info](#validategeometrytypes) |
### validateCoordinates
Accepts `type` and `coordinates`.
**Example:**
```js
import { validateCoordinates } from 'geojsonjs';
const result = validateCoordinates('Point', [11, 12]);
// TypeScript
import { validateCoordinates, ValidationResult } from 'geojsonjs';
const result: ValidationResult = validateCoordinates('Point', [11, 12]);
```
### validateGeometry
Accepts [geometry](#geometry)
**Example:**
```js
const geometry = { type: 'Point', coordinates: [11, 22] };
import { validateGeometry } from 'geojsonjs';
const result = validateGeometry(geometry);
// TypeScript
import { validateGeometry, ValidationResult } from 'geojsonjs';
const result: ValidationResult = validateGeometry(geometry);
```
### validateFeature
Accepts [feature](#feature)
**Example:**
```js
const feature = {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [11, 22],
},
};
import { validateFeature } from 'geojsonjs';
const result = validateFeature(feature);
// TypeScript
import { validateFeature, ValidationResult } from 'geojsonjs';
const result: ValidationResult = validateFeature(feature);
```
### validateFeatures
Accepts [features array](#features-array)
**Example:**
```js
const features = [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [11, 22],
},
},
];
import { validateFeatures } from 'geojsonjs';
const result = validateFeatures(features);
// TypeScript
import { validateFeatures, ValidationResult } from 'geojsonjs';
const result: ValidationResult = validateFeatures(features);
```
### validateFeatureCollection
Accepts [feature collection](#feature-collection)
**Example:**
```js
const featureCollection = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [11, 22],
},
},
],
};
import { validateFeatureCollection } from 'geojsonjs';
const result = validateFeatureCollection(featureCollection);
// TypeScript
import { validateFeatureCollection, ValidationResult } from 'geojsonjs';
const result: ValidationResult = validateFeatureCollection(featureCollection);
```
### validateGeometryTypes
**Example:**
Accepts [geometry type OR array of geometry types](#geometry-types) and [feature collection](#feature-collection)
```js
const featureCollection = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [11, 22],
},
},
],
};
import { GeometryType, validateGeometryTypes } from 'geojsonjs';
const result = validateGeometryTypes([GeometryType.POINT], featureCollection);
// TypeScript
import {
GeometryType,
validateGeometryTypes,
ValidationResult,
} from 'geojsonjs';
const result: ValidationResult = validateGeometryTypes(
GeometryType.POINT,
featureCollection
);
```
## Types
- Geometry types
- [Feature Collection](#feature-collection)
- [Feature Collections (array)](#feature-collections-array)
- [Feature](#feature)
- [Features (array)](#features-array)
- [Geometry](#geometry)
- [Geometries (array)](#geometries-array)
- [Geometry item types](#geometry-types)
- Point
- MultiPoint
- LineString
- MultiLineString
- Polygon
- MultiPolygon
- [Validation result](#validation-result)
- [Validation errors](#validation-errors)
### Feature Collection
```json
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [11, 22]
}
}
]
}
```
### Feature Collections (array)
```json
[
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [11, 22]
}
}
]
},
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [33, 44]
}
}
]
}
]
```
### Feature
```json
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [11, 22]
}
}
```
### Features (array)
```json
[
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [11, 22]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [33, 44]
}
}
]
```
### Geometry
```json
{
"type": "Point",
"coordinates": [11, 22]
}
```
### Geometries (array)
```json
[
{
"type": "Point",
"coordinates": [11, 22]
},
{
"type": "Point",
"coordinates": [33, 44]
}
]
```
### Geometry types
```js
import { GeometryType } from 'geojsonjs';
GeometryType.POINT; // Point
GeometryType.MULTI_POINT; // MultiPoint
GeometryType.LINE_STRING; // LineString
GeometryType.MULTI_LINE_STRING; // MultiLineString
GeometryType.POLYGON; // Polygon
GeometryType.MULTI_POLYGON; // MultiPolygon
```
### Validation Result˝
**Valid example:**
```json
{
"valid": true
}
```
**Invalid example:**
```json
{
"valid": false,
"error": "INVALID_TYPE",
"data": {
"type": "Pointt"
}
}
```
### Validation Errors
```js
import { ValidationError } from 'geojsonjs';
ValidationError.EMTPY; // EMTPY
ValidationError.EMPTY_FEATURES; // EMPTY_FEATURES
ValidationError.EMPTY_COORDINATES; // INVALID_COORDINATES
ValidationError.EMPTY_TYPE; // EMPTY_TYPE
ValidationError.INVALID_TYPE; // INVALID_TYPE
ValidationError.INVALID_FEATURES; // INVALID_FEATURES
ValidationError.INVALID_COORDINATES; // INVALID_COORDINATES
ValidationError.INVALID_PROPERTIES; // INVALID_PROPERTIES
```
## Contributing

@@ -56,0 +486,0 @@

@@ -1,6 +0,3 @@

import { GeoJSON } from './geojson';
export * from './validate';
export * from './types';
export * from './helpers';
export * from './geojson';
export default function geojson(geom?: any): GeoJSON;
export * from './functions';

@@ -17,11 +17,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const geojson_1 = require("./geojson");
__exportStar(require("./validate"), exports);
__exportStar(require("./types"), exports);
__exportStar(require("./helpers"), exports);
__exportStar(require("./geojson"), exports);
function geojson(geom) {
return new geojson_1.GeoJSON(geom);
}
exports.default = geojson;
__exportStar(require("./functions"), exports);
//# sourceMappingURL=index.js.map

@@ -14,3 +14,2 @@ export type GenericObject = {

coordinates: CoordinatesTypes;
properties?: GenericObject | null;
};

@@ -23,4 +22,4 @@ export type FeatureCollection = {

type: 'Feature';
properties?: any;
geometry: Geometry;
properties?: GenericObject;
};

@@ -47,3 +46,3 @@ export declare const FEATURE_COLLECTION_TYPE = "FeatureCollection";

};
export type AllTypes = Geometry | Geometry[] | Feature | Feature[] | FeatureCollection;
export type AllTypes = Geometry | Geometry[] | Feature | Feature[] | FeatureCollection | FeatureCollection[];
export type ValidationResult = {

@@ -50,0 +49,0 @@ valid: boolean;

@@ -6,3 +6,3 @@ "use strict";

const types_1 = require("./types");
const helpers_1 = require("./helpers");
const functions_1 = require("./functions");
function transformResponse(error, data) {

@@ -111,3 +111,3 @@ if (error) {

}
const invalidTypes = (0, helpers_1.getGeometries)(geom)
const invalidTypes = (0, functions_1.getGeometries)(geom)
.map((item) => item.type)

@@ -114,0 +114,0 @@ .filter((t) => !types.includes(t));

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc