cavalion-js 1.0.63 → 1.0.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ### 2021/12/17 - 1.0.66
2
+
3
+ - Enhancing `locale`, now supporting references with the ::-prefix
4
+
5
+ ### 2021/10/09 - 1.0.65
6
+
7
+ - Now supporting the following patterns:
8
+
9
+ > var locale = require("locale").prefixed(["Onderzoek"], { ... });
10
+ > var locale = require("locale").prefixed("Onderzoek");
11
+
12
+ Not sure what todo with the default yet.
13
+
14
+ ### 2021/09/18 - 1.0.64
15
+
16
+ - Introducing `String.decamelize = String.decamelcase`
17
+
1
18
  ### 2021/06/21 - 1.0.63
2
19
  - Introducing `js.groupBy()`
3
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cavalion-js",
3
- "version": "1.0.63",
3
+ "version": "1.0.66",
4
4
  "description": "Cavalion common JavaScript library",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/js/_js.js CHANGED
@@ -38,7 +38,9 @@ define(function(require) {
38
38
  nameOf: nameOf,
39
39
  defineClass: defineClass,
40
40
  mixIn: mixIn,
41
- groupBy: (arr, key) => arr.reduce((a, o) => ((a[o[key]] || (a[o[key]] = [])).push(o), a), {}),
41
+ groupBy: (arr, key) => {
42
+ return arr.reduce((a, o) => ((a[js.get(key, o)] || (a[js.get(key, o)] = [])).push(o), a), {});
43
+ },
42
44
  ctx: function(obj, defaults) {
43
45
  return obj.hasOwnProperty(js_ctx_key) ? obj[js_ctx_key] : obj[js_ctx_key] = (obj[js_ctx_key] || defaults || {});
44
46
  },
@@ -9,6 +9,7 @@ define(function(require) {
9
9
  var inh = ctx.completeLoad;
10
10
  ctx.modulesLoaded = [];
11
11
  ctx.completeLoad = function(moduleName) {
12
+ // console.log(moduleName);
12
13
  ctx.modulesLoaded.push(moduleName);
13
14
  //console.log(moduleName);
14
15
  return inh.apply(this, arguments);
@@ -128,6 +129,21 @@ define(function(require) {
128
129
  */
129
130
  return str.substring(0, 1).toUpperCase() + str.substring(1);
130
131
  };
132
+ String.decamelize = String.decamelcase = function(s) {
133
+ var r = s.charAt(0), i = 0, ch = r;
134
+ while(++i < s.length) {
135
+ if(ch === undefined || ((ch < 'A' || ch > 'Z') || (ch < '0' && ch > '9'))) {
136
+ ch = s.charAt(i);
137
+ if((ch >= 'A' && ch <= 'Z')) {// || (ch >= '0' && ch <= '9')) {
138
+ r += " ";
139
+ }
140
+ } else {
141
+ ch = s.charAt(i);
142
+ }
143
+ r += ch;
144
+ }
145
+ return r.toLowerCase();
146
+ };
131
147
  String.escape = function (s) {
132
148
  /**
133
149
  *
package/src/locale.js CHANGED
@@ -86,6 +86,20 @@ try {
86
86
 
87
87
  /*- TODO Still not found, split by / delimiter and replace by star and try again */
88
88
 
89
+ /* FR: reference other locale with double colon */
90
+ if(typeof r === "string") {
91
+ if(r.charAt(0) === "\\") {
92
+ r = r.substring(1);
93
+ }
94
+ if(r.charAt(0) === ":" && r.charAt(1) === ":") {
95
+ try {
96
+ r = locale(r.substring(2));
97
+ } catch(e) {
98
+ r = "{" + r + "}: " + e.message;
99
+ }
100
+ }
101
+ }
102
+
89
103
  return r;
90
104
  } finally {
91
105
  if(began) {
@@ -133,7 +147,15 @@ try {
133
147
 
134
148
  return r;
135
149
  };
136
- locale.prefixed = function(prefix) {
150
+ locale.prefixed = function(prefix/*, defaults */) {
151
+ if(prefix instanceof Array) {
152
+ prefix = prefix[0];
153
+ }
154
+
155
+ if(arguments.length > 1) {
156
+ locale.define(prefix, arguments[1]);
157
+ }
158
+
137
159
  return function(id/*, ... */) {
138
160
  if(arguments.length === 0) {
139
161
  return prefix;
@@ -144,6 +166,18 @@ try {
144
166
  return locale.apply(this, args);
145
167
  };
146
168
  };
169
+ locale.define = function(prefix, defaults) {
170
+ for(var loc in defaults) {
171
+ var L = {}; L[prefix] = defaults[loc];
172
+
173
+ // console.log(1, locale[loc], L);
174
+
175
+ locale[loc] = locale[loc] || {};
176
+ js.mixIn(locale[loc], js.obj2kvp(L));
177
+
178
+ // console.log(2, locale[loc], L);
179
+ }
180
+ };
147
181
 
148
182
  if(typeof window !== "undefined" && typeof window.location !== "undefined") {
149
183
  locale.loc = (location.search.split('locale=')[1]||'').split('&')[0];
@@ -158,7 +192,7 @@ try {
158
192
  }
159
193
 
160
194
  function unwrap(dict, v) {
161
- /* unwrap arrays */
195
+ /* unwrap arrays */ // TODO why?
162
196
  for(var k in dict) {
163
197
  if(((v = dict[k]) instanceof Array)) {
164
198
  dict[k] = v[0];
@@ -169,6 +203,8 @@ try {
169
203
 
170
204
  return {
171
205
  locale: locale,
206
+
207
+ prefixed: locale.prefixed,
172
208
  module: function(module) {
173
209
  return function() {
174
210
  var args = js.copy_args(arguments);
@@ -194,8 +230,10 @@ try {
194
230
  dict = unwrap(js.mixIn(js.obj2kvp(proto || {}), js.obj2kvp(dict)));
195
231
 
196
232
  js.mixIn(locale[name], dict);
233
+
197
234
  onLoad(dict);
198
235
  });
199
- }
236
+ },
237
+ define: locale.define
200
238
  };
201
239
  });