New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@turf/invariant

Package Overview
Dependencies
Maintainers
4
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/invariant - npm Package Compare versions

Comparing version 4.7.3 to 5.0.0-alpha

index.es5.js

30

index.d.ts

@@ -6,21 +6,23 @@ /// <reference types="geojson" />

export type Feature<Geom extends GeometryObject> = GeoJSON.Feature<Geom>;
export type Features<Geom extends GeometryObject> = GeoJSON.FeatureCollection<Geom>;
export type FeatureCollection<Geom extends GeometryObject> = GeoJSON.FeatureCollection<Geom>;
export type StringGeomTypes = 'Point' | 'LineString' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'GeometryCollection'
export type StringTypes = StringGeomTypes | 'Feature' | 'FeatureCollection'
/**
* http://turfjs.org/docs/
* http://turfjs.org/docs/#getcoords
*/
export function getCoord(obj: Feature<any> | GeometryObject | any[]): Array<any>;
export function getCoord(obj: Feature<any> | GeometryObject | any[]): number[];
/**
* http://turfjs.org/docs/
* http://turfjs.org/docs/#getcoords
*/
export function getCoords(obj: Feature<any> | GeometryObject | any[]): Array<any>;
export function getCoords(obj: Feature<any> | GeometryObject | any[]): any[];
/**
* http://turfjs.org/docs/
* http://turfjs.org/docs/#geojsontype
*/
export function geojsonType(value: Features<any>, type: string, name: string): void;
export function geojsonType(value: FeatureCollection<any>, type: string, name: string): void;
/**
* http://turfjs.org/docs/
* http://turfjs.org/docs/#featureof
*/

@@ -30,8 +32,8 @@ export function featureOf(feature: Feature<any>, type: string, name: string): void;

/**
* http://turfjs.org/docs/
* http://turfjs.org/docs/#collectionof
*/
export function collectionOf(featurecollection: Features<any>, type: string, name: string): void;
export function collectionOf(featurecollection: FeatureCollection<any>, type: string, name: string): void;
/**
* http://turfjs.org/docs/
* http://turfjs.org/docs/#containsnumber
*/

@@ -41,3 +43,3 @@ export function containsNumber(coordinates: any[]): boolean;

/**
* http://turfjs.org/docs/
* http://turfjs.org/docs/#getgeom
*/

@@ -47,4 +49,4 @@ export function getGeom(geojson: GeometryCollection | GeometryObject | Feature<any>): GeometryObject;

/**
* http://turfjs.org/docs/
* http://turfjs.org/docs/#gettype
*/
export function getGeomType(geojson: GeometryCollection | GeometryObject | Feature<any>): string;
export function getType(geojson: GeometryCollection | GeometryObject | Feature<any> | FeatureCollection<any>): StringTypes;

