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

@geocoder-free/utils

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@geocoder-free/utils

utils for geocoding including purging addresses etc.

  • 0.2.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
112
decreased by-40.11%
Maintainers
1
Weekly downloads
 
Created
Source

@geocoder-free/utils

Description

Utils for geocoding.

Installation

Install the package in your project directory with:

// with npm
npm install @geocoder-free/utils

// with yarn
yarn add @geocoder-free/utils

Install From Browser

<script src="https://cdn.jsdelivr.net/npm/@geocoder-free/utils@0.2.8/umd/geocoderfreeutils.min.js"></script>

Extra Installation

If you want to use HttpClient in server, node-fetch is required:

// with npm
npm install node-fetch

// with yarn
yarn add node-fetch

If you want to use HttpClient in client, fetch-jsonp is required:

// with npm
npm install fetch-jsonp

// with yarn
yarn add fetch-jsonp

APIs

  • How to import
  • HttpClient
    • Get: fetch data by url. using jsonp in client and node-fetch in server to avoid CORS errors in client.
    • GetUrl: get redirected url.
    • Post: post and get data by url. using jsonp in client and node-fetch in server to avoid CORS errors in client.
  • Functions for all
  • Functions for Japan only

Import

import { xxx } from '@geocoder-free/utils';

eg: import { dms2deg } from '@geocoder-free/utils';

Import From Browser

const { xxx } = GeocoderFreeUtils;

eg: const { dms2deg } = GeocoderFreeUtils;

HttpClient

Packages node-fetch and fetch-jsonp are required by HttpClient.

Get

jsonp mode Can be disabled by pasing true to the 3rd parameter.

No.ParameterRequiredTypeDefaultDescription
1urlstring
2returnTypestring'json'type of response, 'json' or 'text'
3forceNodeFetchbooleanfalseif true, fetching data by jsonp will be disabled.
import { Get } from '@geocoder-free/utils/HttpClient';

Get(`https://api.google.com/xxxxxx`).then(console.log);
GetUrl

Get the redirected url.

No.ParameterRequiredTypeDefaultDescription
1urlstring
import { GetUrl } from '@geocoder-free/utils/HttpClient';

GetUrl(`https://goo.gl/maps/nQjjgsyid7iGa42J8`).then(console.log);
// get 'https://www.google.com/maps/place/%E7%9A%87%E5%B1%85/@35.6938997,139.7628928,15z/data=!4m5!3m4!1s0x60188c0d02d8064d:0xd11a5f0b379e6db7!8m2!3d35.6851739!4d139.7527993'
Post

jsonp mode Can be disabled by pasing true to the 3rd parameter.

No.ParameterRequiredTypeDefaultDescription
1urlstring
2dataobjectdata for post
3forceNodeFetchbooleanfalseif true, fetching data by jsonp will be disabled.
import { Post } from '@geocoder-free/utils/HttpClient';

Post(`https://api.google.com/xxxxxx`).then(console.log);

dms2deg

No.ParameterRequiredTypeDefaultDescription
1dmsStrstringdms string
dms2deg(`35°39'31.3"N`);
// get 35.658694

dms2deg(`139°44'40.3"W`);
// get -139.744528

getLatLngByDMSStr

No.ParameterRequiredTypeDefaultDescription
1latlngDmsStrstringstring contains dms latitude & dms longitude
getLatLngByDMSStr(`35°39'31.3"N+139°44'40.3"E`);
// get [35.658694, 139.744528]

getLatLngByDecimalStr

No.ParameterRequiredTypeDefaultDescription
1latlngDecimalStrstringstring contains decimal latitude & decimal longitude(split by comma)
getLatLngByDecimalStr(`35.123, 149.123`);
// get [35.123, 149.123]

getLatLngCentroid

No.ParameterRequiredTypeDefaultDescription
1latLngInDegrarraylist of LatLngArray ([latitude, longitude])
getLatLngCentroid([[35.123, 139.234], [35.456, 139.567]]);
// get [35.289614, 139.400158]

getLatLngObj

No.ParameterRequiredTypeDefaultDescription
1latlngDecimalStrstringstring contains decimal latitude & decimal longitude(split by comma)
getLatLngObj(`35.123, 149.123`);
// get { lat: 35.123, lng: 149.123 }

getLocaleString

No.ParameterRequiredTypeDefaultDescription
1dateStrstringoutput is different in different timezone
getLocaleString(`2019-08-29`);
// get "2019/8/29 9:00:00"

logFormat

No.ParameterRequiredTypeDefaultDescription
1msgstringmessage
2funcfunctionnullcall func(formatted string) if func is not null
// example is in Asia/Tokyo

logFormat(`hello`);
// get "2019/8/29 9:00:00 -- hello"

logFormat(`hello`, (str) => `[info]${str}`);
// get "[info]2019/8/29 9:00:00 -- hello"

removeSpace

No.ParameterRequiredTypeDefaultDescription
1strstring
removeSpace('  2 3  4  ');
// get "234"

isCorrectLatLng

No.ParameterRequiredTypeDefaultDescription
1latlngArrarray[latitude, longitude]
isCorrectLatLng([NaN, 139.1]);
// get false

isCorrectLatLng([35.123, NaN]);
// get false

isCorrectLatLng([35.123, 139.1]);
// get true

getTimeByTimezone

No.ParameterRequiredTypeDefaultDescription
1dateStrstring
2timezonenumber
/*
in UTC system.
*/
getTimeByTimezone('2019-09-01 11:00:00', 9);
// get 1567303200000

new Date('2019-09-01 11:00:00').getTime();
// get 1567335600000

formatDate

No.ParameterRequiredTypeDefaultDescription
1datestring / date
2formatstringyyyy/MM/dd HH:mm:ssfor '2019-01-09 08:01:01', yyyy: 2019; yy: 19; MM: 01; M: 1; dd: 09; d: 9; HH: 08; H: 8; mm: 01; m: 1; ss: 01; s: 1; SSS: 000;
formatDate('2019-09-01 8:00:00', 'yyyy/M/d H:m:s');
// get "2019/9/1 8:0:0"

cutToBlockNumber

番地までの住所を取得

No.ParameterRequiredTypeDefaultDescription
1addressstring番地の後ろにスペースが必要
cutToBlockNumber('新宿区 2-3-1 新宿ビル305');
// get "新宿区 2-3-1"

removePostCode

郵便マーク(〒)を削除

removePostCode('〒123-1234+tokyo');
// get "123-1234+tokyo"

License

This project is licensed under the terms of the MIT license.

Keywords

FAQs

Package last updated on 12 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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