-
Notifications
You must be signed in to change notification settings - Fork 0
/
ksp.js
51 lines (46 loc) · 1.51 KB
/
ksp.js
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
41
42
43
44
45
46
47
48
49
50
51
/* -*- coding: UTF-8, tab-width: 2 -*- */
/*jslint indent: 2, maxlen: 80, browser: true */
/*globals define:true*/
(function () {
'use strict';
var EX, objHas = Object.prototype.hasOwnProperty;
function getOwn(o, k, d) { return (objHas.call(o, k) ? o[k] : d); }
EX = function dictLookupKeySuffixParts(dict, parts, opts) {
if (!dict) { return false; }
opts = (opts || false);
var nPartsTotal = parts.length, skip, partsUsed,
glue = (opts.glue || ''),
kPfx = (opts.keyPrefix || ''),
kSuf = (opts.keySuffix || ''),
dKeys = Object.keys(dict), nKeys = dKeys.length,
key, val;
if (nKeys === 0) { return false; }
if (nKeys === 1) {
key = kPfx + kSuf;
if (dKeys[0] === key) {
val = dict[key];
if (val !== undefined) {
return { key: key, val: val, partsUsed: [],
nUsed: 0, nSkip: nPartsTotal };
}
}
}
for (skip = 0; skip <= nPartsTotal; skip += 1) {
partsUsed = parts.slice(skip);
key = kPfx + partsUsed.join(glue) + kSuf;
val = getOwn(dict, key);
if (val !== undefined) {
return { key: key, val: val, partsUsed: partsUsed,
nUsed: partsUsed.length, nSkip: skip };
}
}
return false;
};
(function (e) { // UMD export
/*global define: true */
var d = ((typeof define === 'function') && define),
m = ((typeof module === 'object') && module);
if (d && d.amd) { d(function () { return e; }); }
if (m && m.exports) { m.exports = e; }
}(EX));
}());