File tree Expand file tree Collapse file tree 2 files changed +13
-27
lines changed
Expand file tree Collapse file tree 2 files changed +13
-27
lines changed Original file line number Diff line number Diff line change 44
55import isLanguageTag from '../utilities/validate/isLanguageTag.js' ;
66
7- /**
8- * Proxy traps for the MultiLangString class
9- * @type {Object }
10- */
11- const classTraps = {
12- construct ( Target , args ) {
13-
14- const map = Reflect . construct ( Target , args ) ;
15-
16- Object . defineProperty ( map , `set` , {
17- configurable : true ,
18- enumerable : false ,
19- get ( ) {
20- return function ( key , val ) { // eslint-disable-line func-names
21- validateLanguageTag ( key ) ;
22- validateString ( val ) ;
23- return map . set . apply ( this , [ key , val ] ) ; // eslint-disable-line no-invalid-this
24- } ;
25- } ,
26- } ) ;
27-
28- return map ;
29-
30- } ,
31- } ;
32-
337/**
348 * Validates a language tag. Throws a type error if the input is not a valid IETF language tag.
359 * @param {Any } input The input to validate
@@ -104,10 +78,16 @@ class MultiLangString extends Map {
10478
10579 }
10680
81+ set ( key , val ) {
82+ validateLanguageTag ( key ) ;
83+ validateString ( val ) ;
84+ return super . set ( key , val ) ;
85+ }
86+
10787 toJSON ( ) {
10888 return Object . fromEntries ( this ) ;
10989 }
11090
11191}
11292
113- export default new Proxy ( MultiLangString , classTraps ) ;
93+ export default MultiLangString ;
Original file line number Diff line number Diff line change @@ -92,6 +92,12 @@ describe(modelName, () => {
9292
9393 } ) ;
9494
95+ it ( `MultiLangString.prototype.set()` , ( ) => {
96+ const mls = new MultiLangString ;
97+ const setData = ( ) => mls . set ( `hello` , `world` ) ;
98+ expect ( setData ) . not . toThrow ( ) ;
99+ } ) ;
100+
95101 it ( `MultiLangString.prototype.toJSON()` , ( ) => {
96102
97103 const mls = new MultiLangString ( sampleData ) ;
You can’t perform that action at this time.
0 commit comments