ilib-tools-common 1.0.0

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.
Files changed (49) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +30 -0
  3. package/docs/Resource.html +3645 -0
  4. package/docs/Resource.js.html +522 -0
  5. package/docs/ResourceArray.html +5960 -0
  6. package/docs/ResourceArray.js.html +447 -0
  7. package/docs/ResourcePlural.html +6094 -0
  8. package/docs/ResourcePlural.js.html +424 -0
  9. package/docs/ResourceString.html +5532 -0
  10. package/docs/ResourceString.js.html +295 -0
  11. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  12. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  13. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  14. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  15. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  16. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  17. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  18. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  19. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  20. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  21. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  22. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  23. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  24. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  25. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  26. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  27. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  28. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  29. package/docs/global.html +311 -0
  30. package/docs/ilibToolsCommon.md +0 -0
  31. package/docs/index.html +81 -0
  32. package/docs/scripts/collapse.js +20 -0
  33. package/docs/scripts/linenumber.js +25 -0
  34. package/docs/scripts/nav.js +12 -0
  35. package/docs/scripts/polyfill.js +4 -0
  36. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  37. package/docs/scripts/prettify/lang-css.js +2 -0
  38. package/docs/scripts/prettify/prettify.js +28 -0
  39. package/docs/scripts/search.js +83 -0
  40. package/docs/styles/jsdoc.css +765 -0
  41. package/docs/styles/prettify.css +79 -0
  42. package/docs/utils.js.html +113 -0
  43. package/package.json +77 -0
  44. package/src/Resource.js +453 -0
  45. package/src/ResourceArray.js +378 -0
  46. package/src/ResourcePlural.js +355 -0
  47. package/src/ResourceString.js +226 -0
  48. package/src/index.js +25 -0
  49. package/src/utils.js +44 -0
