Splitting curly braces imports to many lines in WebStorm autoformatting - webstorm

Is it possible to split curly braces import into many lines when more than one thing is imported?
I want something like this:
import {
property1,
property2,
property3
} from './myModule.js'
instead of
import { property1, property2, property3 } from './myModule.js'

I don't think so. This automatically happens depending on your hard wrap settings.

Related

How to use tabulator with ember?

I want to use http://tabulator.info/ with ember. I don't understand the documentation nor can I find any guides on configuration for ember. How can I start by creating a simple table?
Looking at the examples on the site, http://tabulator.info/, it seems that tabulator only needs an element to work (and some config).
So, our end goal is going to be to use a modifier with the ability to pass the tabulator config to it.
So, this is what we'll end up with:
<div {{tabulator someConfig}}></div>
Now, unfortunately, it looks like tabulator only accepts an id in its constructor. so we'll need to dynamically add that in to appears tabulator.
First thing you'll want to do is install https://github.com/ember-modifier/ember-modifier (be sure to read the docs as this is fun stuff)
Then, create a file in your app, app/modifiers/tabulator.js
and use these contents:
import Modifier from 'ember-modifier';
import Tabulator from 'tabulator';
import { guidFor } from '#ember/object/internals';
export default class TabulatorModifier extends Modifier {
id = guidFor(this);
get config() {
return this.args.positional[0];
}
didInstall() {
this.element.id = this.id;
let config = th
this.tabulator = new Tabulator(`#${this.id}`, this.config);
}
}
And then maybe in a component or controller or something, you'd have something like:
export default class MyComponent extends Component {
get myConfig() {
return { ... };
}
}
<div {{tabulator this.myConfig}}></div>
and that should be it.
You'll want to import the CSS in your app.css

UI Kitten & React Native Web no custom mapping

I am having an issue trying to load the most basic custom mapping in React Native Web. The custom styles are loading just fine in the App, but not Web. Using the latest version with the babel loader hack as proposed here. I am using the default mapping as proposed in the UI Kitten docs for v5.x
My code looks like this:
import * as eva from '#eva-design/eva'
import * as mapping from '../styles/mapping.json'
import { myTheme } from '../styles/light-theme'
export default function App(): React.ReactElement {
return <>
<ApplicationProvider {...eva} theme={myTheme} customMapping={mapping}>
...
</ApplicationProvider>
</>
}
I tried replicating with a blank repo and it was working fine, so one line at a time I figured out that my import was not correct (not readable by babel?).
Instead of:
import * as mapping from '../styles/mapping.json'
Should be:
import {default as mapping} from '../styles/mapping.json'
The correct way is suggested in the UIKitten docs, so I don't think it will happen to many, but may help others as it's not an obvious thing if someone is working with the App emulator for the most time and not checking the Web until later.
This is the way I use the custom mapping with ts file: custom-mapping.ts
export const customMapping: any = {
components: {
CircleButton: {
meta:{...},
appearances: {...}
}
}
}
and import it like this:
...
import {customMapping} from '../custom-mapping';
<ApplicationProvider
...
customMapping={{...eva.mapping, ...customMapping}}
>
{children}
</ApplicationProvider>

Nestjs: middleware for all routes except /auth

I am started with nestjs recently and i want apply a middleware for all routes, except the auth route.
In the documentation it says that I can add all the controllers or paths of the routes where I want the middleware, but I find this way quite expensive
.forRoutes(
SearchController,
Other,
Other,
Other
);
So I would like to know if there is a solution, or if you managed to use regex for something like this:
.forRoutes(
{path: 'All route except /auth', method: RequestMethod.ALL}
);
Nowadays we use the function exclude.
export class YourModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(YourMiddleware)
.exclude('auth')
.forRoutes('*');
}
}
For further: https://docs.nestjs.com/middleware#excluding-routes
DOC: https://docs.nestjs.com/middleware
TITLE: Excluding routes
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer.apply(LoggerMiddleware).forRoutes('*')
consumer.apply(tokenVerify).exclude('/auth').forRoutes('*')
} }
Use /auth/(.*) in case you have routes like /auth/login, /auth/register, etc. .
Exclude route referring exact route path.If you have define global prefix at main.ts,It's also need to come in to that exclude path.
Eg :
main.ts
app.setGlobalPrefix('api/v1');
module.ts
export class YourModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(YourMiddleware)
.exclude({ path:'api/v1/auth',method: RequestMethod.ALL})
.forRoutes('*');
}
}

How to Declare Regex string in global resource dictionary in xamarin forms App.xaml?

I have tried to declare a regex as global resource but getting error as shown in attached image.
I just want to keep it in here instead of anywhere else.
Assuming a XAML namespace of sys for System:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Then:
<Application.Resources>
<ResourceDictionary>
<sys:String x:Key="EmailPattern">... some regex patterm ...</sys:String>
</ResourceDictionary>
</Application.Resources>
Usage:
if (Application.Current.Resources.TryGetValue("EmailPattern", out object regexPattern))
{
Console.WriteLine(regexPattern);
}

Using curly braces in JavaScript in Play Framework template

I have passed a list of titles that I have passed through from my controller:
#titles:List[String]
I want to cycle through generating some html headings with {mmm} appearing after:
#titles.map { title =>
<h1>{title} {mmm}</h1>
}
Clearly there is a problem as it will try and find a variable called mmm. How do I escape the brackets?
Or is there a more idiomatic way to generate the HTML that doesn't involve mapping the list? Very new to this!
You shouldn't need to escape curly brackets in Play—unlike in Scala's XML literals, they don't have any special meaning in Play templates except after an #.
You should be able to write the following:
#titles.map { title =>
<h1>#{title} {mmm}</h1>
}
And get <h1>Whatever Title {mmm}</hq>, etc.
Travis' answer demonstrates one possibility (for that you asked for) and it's correct. On the other hand you can also meet other cases and you need to keep in mind other tricks:
for an example this will fail:
#for(title <- titles){
Title: #title {mmm} <br/>
}
But this will work (thanks Travis)
#for(title <- titles) {
Title: #{title} {mmm} <br/>
}
And this will work as well
#for(title <- titles){
Title: #title - <b>something else without bracets</b> <br/>
}
Alternative
Alternatively you can create for an example toBrackets() method in your model and call it in your template (Java sample)
public String toBrackets(String string) {
return "{" + string + "}";
}
in template:
#for(title <- titles){
Title: #title #title.toBrackets("mmm") <br/>
}
If it is not part of JS or other code, and used just to present in the view, then we can use HTML entitles
{ for left curly brace
} for right curly brace
The result:
{ for left curly brace
} for right curly brace
You could create variables #LeftBracket = { and #RightBracket = }, and then this should work:
#titles.map { title =>
<h1>{title} #{LeftBracket}mmm#RightBracket</h1>
}
A side note somewhat related to your question:
My impression is that unless the brackets are matched (that is, a } for each {),
template compilation fails, so perhaps #RightBracket is the only way to insert a single }? This'd be useful in case you needed to write:
#titles.map { title =>
hello :-}
}
:-}