/usr/lib/nodejs/unicode-loose-match/index.js is in node-unicode-loose-match 2.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 'use strict';
const mappings = require('./data/mappings.js');
const aliasToProperty = mappings.aliasToProperty;
const propertyToValueAliases = mappings.propertyToValueAliases;
const normalize = function(string) {
const normalized = string
// Remove case distinctions.
.toLowerCase()
// Remove whitespace.
.replace(/\s/g, '')
// Remove `-` and `_`.
.replace(/[-_]/g, '');
return normalized;
};
const matchLoosely = function(property, value) {
const normalizedProperty = normalize(property);
const canonicalProperty = aliasToProperty.get(normalizedProperty);
if (!canonicalProperty) {
throw new Error(`Unknown property: ${ property }`);
}
const aliasToValue = propertyToValueAliases.get(
canonicalProperty == 'Script_Extensions' ? 'Script' : canonicalProperty
);
const result = {
'property': canonicalProperty
};
if (value) {
const normalizedValue = normalize(value);
const canonicalValue = aliasToValue.get(normalizedValue);
if (canonicalValue) {
result.value = canonicalValue;
}
}
return result;
};
module.exports = matchLoosely;
|