PageSourceSearch

https://bpazar.com/Scripts/knockout.quickmap.js

js bpazar.com collected 2026-10-08 20:12:19 UTC 2,136 bytes, 62 lines download raw bytes

1/// Knockout QuickMap plugin v1.0.0
2/// (c) 2015-2022 CubeCoders Limited - http://cubecoders.com
3/// License: MIT (http://www.opensource.org/licenses/mit-license.php)
4
5(function (factory) {
6	// Module systems magic dance.
7
8	if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
9		// CommonJS or Node: hard-coded dependency on "knockout"
10		factory(require("knockout"), exports);
11	} else if (typeof define === "function" && define["amd"]) {
12		// AMD anonymous module with hard-coded dependency on "knockout"
13		define(["knockout", "exports"], factory);
14	} else {
15		// <script> tag: use the global `ko` object, attaching a `quickmap` property
16		factory(ko, ko.quickmap = {});
17	}
18}(function (ko, exports) {
19	function mapObject(vm, data)
20    {
21        if (data === null || data === undefined) { return; }
22
23        const vmKeys = Object.keys(vm);
24        for (const key of Object.keys(data)) {
25            let value = data[key];
26
27            if (/^\/Date\((\d+)\)\/$/.test(value)) {
28                value = parseDate(value);
29            }
30
31            if (typeof vm[key] === "function") {
32                vm[key](value);
33            }
34            else if (typeof vm[key] !== "undefined" || vmKeys.contains(key)) {
35                vm[key] = value;
36            }
37        }
38    }
39
40    exports.map = mapObject;
41
42    exports.to = function (fn, data, asObservable, perObject) {
43        if (data === null) { return null; }
44        if (data === undefined) { throw new Error("Tried to map an undefined object."); }
45        if (data.constructor === Array) {
46            const result = asObservable ? ko.observableArray() : [];
47            for (const el of data) {
48                const newObj = new fn();
49                mapObject(newObj, el);
50                mapObject(newObj, perObject);
51                result.push(newObj);
52            }
53            return result;
54        }
55        else {
56            const obj = new fn();
57            mapObject(obj, data);
58            mapObject(obj, perObject);
59            return obj;
60        }
61    };
62}));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.