PageSourceSearch

https://correspondant.lamanchelibre.fr/wpublic/js/language/language.js?20260922084155

js lamanchelibre.fr collected 2026-09-24 20:37:45 UTC 6,198 bytes, 189 lines download raw bytes

1function i18n () { //sprintf
2  // http://kevin.vanzonneveld.net
3  // +   original by: Ash Searle (http://hexmen.com/blog/)
4  // + namespaced by: Michael White (http://getsprink.com)
5  // +    tweaked by: Jack
6  // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
7  // +      input by: Paulo Freitas
8  // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
9  // +      input by: Brett Zamir (http://brett-zamir.me)
10  // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
11  // +   improved by: Dj
12  // *     example 1: sprintf("%01.2f", 123.1);
13  // *     returns 1: 123.10
14  // *     example 2: sprintf("[%10s]", 'monkey');
15  // *     returns 2: '[    monkey]'
16  // *     example 3: sprintf("[%'#10s]", 'monkey');
17  // *     returns 3: '[####monkey]'
18  var regex = /%%|%(\d+\$)?([-+\'#0 ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([scboxXuideEfFgG])/g;
19  var a = arguments,
20    i = 0,
21    format = a[i++];
22
23  // pad()
24  var pad = function (str, len, chr, leftJustify) {
25    if (!chr) {
26      chr = ' ';
27    }
28    var padding = (str.length >= len) ? '' : Array(1 + len - str.length >>> 0).join(chr);
29    return leftJustify ? str + padding : padding + str;
30  };
31
32  // justify()
33  var justify = function (value, prefix, leftJustify, minWidth, zeroPad, customPadChar) {
34    var diff = minWidth - value.length;
35    if (diff > 0) {
36      if (leftJustify || !zeroPad) {
37        value = pad(value, minWidth, customPadChar, leftJustify);
38      } else {
39        value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length);
40      }
41    }
42    return value;
43  };
44
45  // formatBaseX()
46  var formatBaseX = function (value, base, prefix, leftJustify, minWidth, precision, zeroPad) {
47    // Note: casts negative numbers to positive ones
48    var number = value >>> 0;
49    prefix = prefix && number && {
50      '2': '0b',
51      '8': '0',
52      '16': '0x'
53    }[base] || '';
54    value = prefix + pad(number.toString(base), precision || 0, '0', false);
55    return justify(value, prefix, leftJustify, minWidth, zeroPad);
56  };
57
58  // formatString()
59  var formatString = function (value, leftJustify, minWidth, precision, zeroPad, customPadChar) {
60    if (precision != null) {
61      value = value.slice(0, precision);
62    }
63    return justify(value, '', leftJustify, minWidth, zeroPad, customPadChar);
64  };
65
66  // doFormat()
67  var doFormat = function (substring, valueIndex, flags, minWidth, _, precision, type) {
68    var number;
69    var prefix;
70    var method;
71    var textTransform;
72    var value;
73
74    if (substring == '%%') {
75      return '%';
76    }
77
78    // parse flags
79    var leftJustify = false,
80      positivePrefix = '',
81      zeroPad = false,
82      prefixBaseX = false,
83      customPadChar = ' ';
84    var flagsl = flags.length;
85    for (var j = 0; flags && j < flagsl; j++) {
86      switch (flags.charAt(j)) {
87      case ' ':
88        positivePrefix = ' ';
89        break;
90      case '+':
91        positivePrefix = '+';
92        break;
93      case '-':
94        leftJustify = true;
95        break;
96      case "'":
97        customPadChar = flags.charAt(j + 1);
98        break;
99      case '0':
100        zeroPad = true;
101        break;
102      case '#':
103        prefixBaseX = true;
104        break;
105      }
106    }
107
108    // parameters may be null, undefined, empty-string or real valued
109    // we want to ignore null, undefined and empty-string values
110    if (!minWidth) {
111      minWidth = 0;
112    } else if (minWidth == '*') {
113      minWidth = +a[i++];
114    } else if (minWidth.charAt(0) == '*') {
115      minWidth = +a[minWidth.slice(1, -1)];
116    } else {
117      minWidth = +minWidth;
118    }
119
120    // Note: undocumented perl feature:
121    if (minWidth < 0) {
122      minWidth = -minWidth;
123      leftJustify = true;
124    }
125
126    if (!isFinite(minWidth)) {
127      throw new Error('sprintf: (minimum-)width must be finite');
128    }
129
130    if (!precision) {
131      precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type == 'd') ? 0 : undefined;
132    } else if (precision == '*') {
133      precision = +a[i++];
134    } else if (precision.charAt(0) == '*') {
135      precision = +a[precision.slice(1, -1)];
136    } else {
137      precision = +precision;
138    }
139
140    // grab value using valueIndex if required?
141    value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++];
142
143    switch (type) {
144    case 's':
145      return formatString(String(value), leftJustify, minWidth, precision, zeroPad, customPadChar);
146    case 'c':
147      return formatString(String.fromCharCode(+value), leftJustify, minWidth, precision, zeroPad);
148    case 'b':
149      return formatBaseX(value, 2, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
150    case 'o':
151      return formatBaseX(value, 8, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
152    case 'x':
153      return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
154    case 'X':
155      return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad).toUpperCase();
156    case 'u':
157      return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
158    case 'i':
159    case 'd':
160      number = (+value) | 0;
161      prefix = number < 0 ? '-' : positivePrefix;
162      value = prefix + pad(String(Math.abs(number)), precision, '0', false);
163      return justify(value, prefix, leftJustify, minWidth, zeroPad);
164    case 'e':
165    case 'E':
166    case 'f': // Should handle locales (as per setlocale)
167    case 'F':
168    case 'g':
169    case 'G':
170      number = +value;
171      prefix = number < 0 ? '-' : positivePrefix;
172      method = ['toExponential', 'toFixed', 'toPrecision']['efg'.indexOf(type.toLowerCase())];
173      textTransform = ['toString', 'toUpperCase']['eEfFgG'.indexOf(type) % 2];
174      value = prefix + Math.abs(number)[method](precision);
175      return justify(value, prefix, leftJustify, minWidth, zeroPad)[textTransform]();
176    default:
177      return substring;
178    }
179  };
180
181/*******************************************************************************/
182/*if (js_translations.hasOwnProperty(format)) {
183    format = js_translations[format];
184}*/
185/*******************************************************************************/
186
187
188  return format.replace(regex, doFormat);
189}

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.