PageSourceSearch

https://yarwiki.ru/js/libs/libs-4.1.js

js yarwiki.ru collected 2026-10-02 10:33:49 UTC 3,230 bytes, 111 lines download raw bytes

1// Number.prototype ------------------------------------------------------------
2
3/**
4 * @example 100500.format(2, 3, ' ', ',') => 100 500,00
5 */
6Number.prototype.format = function (n, x, s, c) {
7	var re = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\D' : '$') + ')';
8	var num = this.toFixed(Math.max(0, ~~n));
9	return (c ? num.replace('.', c) : num).replace(new RegExp(re, 'g'), '$&' + (s || ','));
10};
11
12// String.prototype ------------------------------------------------------------
13
14String.prototype.firstCharsOfWordsToLower = function () {
15	var result = [];
16	var words = this.split(' ');
17	for (var i in words) {
18		result.push(words[i].firstCharToLower());
19	}
20	return result.join(' ');
21};
22
23String.prototype.firstCharsOfWordsToUpper = function () {
24	var result = [];
25	var words = this.split(' ');
26	for (var i in words) {
27		result.push(words[i].firstCharToUpper());
28	}
29	return result.join(' ');
30};
31
32String.prototype.firstCharToLower = function () {
33	return this.length ? this.charAt(0).toLowerCase() + this.slice(1) : this;
34};
35
36String.prototype.firstCharToUpper = function () {
37	return this.length ? this.charAt(0).toUpperCase() + this.slice(1) : this;
38};
39
40String.prototype.trim = function () {
41	return this.replace(/^\s+/, '').replace(/\s+$/, '');
42};
43
44// -----------------------------------------------------------------------------
45
46function extendClass(ChildClass, ParentClass) {
47	var F = function () {
48	};
49	F.prototype = ParentClass.prototype;
50	ChildClass.prototype = new F();
51	ChildClass.prototype.constructor = ChildClass;
52	ChildClass.superclass = ParentClass.prototype;
53	return true;
54}
55
56function mixinObjects(targetObject, sourceObject) {
57	var tempObject = {};
58	for (var i in sourceObject) {
59		if ((typeof tempObject[i] === 'undefined') || (tempObject[i] !== sourceObject[i])) {
60			targetObject[i] = sourceObject[i];
61		}
62	}
63	if (document.all && !document.isOpera) {
64		var f = sourceObject.toString;
65		if ((typeof f === 'function') && (f !== targetObject.toString) && (f !== tempObject.toString)) {
66			targetObject.toString = sourceObject.toString;
67		}
68	}
69}
70
71// -----------------------------------------------------------------------------
72
73$.replaceParamsInString = function (string, params) {
74	if (arguments.length === 1) {
75		return function () {
76			var args = $.makeArray(arguments);
77			args.unshift(string);
78			return $.replaceParamsInString.apply(this, args);
79		};
80	}
81	if ((arguments.length > 2) && (params.constructor !== Array)) {
82		params = $.makeArray(arguments).slice(1);
83	}
84	if (params.constructor !== Array) {
85		params = [params];
86	}
87	$.each(params, function (i, n) {
88		string = string.replace(new RegExp('\\{' + i + '\\}', 'g'), n);
89	});
90	return string;
91};
92
93$.unserialize = function (serializedString) {
94	var string = decodeURI(serializedString);
95	var pairs = string.split('&');
96	var object = {};
97	for (var i = 0, n = pairs.length; i < n; i++) {
98		var pair = pairs[i].split('=');
99		var index = pair[0];
100		if ((index.indexOf('[]') !== -1) && (index.indexOf('[]') === (index.length - 2))) {
101			var _index = index.substring(0, index.length - 2)
102			if (object[_index] === undefined) {
103				object[_index] = [];
104			}
105			object[_index].push(pair[1]);
106		} else {
107			object[index] = pair[1];
108		}
109	}
110	return object;
111};

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.