@@ -0,0 +1,424 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+
5
+ <meta charset="utf-8">
6
+ <title>ResourcePlural.js - Documentation</title>
7
+
8
+
9
+ <script src="scripts/prettify/prettify.js"></script>
10
+ <script src="scripts/prettify/lang-css.js"></script>
11
+ <!--[if lt IE 9]>
12
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
13
+ <![endif]-->
14
+ <link type="text/css" rel="stylesheet" href="styles/prettify.css">
15
+ <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
16
+ <script src="scripts/nav.js" defer></script>
17
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
18
+ </head>
19
+ <body>
20
+
21
+ <input type="checkbox" id="nav-trigger" class="nav-trigger" />
22
+ <label for="nav-trigger" class="navicon-button x">
23
+ <div class="navicon"></div>
24
+ </label>
25
+
26
+ <label for="nav-trigger" class="overlay"></label>
27
+
28
+ <nav >
29
+
30
+ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Resource.html">Resource</a><ul class='methods'><li data-type='method'><a href="Resource.html#addInstance">addInstance</a></li><li data-type='method'><a href="Resource.html#escapeText">escapeText</a></li><li data-type='method'><a href="Resource.html#getAutoKey">getAutoKey</a></li><li data-type='method'><a href="Resource.html#getComment">getComment</a></li><li data-type='method'><a href="Resource.html#getContext">getContext</a></li><li data-type='method'><a href="Resource.html#getDataType">getDataType</a></li><li data-type='method'><a href="Resource.html#getFlavor">getFlavor</a></li><li data-type='method'><a href="Resource.html#getId">getId</a></li><li data-type='method'><a href="Resource.html#getInstances">getInstances</a></li><li data-type='method'><a href="Resource.html#getKey">getKey</a></li><li data-type='method'><a href="Resource.html#getLocalize">getLocalize</a></li><li data-type='method'><a href="Resource.html#getOrigin">getOrigin</a></li><li data-type='method'><a href="Resource.html#getPath">getPath</a></li><li data-type='method'><a href="Resource.html#getProject">getProject</a></li><li data-type='method'><a href="Resource.html#getSource">getSource</a></li><li data-type='method'><a href="Resource.html#getSourceLocale">getSourceLocale</a></li><li data-type='method'><a href="Resource.html#getState">getState</a></li><li data-type='method'><a href="Resource.html#getTarget">getTarget</a></li><li data-type='method'><a href="Resource.html#getTargetLocale">getTargetLocale</a></li><li data-type='method'><a href="Resource.html#getType">getType</a></li><li data-type='method'><a href="Resource.html#isInstance">isInstance</a></li><li data-type='method'><a href="Resource.html#same">same</a></li><li data-type='method'><a href="Resource.html#setComment">setComment</a></li><li data-type='method'><a href="Resource.html#setProject">setProject</a></li><li data-type='method'><a href="Resource.html#setSourceLocale">setSourceLocale</a></li><li data-type='method'><a href="Resource.html#setState">setState</a></li><li data-type='method'><a href="Resource.html#setTargetLocale">setTargetLocale</a></li></ul></li><li><a href="ResourceArray.html">ResourceArray</a><ul class='methods'><li data-type='method'><a href="ResourceArray.html#.hashKey">hashKey</a></li><li data-type='method'><a href="ResourceArray.html#addInstance">addInstance</a></li><li data-type='method'><a href="ResourceArray.html#addSource">addSource</a></li><li data-type='method'><a href="ResourceArray.html#addTarget">addTarget</a></li><li data-type='method'><a href="ResourceArray.html#cleanHashKey">cleanHashKey</a></li><li data-type='method'><a href="ResourceArray.html#cleanHashKeyForTranslation">cleanHashKeyForTranslation</a></li><li data-type='method'><a href="ResourceArray.html#clone">clone</a></li><li data-type='method'><a href="ResourceArray.html#equals">equals</a></li><li data-type='method'><a href="ResourceArray.html#equals">equals</a></li><li data-type='method'><a href="ResourceArray.html#escapeText">escapeText</a></li><li data-type='method'><a href="ResourceArray.html#getAutoKey">getAutoKey</a></li><li data-type='method'><a href="ResourceArray.html#getComment">getComment</a></li><li data-type='method'><a href="ResourceArray.html#getContext">getContext</a></li><li data-type='method'><a href="ResourceArray.html#getDataType">getDataType</a></li><li data-type='method'><a href="ResourceArray.html#getFlavor">getFlavor</a></li><li data-type='method'><a href="ResourceArray.html#getId">getId</a></li><li data-type='method'><a href="ResourceArray.html#getInstances">getInstances</a></li><li data-type='method'><a href="ResourceArray.html#getKey">getKey</a></li><li data-type='method'><a href="ResourceArray.html#getLocalize">getLocalize</a></li><li data-type='method'><a href="ResourceArray.html#getOrigin">getOrigin</a></li><li data-type='method'><a href="ResourceArray.html#getPath">getPath</a></li><li data-type='method'><a href="ResourceArray.html#getProject">getProject</a></li><li data-type='method'><a href="ResourceArray.html#getSource">getSource</a></li><li data-type='method'><a href="ResourceArray.html#getSourceItem">getSourceItem</a></li><li data-type='method'><a href="ResourceArray.html#getSourceLocale">getSourceLocale</a></li><li data-type='method'><a href="ResourceArray.html#getState">getState</a></li><li data-type='method'><a href="ResourceArray.html#getTarget">getTarget</a></li><li data-type='method'><a href="ResourceArray.html#getTargetItem">getTargetItem</a></li><li data-type='method'><a href="ResourceArray.html#getTargetLocale">getTargetLocale</a></li><li data-type='method'><a href="ResourceArray.html#getType">getType</a></li><li data-type='method'><a href="ResourceArray.html#hashKey">hashKey</a></li><li data-type='method'><a href="ResourceArray.html#hashKeyForTranslation">hashKeyForTranslation</a></li><li data-type='method'><a href="ResourceArray.html#isInstance">isInstance</a></li><li data-type='method'><a href="ResourceArray.html#same">same</a></li><li data-type='method'><a href="ResourceArray.html#setComment">setComment</a></li><li data-type='method'><a href="ResourceArray.html#setProject">setProject</a></li><li data-type='method'><a href="ResourceArray.html#setSource">setSource</a></li><li data-type='method'><a href="ResourceArray.html#setSourceLocale">setSourceLocale</a></li><li data-type='method'><a href="ResourceArray.html#setState">setState</a></li><li data-type='method'><a href="ResourceArray.html#setTarget">setTarget</a></li><li data-type='method'><a href="ResourceArray.html#setTargetLocale">setTargetLocale</a></li><li data-type='method'><a href="ResourceArray.html#size">size</a></li></ul></li><li><a href="ResourcePlural.html">ResourcePlural</a><ul class='methods'><li data-type='method'><a href="ResourcePlural.html#.hashKey">hashKey</a></li><li data-type='method'><a href="ResourcePlural.html#addInstance">addInstance</a></li><li data-type='method'><a href="ResourcePlural.html#addSourcePlural">addSourcePlural</a></li><li data-type='method'><a href="ResourcePlural.html#addTargetPlural">addTargetPlural</a></li><li data-type='method'><a href="ResourcePlural.html#cleanHashKey">cleanHashKey</a></li><li data-type='method'><a href="ResourcePlural.html#cleanHashKeyForTranslation">cleanHashKeyForTranslation</a></li><li data-type='method'><a href="ResourcePlural.html#clone">clone</a></li><li data-type='method'><a href="ResourcePlural.html#equals">equals</a></li><li data-type='method'><a href="ResourcePlural.html#escapeText">escapeText</a></li><li data-type='method'><a href="ResourcePlural.html#getAllValidCategories">getAllValidCategories</a></li><li data-type='method'><a href="ResourcePlural.html#getAutoKey">getAutoKey</a></li><li data-type='method'><a href="ResourcePlural.html#getCategories">getCategories</a></li><li data-type='method'><a href="ResourcePlural.html#getClasses">getClasses</a></li><li data-type='method'><a href="ResourcePlural.html#getComment">getComment</a></li><li data-type='method'><a href="ResourcePlural.html#getContext">getContext</a></li><li data-type='method'><a href="ResourcePlural.html#getDataType">getDataType</a></li><li data-type='method'><a href="ResourcePlural.html#getFlavor">getFlavor</a></li><li data-type='method'><a href="ResourcePlural.html#getId">getId</a></li><li data-type='method'><a href="ResourcePlural.html#getInstances">getInstances</a></li><li data-type='method'><a href="ResourcePlural.html#getKey">getKey</a></li><li data-type='method'><a href="ResourcePlural.html#getLocalize">getLocalize</a></li><li data-type='method'><a href="ResourcePlural.html#getOrigin">getOrigin</a></li><li data-type='method'><a href="ResourcePlural.html#getPath">getPath</a></li><li data-type='method'><a href="ResourcePlural.html#getProject">getProject</a></li><li data-type='method'><a href="ResourcePlural.html#getSource">getSource</a></li><li data-type='method'><a href="ResourcePlural.html#getSourceLocale">getSourceLocale</a></li><li data-type='method'><a href="ResourcePlural.html#getSourcePlural">getSourcePlural</a></li><li data-type='method'><a href="ResourcePlural.html#getState">getState</a></li><li data-type='method'><a href="ResourcePlural.html#getTarget">getTarget</a></li><li data-type='method'><a href="ResourcePlural.html#getTargetLocale">getTargetLocale</a></li><li data-type='method'><a href="ResourcePlural.html#getTargetPlural">getTargetPlural</a></li><li data-type='method'><a href="ResourcePlural.html#getType">getType</a></li><li data-type='method'><a href="ResourcePlural.html#hashKey">hashKey</a></li><li data-type='method'><a href="ResourcePlural.html#hashKeyForTranslation">hashKeyForTranslation</a></li><li data-type='method'><a href="ResourcePlural.html#isInstance">isInstance</a></li><li data-type='method'><a href="ResourcePlural.html#same">same</a></li><li data-type='method'><a href="ResourcePlural.html#setComment">setComment</a></li><li data-type='method'><a href="ResourcePlural.html#setProject">setProject</a></li><li data-type='method'><a href="ResourcePlural.html#setSource">setSource</a></li><li data-type='method'><a href="ResourcePlural.html#setSourceLocale">setSourceLocale</a></li><li data-type='method'><a href="ResourcePlural.html#setState">setState</a></li><li data-type='method'><a href="ResourcePlural.html#setTarget">setTarget</a></li><li data-type='method'><a href="ResourcePlural.html#setTargetLocale">setTargetLocale</a></li><li data-type='method'><a href="ResourcePlural.html#size">size</a></li></ul></li><li><a href="ResourceString.html">ResourceString</a><ul class='methods'><li data-type='method'><a href="ResourceString.html#.cleanHashKey">cleanHashKey</a></li><li data-type='method'><a href="ResourceString.html#.hashKey">hashKey</a></li><li data-type='method'><a href="ResourceString.html#addInstance">addInstance</a></li><li data-type='method'><a href="ResourceString.html#cleanHashKey">cleanHashKey</a></li><li data-type='method'><a href="ResourceString.html#cleanHashKeyForTranslation">cleanHashKeyForTranslation</a></li><li data-type='method'><a href="ResourceString.html#clone">clone</a></li><li data-type='method'><a href="ResourceString.html#equals">equals</a></li><li data-type='method'><a href="ResourceString.html#escapeText">escapeText</a></li><li data-type='method'><a href="ResourceString.html#getAutoKey">getAutoKey</a></li><li data-type='method'><a href="ResourceString.html#getComment">getComment</a></li><li data-type='method'><a href="ResourceString.html#getContext">getContext</a></li><li data-type='method'><a href="ResourceString.html#getDataType">getDataType</a></li><li data-type='method'><a href="ResourceString.html#getFlavor">getFlavor</a></li><li data-type='method'><a href="ResourceString.html#getId">getId</a></li><li data-type='method'><a href="ResourceString.html#getInstances">getInstances</a></li><li data-type='method'><a href="ResourceString.html#getKey">getKey</a></li><li data-type='method'><a href="ResourceString.html#getLocalize">getLocalize</a></li><li data-type='method'><a href="ResourceString.html#getOrigin">getOrigin</a></li><li data-type='method'><a href="ResourceString.html#getPath">getPath</a></li><li data-type='method'><a href="ResourceString.html#getProject">getProject</a></li><li data-type='method'><a href="ResourceString.html#getSource">getSource</a></li><li data-type='method'><a href="ResourceString.html#getSourceLocale">getSourceLocale</a></li><li data-type='method'><a href="ResourceString.html#getState">getState</a></li><li data-type='method'><a href="ResourceString.html#getTarget">getTarget</a></li><li data-type='method'><a href="ResourceString.html#getTargetLocale">getTargetLocale</a></li><li data-type='method'><a href="ResourceString.html#getType">getType</a></li><li data-type='method'><a href="ResourceString.html#hashKey">hashKey</a></li><li data-type='method'><a href="ResourceString.html#hashKeyForTranslation">hashKeyForTranslation</a></li><li data-type='method'><a href="ResourceString.html#isInstance">isInstance</a></li><li data-type='method'><a href="ResourceString.html#same">same</a></li><li data-type='method'><a href="ResourceString.html#setComment">setComment</a></li><li data-type='method'><a href="ResourceString.html#setProject">setProject</a></li><li data-type='method'><a href="ResourceString.html#setSource">setSource</a></li><li data-type='method'><a href="ResourceString.html#setSourceLocale">setSourceLocale</a></li><li data-type='method'><a href="ResourceString.html#setState">setState</a></li><li data-type='method'><a href="ResourceString.html#setTarget">setTarget</a></li><li data-type='method'><a href="ResourceString.html#setTargetLocale">setTargetLocale</a></li><li data-type='method'><a href="ResourceString.html#size">size</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#cleanString">cleanString</a></li></ul>
31
+ </nav>
32
+
33
+ <div id="main">
34
+
35
+ <h1 class="page-title">ResourcePlural.js</h1>
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ <section>
44
+ <article>
45
+ <pre class="prettyprint source linenums"><code>/*
46
+ * ResourcePlural.js - represents an array of plural strings in a resource file
47
+ *
48
+ * Copyright © 2022 JEDLSoft
49
+ *
50
+ * Licensed under the Apache License, Version 2.0 (the "License");
51
+ * you may not use this file except in compliance with the License.
52
+ * You may obtain a copy of the License at
53
+ *
54
+ * http://www.apache.org/licenses/LICENSE-2.0
55
+ *
56
+ * Unless required by applicable law or agreed to in writing, software
57
+ * distributed under the License is distributed on an "AS IS" BASIS,
58
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59
+ *
60
+ * See the License for the specific language governing permissions and
61
+ * limitations under the License.
62
+ */
63
+
64
+ import Resource from "./Resource.js";
65
+ import { cleanString } from "./utils.js";
66
+ import log4js from "@log4js-node/log4js-api";
67
+
68
+ const logger = log4js.getLogger("tools-common.ResourcePlural");
69
+
70
+ /**
71
+ * @class A class that models a resource that handles translations of
72
+ * plurals.
73
+ * @extends Resource
74
+ */
75
+ class ResourcePlural extends Resource {
76
+ /**
77
+ * Construct a new instance of a plural resource.
78
+ *
79
+ * Hashes of strings are used in Android apps to specify translations
80
+ * of the various categories of plurals.&lt;p>
81
+ *
82
+ * The props may contain any
83
+ * of properties from the Resource constructor and additionally,
84
+ * these properties:
85
+ *
86
+ * &lt;ul>
87
+ * &lt;li>&lt;i>source&lt;/i> {Object} A hash of strings that map the categories
88
+ * to translations.
89
+ * &lt;/ul>
90
+ *
91
+ * The properties of the strings hash can be any of the categories supported
92
+ * by the Unicode CLDR data:
93
+ *
94
+ * &lt;ul>
95
+ * &lt;li>zero
96
+ * &lt;li>one
97
+ * &lt;li>two
98
+ * &lt;li>few
99
+ * &lt;li>many
100
+ * &lt;/ul>
101
+ *
102
+ * @constructor
103
+ * @param {Object} props Any of the properties given above
104
+ */
105
+ constructor(props) {
106
+ super(props);
107
+
108
+ this.source = {};
109
+
110
+ // deep copy this so that the props can have a different set of
111
+ // plural forms than this instance
112
+ if (props) {
113
+ if (typeof(props.source) === 'object') {
114
+ for (let p in props.source) {
115
+ this.source[p] = props.source[p];
116
+ }
117
+ }
118
+
119
+ if (typeof(props.target) === 'object') {
120
+ this.target = {};
121
+ for (let p in props.target) {
122
+ this.target[p] = props.target[p];
123
+ }
124
+ }
125
+ }
126
+
127
+ this.datatype = this.datatype || "x-android-resource";
128
+ this.resType = ResourcePlural.resClass;
129
+ }
130
+
131
+ /**
132
+ * Set the source plurals hash of this plurals resource.
133
+ *
134
+ * @param {Object} plurals the source hash
135
+ */
136
+ setSource(plurals) {
137
+ if (typeof(plurals) !== 'object') return;
138
+ this.source = plurals;
139
+ }
140
+
141
+ /**
142
+ * Set the target plurals hash of this plurals resource.
143
+ *
144
+ * @param {Object} plurals the target hash
145
+ */
146
+ setTarget(plurals) {
147
+ if (typeof(plurals) !== 'object') return;
148
+ this.target = plurals;
149
+ }
150
+
151
+ /**
152
+ * Return the source string of the given plural category.
153
+ *
154
+ * @returns {String} the source string for the given
155
+ * plural category
156
+ */
157
+ getSourcePlural(pluralClass) {
158
+ return this.source &amp;&amp; this.source[pluralClass];
159
+ }
160
+
161
+ /**
162
+ * Return the target string of the given plural category.
163
+ *
164
+ * @returns {String} the target string for the given
165
+ * plural category
166
+ */
167
+ getTargetPlural(pluralClass) {
168
+ return this.target &amp;&amp; this.target[pluralClass];
169
+ }
170
+
171
+ /**
172
+ * Return an array of names of source categories of plurals
173
+ * that are used in this resource.
174
+ *
175
+ * @deprecated Use getCategories instead
176
+ *
177
+ * @returns {Array.&lt;string>} an array of source categories
178
+ */
179
+ getClasses() {
180
+ return this.getCategories();
181
+ }
182
+
183
+ /**
184
+ * Return an array of names of source categories of plurals
185
+ * that are used in this resource.
186
+ *
187
+ * @returns {Array.&lt;string>} an array of source categories
188
+ */
189
+ getCategories() {
190
+ return this.source &amp;&amp; Object.keys(this.source);
191
+ }
192
+
193
+ /**
194
+ * Return an array of names of all possible categories
195
+ * of plurals, even if they are not currently used in this
196
+ * plural instance.
197
+ *
198
+ * @returns {Array.&lt;string>} an array of category names
199
+ */
200
+ getAllValidCategories() {
201
+ return ResourcePlural.validPluralCategories;
202
+ }
203
+
204
+ /**
205
+ * Add a string with the given plural category to the source of
206
+ * this plural resource.
207
+ *
208
+ * @param {String} pluralCategory the CLDR category of this string
209
+ * @param {String} str the source string to add for the category
210
+ */
211
+ addSourcePlural(pluralCategory, str) {
212
+ logger.trace("Adding string '" + str + "' with category " + pluralCategory);
213
+ if (!pluralCategory || !str) return;
214
+ if (!this.source) {
215
+ this.source = {};
216
+ }
217
+ this.source[pluralCategory] = str;
218
+ }
219
+
220
+ /**
221
+ * Add a string with the given plural category to the target of
222
+ * this plural resource.
223
+ *
224
+ * @param {String} pluralCategory the CLDR category of this string
225
+ * @param {String} str the target string to add for the category
226
+ */
227
+ addTargetPlural(pluralCategory, str) {
228
+ logger.trace("Adding string '" + str + "' with category " + pluralCategory);
229
+ // have to have a source plural string in order to add the target
230
+ if (!pluralCategory || !str || !this.source) return;
231
+ if (!this.target) {
232
+ this.target = {};
233
+ }
234
+ this.target[pluralCategory] = str;
235
+ }
236
+
237
+ /**
238
+ * Return the length of the array of strings in this resource.
239
+ *
240
+ * @returns {number} the length of the array of strings in this
241
+ * resource
242
+ */
243
+ size() {
244
+ let len = this.source ? Object.keys(this.source).length : 0;
245
+ if (this.target) {
246
+ len = Math.max(len, Object.keys(this.target).length);
247
+ }
248
+ return len;
249
+ }
250
+
251
+ /**
252
+ * Clone this resource and override the properties with the given ones.
253
+ *
254
+ * @params {Object|undefined} overrides optional properties to override in
255
+ * the cloned object
256
+ * @returns {ResourceArray} a clone of this resource
257
+ */
258
+ clone(overrides) {
259
+ const r = new ResourcePlural(this);
260
+ if (overrides) {
261
+ for (let p in overrides) {
262
+ r[p] = overrides[p];
263
+ }
264
+ }
265
+ return r;
266
+ }
267
+
268
+ /**
269
+ * Return true if the other resources contains the same resources as
270
+ * the current one. The pathName, state, and comment fields are
271
+ * ignored as minor variations.
272
+ * @param {Resource} other another resource to test against the current one
273
+ * @returns {boolean} true if these represent the same resource, false otherwise
274
+ */
275
+ equals(other) {
276
+ if (!other || !this.same(other)) return false;
277
+
278
+ if (this.source || other.source) {
279
+ if (this.source &amp;&amp; other.source) {
280
+ for (let p in this.source) {
281
+ if (this.source[p] !== other.source[p]) {
282
+ return false;
283
+ }
284
+ }
285
+ } else {
286
+ return false;
287
+ }
288
+ }
289
+
290
+ if (this.target || other.target) {
291
+ if (this.target &amp;&amp; other.target) {
292
+ for (let p in this.target) {
293
+ if (this.target[p] !== other.target[p]) {
294
+ return false;
295
+ }
296
+ }
297
+ } else {
298
+ return false;
299
+ }
300
+ }
301
+
302
+ return true;
303
+ }
304
+
305
+ /**
306
+ * Calculate a resource key string for this category of resource given the
307
+ * parameters.
308
+ *
309
+ * @static
310
+ * @return {String} a hash key
311
+ */
312
+ static hashKey(project, context, locale, reskey) {
313
+ const key = ["rp", project, context, locale, reskey].join("_");
314
+ logger.trace("Hashkey is " + key);
315
+ return key;
316
+ }
317
+
318
+ /**
319
+ * Return the a hash key that uniquely identifies this resource.
320
+ *
321
+ * @return {String} a unique hash key for this resource
322
+ */
323
+ hashKey() {
324
+ const locale = this.targetLocale || this.getSourceLocale();
325
+ return ResourcePlural.hashKey(this.project, this.context, locale, this.reskey);
326
+ }
327
+
328
+ /**
329
+ * Return the a hash key that uniquely identifies the translation of
330
+ * this resource to the given locale.
331
+ *
332
+ * @param {String} locale a locale spec of the desired translation
333
+ * @return {String} a unique hash key for this resource
334
+ */
335
+ hashKeyForTranslation(locale) {
336
+ return ResourcePlural.hashKey(this.project, this.context, locale, this.reskey);
337
+ }
338
+
339
+ /**
340
+ * Return the a hash key that uniquely identifies this resource.
341
+ *
342
+ * @return {String} a unique hash key for this resource
343
+ */
344
+ cleanHashKey() {
345
+ const cleaned = this.reskey &amp;&amp; this.reskey.replace(/\s+/g, " ").trim() || "";
346
+ const locale = this.targetLocale || this.getSourceLocale();
347
+ return ResourcePlural.hashKey(this.project, this.context, locale, cleaned);
348
+ }
349
+
350
+ /**
351
+ * Return the a hash key that uniquely identifies the translation of
352
+ * this resource to the given locale.
353
+ *
354
+ * @param {String} locale a locale spec of the desired translation
355
+ * @return {String} a unique hash key for this resource
356
+ */
357
+ cleanHashKeyForTranslation(locale) {
358
+ const cleaned = this.reskey &amp;&amp; this.reskey.replace(/\s+/g, " ").trim() || "";
359
+ return ResourcePlural.hashKey(this.project, this.context, locale, cleaned);
360
+ }
361
+
362
+ /**
363
+ * Check if the given resource is an instance of the current
364
+ * resource.
365
+ *
366
+ * @override
367
+ * @param {Resource} a resource to check
368
+ * @returns {boolean} true if this is an instance of
369
+ * the current resource, false otherwise.
370
+ */
371
+ isInstance(resource) {
372
+ if (!super.isInstance(resource)) {
373
+ return false;
374
+ }
375
+
376
+ // now check the properties specific to this resource subclass
377
+ return Object.keys(this.source).every(prop => {
378
+ return cleanString(this.source[prop]) === cleanString(resource.source[prop]);
379
+ });
380
+ }
381
+ }
382
+
383
+ /**
384
+ * The class of this kind of string plural.
385
+ *
386
+ * @static
387
+ * @const
388
+ */
389
+ ResourcePlural.resClass = "plural";
390
+
391
+ /**
392
+ * Acceptable values for plural categories
393
+ *
394
+ * @static
395
+ * @const
396
+ */
397
+ ResourcePlural.validPluralCategories = ['zero', 'one', 'two', 'few', 'many', 'other'];
398
+
399
+ export default ResourcePlural;
400
+ </code></pre>
401
+ </article>
402
+ </section>
403
+
404
+
405
+
406
+
407
+
408
+
409
+ </div>
410
+
411
+ <br class="clear">
412
+
413
+ <footer>
414
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Thu Nov 17 2022 07:06:52 GMT-0800 (Pacific Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
415
+ </footer>
416
+
417
+ <script>prettyPrint();</script>
418
+ <script src="scripts/polyfill.js"></script>
419
+ <script src="scripts/linenumber.js"></script>
420
+
421
+
422
+
423
+ </body>
424
+ </html>