@@ -13,3 +13,3 @@ /**

*/
function getCoord(obj) {
export function getCoord(obj) {
if (!obj) throw new Error('obj is required');

@@ -41,3 +41,3 @@

*/
function getCoords(obj) {
export function getCoords(obj) {
if (!obj) throw new Error('obj is required');

@@ -73,3 +73,3 @@ var coordinates;

*/
function containsNumber(coordinates) {
export function containsNumber(coordinates) {
if (coordinates.length > 1 &&

@@ -96,3 +96,3 @@ typeof coordinates[0] === 'number' &&

*/
function geojsonType(value, type, name) {
export function geojsonType(value, type, name) {
if (!type || !name) throw new Error('type and name required');

@@ -115,3 +115,3 @@

*/
function featureOf(feature, type, name) {
export function featureOf(feature, type, name) {
if (!feature) throw new Error('No feature passed');

@@ -137,3 +137,3 @@ if (!name) throw new Error('.featureOf() requires a name');

*/
function collectionOf(featureCollection, type, name) {
export function collectionOf(featureCollection, type, name) {
if (!featureCollection) throw new Error('No featureCollection passed');

@@ -173,3 +173,3 @@ if (!name) throw new Error('.collectionOf() requires a name');

*/
function getGeom(geojson) {
export function getGeom(geojson) {
if (!geojson) throw new Error('geojson is required');

@@ -184,5 +184,14 @@ if (geojson.geometry !== undefined) return geojson.geometry;

*
* @param {Feature|Geometry} geojson GeoJSON Feature or Geometry Object
* @returns {string} GeoJSON Geometry Type
* @throws {Error} if geojson is not a Feature or Geometry Object
* @throws {Error} **DEPRECATED** in v5.0.0 in favor of getType
*/
export function getGeomType() {
throw new Error('invariant.getGeomType has been deprecated in v5.0 in favor of invariant.getType');
}
/**
* Get GeoJSON object's type, Geometry type is prioritize.
*
* @param {GeoJSON} geojson GeoJSON object
* @param {string} [name] name of the variable to display in error message
* @returns {string} GeoJSON type
* @example

@@ -197,20 +206,12 @@ * var point = {

* }
* var geom = turf.getGeomType(point)
* var geom = turf.getType(point)
* //="Point"
*/
function getGeomType(geojson) {
if (!geojson) throw new Error('geojson is required');
var geom = getGeom(geojson);
if (geom) return geom.type;
export function getType(geojson, name) {
if (!geojson) throw new Error((name || 'geojson') + ' is required');
// GeoJSON Feature & GeometryCollection
if (geojson.geometry && geojson.geometry.type) return geojson.geometry.type;
// GeoJSON Geometry & FeatureCollection
if (geojson.type) return geojson.type;
throw new Error((name || 'geojson') + ' is invalid');
}
module.exports = {
geojsonType: geojsonType,
collectionOf: collectionOf,
featureOf: featureOf,
getCoord: getCoord,
getCoords: getCoords,
containsNumber: containsNumber,
getGeom: getGeom,
getGeomType: getGeomType
};
{
"name": "@turf/invariant",
"version": "4.7.3",
"version": "5.0.0-alpha",
"description": "turf invariant module",
"main": "index.js",
"main": "index.es5.js",
"module": "index.js",
"jsnext:main": "index.js",
"types": "index.d.ts",
"files": [
"index.js",
"index.d.ts"
"index.d.ts",
"index.es5.js"
],
"scripts": {
"test": "node test.js",
"pretest": "rollup -c ../../rollup.config.js",
"test": "node test.es5.js",
"bench": "node bench.js"
},
"repository": {
"type": "git",
"url": "git://github.com/Turfjs/turf.git"
},
"keywords": [

@@ -21,16 +29,18 @@ "turf",

"author": "Turf Authors",
"contributors": [
"Tom MacWright <@tmcw>",
"Denis Carriere <@DenisCarriere>"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/Turfjs/turf.git"
},
"homepage": "https://github.com/Turfjs/turf",
"bugs": {
"url": "https://github.com/Turfjs/turf/issues"
},
"homepage": "https://github.com/Turfjs/turf",
"devDependencies": {
"@turf/helpers": "^4.7.3",
"benchmark": "2.1.4",
"tape": "4.8.0"
}
"@turf/helpers": "*",
"benchmark": "*",
"rollup": "*",
"tape": "*"
},
"dependencies": {}
}

@@ -122,2 +122,3 @@ # @turf/invariant

Get Geometry Type from Feature or Geometry Object
**DEPRECATED** in v5.0.0 in favor of getType

@@ -127,2 +128,3 @@ **Parameters**

- `geojson` **([Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry))** GeoJSON Feature or Geometry Object
- `name` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** name of the variable to display in error message

@@ -148,2 +150,28 @@ **Examples**

# getType
Get GeoJSON object's type, Geometry type is prioritize.
**Parameters**
- `geojson` **[GeoJSON](http://geojson.org/geojson-spec.html#geojson-objects)** GeoJSON object
- `name` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** name of the variable to display in error message
**Examples**
```javascript
var point = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [110, 40]
}
}
var geom = turf.getType(point)
//="Point"
```
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** GeoJSON type
<!-- This file is automatically generated. Please don't edit it directly:

@@ -150,0 +178,0 @@ if you find an error, edit the source file (likely index.js), and re-run

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