Export Nested SCSS Map to Json - json

I am attempting to export my scss to JSON npm package sass-export
I can successfully export variables and maps one level deep, but the problem is I have a colour map(shown is just the first portion there are many colours in it) that is two levels deep. The error that is thrown is about unclosed parenthesis. Everything appears good to me, I have followed the docs to export maps but I can't find much more info on the subject. Thanks for any insight you can provide.
Successfully exported
$z-index: (
"below-base": -1,
"base":0,
"xs": 100,
"sm": 200,
"md": 300,
"lg": 400,
"xl": 500
);
Console Output
mapValue:Array(7)
0: {name: "below-base", value: "-1", compiledValue: "-1"}
1: {name: "base", value: "0", compiledValue: "0"}
2: {name: "xs", value: "100", compiledValue: "100"}
3: {name: "sm", value: "200", compiledValue: "200"}
4: {name: "md", value: "300", compiledValue: "300"}
5: {name: "lg", value: "400", compiledValue: "400"}
6: {name: "xl", value: "500", compiledValue: "500"}
Unsuccessful
$colour-palette: (
gray: (
0: #0D0D0D,
1: #1A1A1A,
2: #262626,
3: #333333,
4: #5C5C5C,
5: #858585,
6: #ADADAD,
7: #D4D6DB
),
);
Terminal Error Output
{ Error: unclosed parenthesis
at Object.module.exports.renderSync (C:\Users\tbilcke\Documents\repos\node_modules\node-sass\lib\index.js:439:16)
status: 1,
file: 'stdin',
line: 193,
column: 34,
message: 'unclosed parenthesis',
formatted: 'Error: unclosed parenthesis\n on line 193 of stdin\n>> #sass-export-id.gray{content:"#{(0: #0D0D0D}";}\n ---------------------------------^\n' }
Console Output
colour-palette: Array(1)
0:
compiledValue:"(gray: (0: #0D0D0D, 1: #1A1A1A, 2: #262626, 3: #333333, 4: #5C5C5C, 5: #858585, 6: #ADADAD, 7: #D4D6DB))"
mapValue: Array(1)
0: {name: "gray", value: "(0: #0D0D0D", compiledValue: ""}
length:1
__proto__: Array(0)
name: "$colour-palette"
value :
"(gray: (0: #0D0D0D,1: #1A1A1A,2: #262626,3: $gray-base,4: #5C5C5C,5: #858585,6: #ADADAD,7: #D4D6DB),)"
Sass Export - Working
let __root = path.join(__dirname, '../')
let __src = path.join(__dirname, '../src')
let exportPath = path.join(__src, 'scss/_test_cars.scss')
let importPath = path.join(__src, 'scss/')
let options = {
inputFiles: [exportPath],
includePaths: [importPath]
}
let asObject = exporter(options).getStructured()
process.env.styles = JSON.stringify(asObject)

I recently encountered the same issue and managed to resolve it with a relatively painless workaround.
If you take your child arrays and separate them out like so;
$colour-palette-gray: (
0: #0D0D0D,
1: #1A1A1A,
2: #262626,
3: #333333,
4: #5C5C5C,
5: #858585,
6: #ADADAD,
7: #D4D6DB
);
and then in a separate scss file (which you dont observe with sass-export) load them into the parent array
$colour-palette: (
'grey': $colour-palette-gray,
'blue': $colour-palette-blue,
'pink': $colour-palette-pink
);
you can also use the special comment syntax above each child array declaration to ensure that the nodes in the JSON are labelled correctly;
/**
* #sass-export-section="brand-colors"
*/
I am using the gulp implementation of the module in this way and it works as desired

Related

$filter ignored by OData when specifying additional parameters

