順豐香港地址

Posted on Tue, Sep 4, 2018 科技趣聞

網址

GitLab: https://gitlab.com/lenchan139/nodejs-module-sfaddress-hk

npmjs: https://www.npmjs.com/package/sfaddress-hk

起因

其實起因唔係咩複雜事,就係我司要搞新嘅responsive web,而當中會有郵寄,而且係用順豐作delivery嘅,不過一直以來都係要由用戶手打編號/順豐站地址。所以我咪順便收集埋順豐站地址 from 官網然之後整成簡單嘅module方便下。

簡介

方便大家拎順豐地址用嘅npm modules

安裝

前往你嘅nodejs project,鍵入:npm i sfaddress-hk

太初

  // 創建最基本嘅 sf object
const sf = require('sfaddress-hk')

  // 使用預設嘅順豐站地址(順豐站-中文)
const sfaddress = sf()

  // 或者你可以用本身內置嘅順豐站資料
const csvKeys = sf().csv
const sfaddress = sf(csvKeys.store_en) // 順豐站(英文)
const sfaddress = sf(csvKeys.store_zh) // 順豐站(中文)
const sfaddress = sf(csvKeyss.locker_zh) // Locker自取點(中文)

  // 或者,你可以按照以下格式製作一份合乎格式嘅CSV檔案以便程式讀取。
  // 請注意,如果 district 爲空,程式會嘗試複製上一行嘅 district 。
  // CSV 例子:
  // "district", "code" , "address", "weekday" , "weekend"
  // "香港仔",852TAL,"香港香港仔大道 234 號富嘉工業大廈 9 樓 6 室","11:00-22:00","12:00-20:00"
  // "",852TBL,"香港薄扶林華富道18號華富(一)邨華安樓119號舖","11:00-22:00","12:00-20:00"
  // "鴨脷洲",852TCL,"香港鴨脷洲鴨脷洲大街42-44號地下1號舖","11:00-22:00","12:00-20:00"
  // .....
const sfaddress = require('sfaddress-hk')(your_custom_csv)

使用

  // 獲取所有地點資料:
  sfaddress.allStore // array<object>

  // 獲取所有可使用嘅地區(district) :
  sfaddress.allDistrict // array<string>

  // 以 district 獲取地點資料(district需完全相符):
  sfaddress.searchByDistrict('香港仔') //return array<object>

  // 以地點代碼獲取地點(需一致):
  sfaddress.getByCode('852TAL') // return object

  // 以地址內容作地點資料之搜尋:
  sfaddress.searchInAddress('地下')

  //你亦可以以RegExp方式搜尋:
  sfaddress.searchInAddress(/[A-Z]/g)

額外

  // 獲取該Module之根目錄路徑:
  sfaddress.dirname

  //獲取 index.js 之路徑:
  sfaddress.filename

授權

address infomation is owned by SF-Express.the other code is licensed under ISC:

Copyright 2018-, Len Chan<[email protected]>

Permission to use, copy, modify,and/or distributethis softwarefor any purpose withor without feeis hereby granted, provided that the above copyright noticeandthis permission notice appearin all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.