melanite is a Node.js module that converts a user-agent string to a normalised device. It is used by the 成人快手 to determine the type of device that is accessing its services.
InstallationCopy heading link to clipboard
npm install --save melanite
Getting startedCopy heading link to clipboard
In order to use melanite
, you need to provide one or more
"matchers"; a matcher represents a device you wish to identify. Below
is an example matcher that could be used to identify a Microsoft Xbox
One device:
Let's take a look at each component of a matcher (all of which are mandatory).
brand
Copy heading link to clipboard
The brand of the device; it serves no purpose for identification and is merely a friendly name for a group of several different devices (e.g. by manufacturer)
model
Copy heading link to clipboard
The model of the device; like brand
, it serves no purpose for
identification and is instead a friendly name for a specific device.
invariants
Copy heading link to clipboard
invariants
is an array of strings (each of these is referred to as
an invariant); in order for a user agent to be matched to this
matcher, it must contain every invariant (similar to an allowlist).
disallowed
Copy heading link to clipboard
disallowed
is an array of strings, it is in the opposite of
invariants
. In order for a user agent to be matched to this matcher,
it must not contain any of these strings (similar to a denylist).
In the above example, we haven't specified any disallowed items. The
disallowed
property is most useful when you have two or more
matchers that are very similar to each other.
fuzzy
Copy heading link to clipboard
fuzzy
can be thought of as an example user agent. When a group of
matchers have been filtered using invariants
and disallowed
,
melanite
calculates the
between the fuzzy
and the user-agent - the matcher with the lowest
Levenshtein distance is the one returned by melanite
.
type
Copy heading link to clipboard
The type of the device; like brand
and model
, it serves no purpose
for identification.
Identifying devicesCopy heading link to clipboard
Now that we have a matcher, let's use it to identify some user agents:
For a further example, please see .
Snapshot dataCopy heading link to clipboard
We have provided a snasphot of the 成人快手's devices in production in the , if you wish to use these matchers your self.