149 questions
0
votes
1
answer
30
views
Can't assign numerical value to numerical template string in typescript
In typescript, I want to assign a number variable to a string variable that only accepts numerical strings. I tried the following:
const x: number = 0;
const y: `${number}` = x.toString();
But ...
0
votes
3
answers
50
views
Is it possible to interpolate a template string using data from an object in JavaScript?
Is it possible to interpolate a template string using key/values from a object in JavaScript, like string substitution in Python:
data = {"age": 18, "name": "John"}
"...
0
votes
1
answer
101
views
Is it possible to add a JSX element to a template string that is within an array of objects?
I'm trying to add JSX elements like <a>, <p> and else to an array of objects in a template string, this project has a portfolio.jsx file that holds the array, another file called Projects....
1
vote
1
answer
4k
views
ESLint with typescript "Parsing error: Type expected" with Template Literal Types
I have this type:
export type ICfnOutput = {
ENDPOINTS: {
[key in `${keyof typeof MSERVICES}_ENDPOINT`]: string
},
USER_POOL_CLIENT_ID: string,
amplifyClientUrl: string,
...
0
votes
1
answer
544
views
Angular Drawflow: How to drop component as node
Is it possible to make the click event working for template strings like this?
const htmlTemplate = `
<div>
<div>
<textarea df-template></textarea>
<button (...
1
vote
1
answer
954
views
Handlebars.js with JavaScript template strings throws error
I'm using plop for code generation of some TypeScript files. This is not using HTML at all. Under the hood plop uses Handlebars for it's templating. One of my templates generates a series of new ...
0
votes
1
answer
1k
views
How to get value of object property using template strings
I have this object totalData which I am destructuring to add on a new object value. I understand I am able to define new object properties using template strings (as shown below) but how can I use ...
0
votes
1
answer
156
views
How to upgrade the docx format to the latest by docx?
👉The original file is docx format, which has multiple tables, but there may be format problems, so it cannot be read by python-docx.
✔️ 1.Solution by hand:
solve the question by click [save as ....]...
0
votes
1
answer
331
views
How can I avoid control character interpretation in Javascript template string interpolation?
I have a string variable containing a control character (newline). I want to output that variable but with the control character as its literal representation and not interpreted:
console.log(`Using &...
0
votes
0
answers
100
views
import dynamically in ReactJs using for to assign an imported const to different objects
Please be patience, my english is not that good. I am trying to create a for loop to push for each image imported, an object with different values. I want to avoid just setting all the objects i want ...
0
votes
1
answer
331
views
Generate variables from JSON to use in string template (Javascript)
I have some JSON that looks a little like this:
component.json
[
{ "template": "<div class="${layout} ${border}"></div>" },
{
"layout": &...
0
votes
1
answer
489
views
Template strings in mongoose update query with typescript [duplicate]
I want to use a template string in a mongoose update query using typescript.
The field I want to update is a Map called messages with string keys and array values of type Message.
So something like
...
3
votes
4
answers
134
views
What is the difference between these two functions involving typeof
My teacher in JavaScript gave me an assignment to master functions. I tried to solve the assignment which requires me to make the output like the second code:
function showDetails(name = "unknown&...
1
vote
0
answers
29
views
Trying to find a way to control background color via 11 different buttons. Question about template strings?
I have 11 buttons with their own class, as well as all 11 share the class .theme-color. I am trying to have it change to the background color on the button class. My idea was to get the class into the ...
0
votes
0
answers
29
views
No output with template-string
I try to use the npm qrcode API with express. When the user enters an address into a form, the QR-Code should be displayed on the website. I searched for a long time, but can't figure it out, since I ...
1
vote
1
answer
87
views
How to use string template while using JSON?
I am working on a project and would like to use prodConfig or draftConfig according to few conditions. I am using Hasura and getting 2 different JSON responses with only 1 key different in the ...
0
votes
1
answer
286
views
String to template string for array of object mapping
somewhere from the API data I am getting normal string like, “Hi ${person[0].name}” now this string I am converting into template string and getting replace its variables from array of object.
Here is ...
3
votes
1
answer
2k
views
Twin.Macro (Styled Components) + Typescript in NextJS : Argument of type 'Interpolation<never>' is not assignable to parameter of type
Just followed the twin.macro tutorial to set it up with next.js, styled-components & typescript. Followed everything in a newly setup project, but I'm getting this error:
./components/...
0
votes
2
answers
646
views
i need to increment a number in a classList template string javascript
hello friends I got a hard one and I'm a bit in a pickle
in my blackjack game I create images(of the cards) and the values come from the .PNG name from a list in an object. what I want to do is be ...
0
votes
1
answer
703
views
How to insert html tags in template literals in response object NodeJs
Resultant Response in Messenger. But I need to bold username, phone-number, etc.
I am new in web development.
I also tried \x3Cb>I am Bold\x3C/b>" but didn't work for me.
How can I add HTML ...
1
vote
1
answer
2k
views
Angular Pipes with template strings that are inserted through [innerHTML]
I was trying to implement ngx-translate in one of the recently completed angular projects. In the project we have a component that renders HTML files inside a certain div through innerHTML. Now as I ...
0
votes
2
answers
2k
views
How to access data displayed by dangerous html
I have tables that I am displaying using dangerous HTML in reacting hooks
Live Demo : live demo code sand box
Data looks like this
export const json = [
{
template: `
<div ref={tableRef} ...
0
votes
1
answer
1k
views
Uncaught SyntaxError: Unexpected identifier in template string
I have some html that I converted into a template string and getting the above error when I check the checkbox, I know it has to do with the ${currentRow}, just not sure why its acting this way
...
1
vote
1
answer
481
views
Defining HTML attributes with template string
I am trying to set the href attribute of an <a>-Tag inside a template string but it does not work.
function createLink(object) {
return `<a href="${object.DetailActionUri}">...
1
vote
0
answers
45
views
Is this correct syntax for ES2015 tagged template? [duplicate]
On this page there is the following code snippet (which can also be found here), demonstrating some use of a template string. The only explanation or context is the comment at the start, which makes ...
0
votes
0
answers
79
views
Using TS literal types, what is the most straight-forward way to get a string that matches multiple patterns against a union of string literals?
Let's say i have the following union:
type T = "a.success" | "a.failure" | "b.success" | "c";
and I want to get a union of all strings that match two patterns ...
0
votes
1
answer
536
views
Defining a variable using template strings [duplicate]
Is it possible to create a variable using template strings? Here is a simple example of what I want to achieve:
let times, hours="fullTime";
if (hours === "fullTime") {
...
0
votes
1
answer
50
views
How do I make this with template string?
I have smth like this
const activeLang = 'pl'
const uniqueCategories = products.map((product) => {
return product.category_pl
})
How do I make this the same but with using template ...
1
vote
1
answer
419
views
Javascript Template Literals and Html Textarea
To get some html to render nicely inside a textarea,
I have to make my code-indentation look ugly;
What's the proper way to write my template literal, without resorting to bad indentation?
0
votes
2
answers
60
views
Why the es6 template-string needs double quart in this occasion Javascript?
I`m on the Javascript30 #1 now, and I`ve been wondering about a small stuff...
This code below worked.
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
But, this code ...
9
votes
1
answer
9k
views
Variable "$userId" of type "ID" used in position expecting type "ID!"
I am trying to make a graphql request using the npm package graphql-request. I am discovering the use of template literals.
async getCandidate(userId: number) {
const query = gql`
...
0
votes
0
answers
604
views
Using React router link inside template string does not working
I am trying to use Link of react router inside a template string with no success.
i tried also to wrap the tag with ${} but that doesnt work either.
does anyone know how can i make it work?
const ...
-1
votes
2
answers
100
views
Could not insert data into the template literal for SMS distribution
I have a problem with the template literals JS.
I get user data and an SMS template from a MySQL table.
// User fields
let name = data.info.name; // Chingis
let start_datetime = data.info....
0
votes
1
answer
293
views
Template literals in API fetch don't pass data in Angular
I have a fetch() function to collect data from Skyscanner API. It works fine until I use template literals. This results in getting error 400.
public departureAPI = "WAW-sky";
fetch(
&...
0
votes
0
answers
26
views
Template string in a JS function call [duplicate]
I have this object:
let user = {
name: undefined,
age: undefined,
city: undefined,
}
and these arrays
props = ["name", "age", "city"];
values = ["alan", 90, "london"];
and i want to do ...
0
votes
1
answer
852
views
How to convert a template string in JSON in angular?
I have this code in my ty file:
onSubmit(form: NgForm){
console.log('Executado')
let dados = `
name: ${form.value.name},
email: ${form.value.email},
specialty: ${form.value.specialty},
...
-1
votes
2
answers
1k
views
Passing template literal as prop is not rendering
I've got a functional component
const Paragraph = forwardRef((ref: any) => {
return (
<div>
<p dangerouslySetInnerHTML={{ __html: props.text }}></p>
</div>
...
0
votes
2
answers
53
views
Why use the templatestring expression a=`${a}` in javascript?
I was looking at some javascript code and noticed a line using the template string backticks:
a=`${a}`
However, this does not seem to have any effect to me as the variable a contains a string.
Is ...
0
votes
1
answer
84
views
Replace part in some string written in separate file that is being used in other file javascript
I have a config file that has different URLs for different environments. I am using the object key for base url from the given object.
const configDev = {
API: {
url: 'http://api.domain....
0
votes
1
answer
299
views
Problem with tagged template strings and closure
Symbol.toPrimitive method, invoked within tagged template literal loses access to the closure.
To reproduce, simply paste the provided code snippet in dev console, run it with and without tag-...
0
votes
3
answers
151
views
Difference between {`${props.title} `} and {props.title}
I see in some places, to get the value of title from props, we use
{`${props.title} `}
while in some other places, we use it
{props.title}
What is the difference?
1
vote
2
answers
6k
views
Query not working with SQL Template Strings npm
I'm trying to use the sql template strings npm package to use template literals in my SQL queries securely, but I keep getting an error that states that there is a problem with the sql syntax. When I ...
0
votes
1
answer
366
views
Minify html template string with javascript regex
In my project I am using a lot of JavaScript template string. After webpack compilation that is resulting in newlines, tabs and white spaces. How can I remove it with regex or any DOM API like ...
6
votes
0
answers
512
views
Including a literal backtick in a String.raw template literal
I am working on a system that generates JavaScript, and I would like to minimize the amount of escaping that needs to be done for string literals. My current approach is to use the String.raw template ...
1
vote
4
answers
4k
views
If Else Condition Not Working In Javascript Template Literals
I am getting issue while displaying my table data inside tbody, in my javascript i am getting result object and i am using template literals inside javascript file Here's my code:
for (i = 0; i < ...
2
votes
1
answer
62
views
How to change the value that a template string extrapolates
I'm trying to write a simple Id monad to play around with and learn.
Here is what I've written:
const util = require('util');
const Id = x => ({
[util.inspect.custom]: () => `Id(${x})`,
...
6
votes
2
answers
9k
views
Proper way to escape ${} in a JS template string
I am creating a bash command:
const k = cp.spawn('bash');
k.stdin.end(`
alias ssh='ssh "${SSH_ARGS[@]}"'
`);
but of course, I have to escape it. I assume the best way to escape it, is using:
`...
0
votes
2
answers
2k
views
How to match a template string in switch statement with js?
I have a function that returns a component that depends on the pathname of the window.
getComponentByPathname = (pathname) => {
switch(patname){
case "/view1": return <...
0
votes
1
answer
902
views
JavaScript returning boolean over 21 y/o within template string
I can't figure out how to implement a greater then formula within a template string to return a boolean value (see code).
const age = 47; // simplified for question
let html;
html = `<ul>
...
-1
votes
1
answer
103
views
Javascript template string [duplicate]
I need to create some substrings using the template string.
I try to use this code but I have some problem about the auto filling of the template.
Object.keys(optionsParams).forEach(function (...