When adding parameters to a call to an OData endpoint in my application like this
https://localhost:12345/TestServer/RequestDto
?$count=true&$orderby=TimeStamp%20desc
&$filter=(Ownername%20eq%20%27Baggins%2C%20Frodo%27)
&$skip=0&$top=26&userID=bt0388&showByAuthor=False
the $filter seems to be getting ignored. userID and showByAuthor are the additional parameters.
The related endpoint looks like this.
public class RequestDtoController : ODataController
{
// ...
[EnableQuery]
public IQueryable<DocumentRequestDTO> Get(string userID, bool showByAuthor)
{
// ...
}
It does get called with proper parameters. The data it returns is correct and complete.
I expect the OData layer to apply the filter, but it doesn't. This is the final result set:
{#odata.context: "https://localhost:44393/DocServer2/$metadata#RequestDto", #odata.count: 4,…}
#odata.context: "https://localhost:44393/DocServer2/$metadata#RequestDto"
#odata.count: 4
value:
[{ID: "dc3a6999", AuthorID: "0388", Authorname: "Wonka, Willy",…},…]
0:
{ID: "dc3a6999", AuthorID: "0388", Authorname: "Wonka, Willy",…}
Ownername: "Wonka, Willy"
...
1:
{ID: "685b7e33", AuthorID: "Test-Owner", Authorname: "Test, Owner",…}
Ownername: "Wonka, Willy"
...
2: {ID: "8192d591", AuthorID: "0003", Authorname: "Hedgehog, Sonic",…}
Ownername: "Baggins, Frodo"
...
3: {ID: "b56b7cfc", AuthorID: "0003", Authorname: "Hedgehog, Sonic",…}
Ownername: "Baggins, Frodo"
...
How would I need to go about fixing it?

Reading a csv file to run the shortest path (Dijkstra's) algorithm in Jupyter Notebook

I am trying to run the shortest path (Dijkstra’s) algorithm, reading “Start” and “End” nodes and the cost from a csv file. Each set in the file represents a link (Start,End,Cost). The file looks like this:
Start,End,Cost
0,1,2
0,2,10
0,3,7
1,5,4
2,3,4
2,4,3
3,6,1
4,0,15
5,3,1
7,8,3
The algorithm that I want to use requires the graph in the following format:
{0: {1: 2, 2: 10, 3: 7}, 1: {5: 4}, 2: {3: 4, 4: 3}, 3: {6: 1}, 4: {0: 15}, 5: {3: 1}, 6: {}, 7: {8: 3}, 8: {}}
Anyone knows how to do it? Don’t want to do it manually because I want to run the algorithm with a larger graph (e.g.: 1000 nodes and 2500 links).
I’ve started reading the csv file to a df and then to a dictionary, then a couple of loops and assignments, but I haven’t been successful in getting the right format.
Sometimes I print it and looks like this (which is incorrect):
{0: {3: 7}, 1: {5: 4}, 2: {4: 3}, 3: {6: 1}, 4: {0: 15}, 5: {3: 1}, 6: {}, 7: {8: 3}, 8: {}}
Other times I’ve tried merging and looks like this (close, but also incorrect):
{0: ((({}, {1: 2}), {2: 10}), {3: 7}), 1: ({}, {5: 4}), 2: (({}, {3: 4}), {4: 3}), 3: ({}, {6: 1}), 4: ({}, {0: 15}), 5: ({}, {3: 1}), 6: {}, 7: ({}, {8: 3}), 8: {}}
All suggestions are welcomed, thanks!

how to remove undefined in object

I have this object and need to remove undefined in typescript. How to do that
myObject = {
0: undefined
1: {label: '129 XENON (RO7492908-001)', genericName: '129 XENON', itemumber: 'RO7492908-001'}
2: {label: '203PB-DOTAM (RO7205834-006)', genericName: '203PB-DOTAM', itemumber: 'RO7205834-006'}
3: {label: '212PB-DOTAM (RO7205834-007)', genericName: '212PB-DOTAM', itemumber: 'RO7205834-007'}
};

how to iterate inside json file by field name

i have a json result:
0: { m_event_type_id: 0, m_event_log_description: "SYSTEM_LOG_44: RPM Reduction Due to High Wind Turbulence OFF", …}
1: { m_event_type_id: 0, m_event_log_description: "SYSTEM_LOG_44: RPM Reduction Due to High Wind Turbulence ON", …}
2: { m_event_type_id: 0, m_event_log_description: "Grease Pump Stopped 30 cycles executed", …}
3: { m_event_type_id: 0, m_event_log_description: "Grease Pump Started", …}
4: { m_event_type_id: 0, m_event_log_description: "SYSTEM_LOG_40: Battery Test Request Signal ON", …}
my result is stored in a variable call rslt,now i want to access
rslt.m_event_log_description
but it gives me error because cant access the property like this,any way to achive it?i dont want to write rslt[0].m_event_log_description because it just gives me the first one
You could use the Array#map function to extract a property from an object array as an array.
Try the following
someService.getData().subscribe(
response => {
this.rslt = response;
this.logDescriptions = response.map(item => item['m_event_log_description']);
},
error => {
// handle error
}
);
Now you could use the logDescriptions property in the template
<div *ngFor="description of logDescriptions">
{{ description }}
</div>

Elixir decode with Poison

I'm getting this string as query result from my database:
"%Sample.Struct{list: [], total: \"0.00\", day: 6, id: \"8vfts6\"}"
Is there any way to convert this one back to map?
I'm getting this error decoding it with poison
** (Poison.SyntaxError) Unexpected token: %
(poison) lib/poison/parser.ex:56: Poison.Parser.parse!/2
(poison) lib/poison.ex:83: Poison.decode!/2
I can't fix the way data is being added to database, i must find a proper way for a key/value route to easily retrive data from that. (this is just a sample for a more complex result)
As it was mentioned in comments, you should not use Code.eval_string. But, there is a way to safely convert your code to Elixir struct, using Code module:
ex(1)> encoded = "%Sample.Struct{list: [], total: \"0.00\", day: 6, id: \"8vfts6\"}"
"%Sample.Struct{list: [], total: \"0.00\", day: 6, id: \"8vfts6\"}"
First, get the AST from the string, but use the pattern matching to ensure it is a struct you are looking for ({:__aliases__, _, [:Sample, :Struct]}). All other (potentially malicious) code will fail this match:
iex(2)> {:ok, {:%, _, [{:__aliases__, _, [:Sample, :Struct]}, {:%{}, _, keymap}]} = ast} = Code.string_to_quoted(encoded)
{:ok,
{:%, [line: 1],
[{:__aliases__, [line: 1], [:Sample, :Struct]},
{:%{}, [line: 1], [list: [], total: "0.00", day: 6, id: "8vfts6"]}]}}
Here you have the full ast for you struct, and the keymap. You may now be tempted to use eval_quoted with the AST, to get the struct you needed:
iex(3)> {struct, _} = Code.eval_quoted(ast)
{%Sample.Struct{day: 6, id: "8vfts6", list: [], total: "0.00"}, []}
iex(4)> struct
%Sample.Struct{day: 6, id: "8vfts6", list: [], total: "0.00"}
But it is still not safe! Someone may put a function causing side effect into the string, like "%Sample.Struct{list: IO.puts \"Something\"}", which will be executed during the evaluation. So you will need to check the keymap firsts, if it contain safe data.
Or you may just use keymap directly, without evaluating anyting:
iex(5)> struct(Sample.Struct, keymap)
%Sample.Struct{day: 6, id: "8vfts6", list: [], total: "0.00"}