1- import Protocol from ' ./protocol' ;
2- import Core from ' ../core' ;
1+ import Protocol from " ./protocol" ;
2+ import Core from " ../core" ;
33
44function call_property ( item , property ) {
55 let prop = null ;
66
77 if (
8- typeof item === ' number' ||
9- typeof item === ' symbol' ||
10- typeof item === ' boolean' ||
11- typeof item === ' string'
8+ typeof item === " number" ||
9+ typeof item === " symbol" ||
10+ typeof item === " boolean" ||
11+ typeof item === " string"
1212 ) {
1313 if ( item [ property ] !== undefined ) {
1414 prop = property ;
@@ -50,15 +50,15 @@ function contains(left, right) {
5050}
5151
5252function get_global ( ) {
53- if ( typeof self !== ' undefined' ) {
53+ if ( typeof self !== " undefined" ) {
5454 return self ;
55- } else if ( typeof window !== ' undefined' ) {
55+ } else if ( typeof window !== " undefined" ) {
5656 return window ;
57- } else if ( typeof global !== ' undefined' ) {
57+ } else if ( typeof global !== " undefined" ) {
5858 return global ;
5959 }
6060
61- throw new Error ( ' No global state found' ) ;
61+ throw new Error ( " No global state found" ) ;
6262}
6363
6464function defstruct ( defaults ) {
@@ -78,15 +78,15 @@ function defstruct(defaults) {
7878function defexception ( defaults ) {
7979 return class extends Error {
8080 constructor ( update = { } ) {
81- const message = update . message || '' ;
81+ const message = update . message || "" ;
8282 super ( message ) ;
8383
8484 const the_values = Object . assign ( defaults , update ) ;
8585 Object . assign ( this , the_values ) ;
8686
8787 this . name = this . constructor . name ;
8888 this . message = message ;
89- this [ Symbol . for ( ' __exception__' ) ] = true ;
89+ this [ Symbol . for ( " __exception__" ) ] = true ;
9090 Error . captureStackTrace ( this , this . constructor . name ) ;
9191 }
9292
@@ -121,7 +121,7 @@ function is_valid_character(codepoint) {
121121function b64EncodeUnicode ( str ) {
122122 return btoa (
123123 encodeURIComponent ( str ) . replace ( / % ( [ 0 - 9 A - F ] { 2 } ) / g, ( match , p1 ) =>
124- String . fromCharCode ( `0x${ p1 } ` ) ) ,
124+ String . fromCharCode ( `0x${ p1 } ` ) )
125125 ) ;
126126}
127127
@@ -148,7 +148,7 @@ function update_map(map, property, value) {
148148 return add_property_to_map ( map , property , value ) ;
149149 }
150150
151- throw ' map does not have key' ;
151+ throw " map does not have key" ;
152152}
153153
154154function bnot ( expr ) {
@@ -213,7 +213,7 @@ function can_decode64(data) {
213213function remove_from_list ( list , element ) {
214214 let found = false ;
215215
216- return list . filter ( ( elem ) => {
216+ return list . filter ( elem => {
217217 if ( ! found && elem === element ) {
218218 found = true ;
219219 return false ;
@@ -309,9 +309,9 @@ function reverse(list) {
309309
310310function maps_find ( key , map ) {
311311 if ( key in get_object_keys ( map ) ) {
312- return new Core . Tuple ( Symbol . for ( 'ok' ) , map [ key ] ) ;
312+ return new Core . Tuple ( Symbol . for ( "ok" ) , map [ key ] ) ;
313313 }
314- return Symbol . for ( ' error' ) ;
314+ return Symbol . for ( " error" ) ;
315315}
316316
317317function flatten ( list , tail = [ ] ) {
@@ -377,6 +377,25 @@ function maps_fold(fun, acc, map) {
377377 return acc1 ;
378378}
379379
380+ function build_namespace ( ns , ns_string ) {
381+ let parts = ns_string . split ( "." ) ;
382+ let parent = ns ;
383+
384+ if ( parts [ 0 ] === "Elixir" ) {
385+ parts = parts . slice ( 1 ) ;
386+ }
387+
388+ for ( const part of parts ) {
389+ if ( typeof parent [ part ] === "undefined" ) {
390+ parent [ part ] = { } ;
391+ }
392+
393+ parent = parent [ part ] ;
394+ }
395+
396+ return parent ;
397+ }
398+
380399export default {
381400 call_property,
382401 apply,
@@ -416,4 +435,5 @@ export default {
416435 mapfoldl,
417436 filtermap,
418437 maps_fold,
438+ build_namespace
419439} ;
0 commit comments