51degrees 中文文档教程
51degrees.node
![Gitter](https://badges.gitter .im/Join Chat.svg)
51degrees c-sdk native bindings for nodejs, 它可以帮助您从 userAgent
中高性能地检测设备。
Windows | Mac/Linux |
---|---|
API
.Parse(filename[, properties, options])
filename
{String} 您的 51degrees 数据,精简版或高级版。properties
{Array} 可选,必需属性options
{Object}options.autoUpdate
{Boolean} 启用/禁用autoUpdate
featureoptions.key
{String} 自动更新需要 51Degreesoptions.interval
{Integer} 的许可证密钥,默认值 30 * 60 * 1000(半小时)options.onupdated
{Function} 如果自动更新,你会在这个函数上接到电话以
获取更多信息,你可以移动到 51degrees 文档
parser.parse(userAgent)
userAgent
{String}
解析你给的userAgent
,并返回结果。
Usage
var Parser = require('51degrees').Parser;
var psr = new Parser('51Degrees-Lite.dat');
var userAgent = '...'; // your userAgent in any clients(browser/ios/android)
var ret = psr.parse(userAgent);
console.log(ret);
Create an auto-updated pattern parser
var psr = new Parser('51Degrees-Lite.dat', [], {
autoUpdate: true,
key: 'your license key'
});
注意:此功能仅用于pattern数据。
在上面的程序之后,你将得到:
{ Id: '17595-21721-21635-18092',
Canvas: true,
CssTransforms: true,
CssTransitions: true,
History: true,
Html5: true,
IndexedDB: true,
IsMobile: false,
Json: true,
PostMessage: true,
Svg: true,
TouchEvents: true,
WebWorkers: true,
method: 'trie',
data: {} }
.ALL_PROPERTIES
51Degrees.node
exposure ALL_PROPERTIES
以快速从 userAgent
中获取所有属性,就像这样使用:
var properties = require('51degrees').ALL_PROPERTIES;
var userAgent = '...' // your userAgent in any clients(browser/ios/android)
var psr = new Parser('51Degrees-Lite.trie', properties);
var ret = psr.parse(userAgent);
console.log(ret);
Then will打印整个属性,这对于概述此模块和 51Degrees 产品非常有用。
Properties
以下列表显示了 51degrees 将以 json 格式导出的所有属性:
AnimationTiming
BlobBuilder
Canvas
CssBackground
CssBorderImage
CssCanvas
CssColor
CssColumn
CssFlexbox
CssFont
CssImages
CssMediaQueries
CssMinMax
CssOverflow
CssPosition
CssText
CssTransforms
CssTransitions
CssUI
DataSet
DataUrl
DeviceOrientation
FileReader
FileSaver
FileWriter
FormData
Fullscreen
GeoLocation
History
Html5
Html-Media-Capture
Id
Iframe
IndexedDB
IsMobile
Json
LayoutEngine
Masking
PostMessage
Progress
Prompts
ScreenPixelsHeight
ScreenPixelsWidth
Selector
Svg
TouchEvents
Track
Video
Viewport
WebWorkers
Xhr
Installation
$ npm install 51degrees --save
License
51degrees.node
![Gitter](https://badges.gitter.im/Join Chat.svg)
51degrees c-sdk native bindings for nodejs, it helps you detect devices from userAgent
in high performance.
Windows | Mac/Linux |
---|---|
API
.Parse(filename[, properties, options])
filename
{String} your 51degrees data, lite or premium.properties
{Array} optional, required propertiesoptions
{Object}options.autoUpdate
{Boolean} enable/disableautoUpdate
featureoptions.key
{String} auto-update requires a licesen key from 51Degreesoptions.interval
{Integer}, default value 30 * 60 * 1000 (half hours)options.onupdated
{Function} if auto updated, you will get call at this function
for more information, you could move to 51degrees documentation
parser.parse(userAgent)
userAgent
{String}
parse the userAgent
given by you, and return result of that.
Usage
var Parser = require('51degrees').Parser;
var psr = new Parser('51Degrees-Lite.dat');
var userAgent = '...'; // your userAgent in any clients(browser/ios/android)
var ret = psr.parse(userAgent);
console.log(ret);
Create an auto-updated pattern parser
var psr = new Parser('51Degrees-Lite.dat', [], {
autoUpdate: true,
key: 'your license key'
});
Note: this feature only is used at pattern data.
After the above program, you will get:
{ Id: '17595-21721-21635-18092',
Canvas: true,
CssTransforms: true,
CssTransitions: true,
History: true,
Html5: true,
IndexedDB: true,
IsMobile: false,
Json: true,
PostMessage: true,
Svg: true,
TouchEvents: true,
WebWorkers: true,
method: 'trie',
data: {} }
.ALL_PROPERTIES
51Degrees.node
exposure ALL_PROPERTIES
to shortly fetch all propertites from userAgent
, just using like this:
var properties = require('51degrees').ALL_PROPERTIES;
var userAgent = '...' // your userAgent in any clients(browser/ios/android)
var psr = new Parser('51Degrees-Lite.trie', properties);
var ret = psr.parse(userAgent);
console.log(ret);
Then will print the whole properties, it's super useful for overview of this module and 51Degrees product.
Properties
The following list shows all properties that 51degrees would export in json:
AnimationTiming
BlobBuilder
Canvas
CssBackground
CssBorderImage
CssCanvas
CssColor
CssColumn
CssFlexbox
CssFont
CssImages
CssMediaQueries
CssMinMax
CssOverflow
CssPosition
CssText
CssTransforms
CssTransitions
CssUI
DataSet
DataUrl
DeviceOrientation
FileReader
FileSaver
FileWriter
FormData
Fullscreen
GeoLocation
History
Html5
Html-Media-Capture
Id
Iframe
IndexedDB
IsMobile
Json
LayoutEngine
Masking
PostMessage
Progress
Prompts
ScreenPixelsHeight
ScreenPixelsWidth
Selector
Svg
TouchEvents
Track
Video
Viewport
WebWorkers
Xhr
Installation
$ npm install 51degrees --save