How to mark certain words with asterisks (Javascript)

I have an array of objects with a set of certain words like entities. For example :

entities: [
    { sourceText: 'red'},
    { sourceText: 'green'},
    { sourceText: 'yellow'},
    { sourceText: 'purple'},
    { sourceText: 'grey'},
    { sourceText: 'blue'}
  ]

And i have some random sentences. For example: ‘I drive a red car among green fields and look at the gray sky’

The goal is to mark words with asterisks according to the object of entities:

‘I drive a red* car among green** fields and look at the gray*** sky’

I’m trying to do this in a loop with silce and Regexp but I can’t concatenate the string correctly

How can this be done ?

Need help printing out a list from db

Been trying to print out a simple list from db for 2 days now, here’s the code right now:

function CategoriesTable() {

const [isLoading, setLoading] = useState(true);
let item_list = [];
let print_list;

useEffect(() =>{
    Axios.get('http://localhost:3000/categories').then((response) => {

        const category_list = response.data.result;
        
        if(category_list) {
            for(let i = 0; i < category_list.length; i++){
                item_list.push(category_list[i].category_name)
            }
        }

        print_list = function() {
            console.log(item_list.map((item) => <li>item</li>))
            return item_list.map((item) => <li>item</li>)
        }

        setLoading(false);
    })      
}, [])


return (
    <div>
        { !isLoading && print_list }
    </div>
    )
}

I think the function should be executed after the loading state gets changed to false, right? For some reason the function is not executing

By the way, I can print out the list in console without a problem, rendering the list is the problem.

TypeError: .ban is not a function

I was trying to make a ban slash command with discord.js v13, but it gives me an error!
Whats wrong?

const { MessageEmbed } = require("discord.js");
module.exports = {
    data: new SlashCommandBuilder()
        .setName('ban')
        .setDescription('Ban someone!')
        .addUserOption(option => option.setName('user').setDescription('Select a user').setRequired(true))
        .addStringOption(option => option.setName('reason').setDescription('Enter a reason').setRequired(true))
    ,
    async execute(interaction) {
        if (!interaction.member.permissions.has("BAN_MEMBERS")) return interaction.reply({ content: "Jij kan dit niet doen", ephemeral: true });

        const banUser = interaction.options.getUser('user');
        const reason = interaction.options.getString('reason');
        let member = interaction.options._hoistedOptions[0]
        console.log(member);
        console.log(banUser);
        console.log(interaction.options);


        member.ban({ reason: reason }).catch(err => {
            if (err) return interaction.reply({ content: `Er is een fout opgetreden tijdens het uitvoeren van dit commando!nMogelijke redenen: n- De gebruiker zit niet in de server;n- De gebruiker heeft een te hoge rang;n- Ik heb niet genoeg permissies om dit commando uit te voeren.`, ephemeral: true })
            console.log(err)
        });
        var logEmbed = new MessageEmbed()
            .setColor("BLURPLE")
            .setFooter({ text: interaction.member.displayName, iconURL: interaction.user.displayAvatarURL })
            .setTimestamp()
            .setDescription(`**Gebanned:**
        ${member.user.username} (${member.id})
        **Ban door:** ${interaction.author}
        **Reden:** ${reason}`);
        const logChannel = interaction.client.channels.cache.get("934107862072950814");
        if (!logChannel) return interaction.reply({ content: "Ik kan niet bij het logs kanaal, meld dit bij de bot developer!", ephemeral: true });
        logChannel.send({ embeds: [logEmbed] });

    },
};

My error:

TypeError: member.ban is not a function

Does someone know how to fix?

How to make ::selection background and text change randomly based on specific colors

I’m trying to change the ::selection background and text of my website using JS.
I want to make the selection background and text change randomly based on the colors I already chose.
I have the color changed using just CSS, like this:

::selection {
    background-color: #ffce00;
    color: #000;
}

::-moz-selection {
    background-color: #ffce00;
    color: #000;
}

::-o-selection {
    background-color: #ffce00;
    color: #000;
}

::-ms-selection {
    background-color: #ffce00;
    color: #000;
}

::-webkit-selection {
    background-color: #ffce00;
    color: #000;
}

But I want the color to be changed in each new selection made, like this :

https://imgur.com/749VnR4

https://imgur.com/h3PWmhD

https://imgur.com/TXByYVl

https://imgur.com/UpkIgHA

I’d appreciate it if anyone could help.
Thank you.

NestJS – avoid setContext() in constructor on logger injection

In NestJS I have custom logger:

import { Injectable, Logger, Scope } from '@nestjs/common';

@Injectable({ scope: Scope.TRANSIENT })
export class LoggerService extends Logger {
  log(message: any) {
    super.log(message);
  }

  error(message: any) {
    super.log(message);
  }

  warn(message: any) {
    super.log(message);
  }

  debug(message: any) {
    super.log(message);
  }

  verbose(message: any) {
    super.log(message);
  }

  setContext(context: string) {
    super.context = context;
  }
}

It is registered globally:

import { Global, Module } from '@nestjs/common';
import { LoggerService } from './logger.service';

@Global()
@Module({
  providers: [LoggerService],
  exports: [LoggerService],
})
export class LoggerModule {}

Is there any way to somehow pass context on injection in service constructor and avoid execution of logger.setContext(context) in every service – instead just set it in LoggerService constructor?

Example usage now:

constructor(private logger: LoggerService) {
    this.logger.setContext(ClassName.name);
}

Expected usage:

constructor(private logger: LoggerService) {}

Is it possible to read MS Document or Excel in indesign script?

I have following code. My script can read external file liken(txt) and place it to InDesign file but if I try to change .txt –> .doc I get some weird characters It looks like .js or .jsx doesn’t know to read it What I can do in this case?

this works

var variable ="hello world"

var doc = app.activeDocument;
var titleTextFrame = doc.textFrames.add(); 
titleTextFrame.contents = variable; 
titleTextFrame.geometricBounds = [20, 80, 80, 150]; 


    var inputFile = File("~/Desktop/text.txt");
    
    var inputData;
    inputFile.open("r");
    inputData = inputFile.read().toString();
    inputFile.close();
    
  
alert(inputData);

var textLorem = doc.textFrames.add();
textLorem.contents = inputData; 
textLorem.geometricBounds = [30, 80, 80, 150];  

this doesn’t work

 var inputFile = File("~/Desktop/text.doc");

login for website within website integration

so i have requirement where i need to handle a case where in when you login to one website, we need to be allowed to login to another website

Let me explain
Say there is a parent website and a child website, both this website have the user details who is going to be logged in.

//PARENT WEBSITE
<!DOCTYPE html>
<html>
<body>
<iframe src="https://childwebsiteurl?param=parentwebsitetoken" title="this is child website">
</iframe>
</body>
</html>

So i want a solution basically where in when i login to the parent website, i should be logged in to the child website also.

Right now i have one solution in mind:
When the user logs in to the parent website, i will get a token and that token i will then past it to the child website(here we are assuming that the backend of both child and parent website has means to verify the token, n both has the user information) and that way i can login to child website and child website is shown in the iframe of the parent website.

My only concern is, is there a standard way to do this, or is what i have proposed is it proper?

Thanks in advance.

Send post request with Angular , catch data with javascript

I need to send http post request at Angular9 app and catch data from a javascript file with ajax javascript. Problem occured bc of i’m running two different ports in a application on the frontend side and need to send data between these two ports. One side of app is angular , other side is javascript. Could you recommend to me some documentation or advice?

How to convert a combination of month & year into yyyy-mm-dd format using date-fns library?

I want to convert my date format into yyyy-mm-dd using date-fns library.

const a = 'Dezember 2022'; // where Dezember is in 'de' locale
const b = 'März 2022'; // where März is in 'de' locale & it's March

I wanna convert const a variable value into ‘2022-12-01’ format. Similarly for const b variable value should be converted in ‘2022-03-01’. How can I do that ?

I have written a function but it’s not working.
my Code –

export function convertDate(date: string, formatStr = 'dd-MM-yyyy'): string {
  if (!date) return '';

  return format(new Date(date),formatStr, {locale: de.localize.month('Dezember')});
}

I am calling convertDate('März 2022'); but it’s not working.
Any solutions ?

Convert TO bezierCurveTo()

So i am newbie in canvas and i am newbie in Bezier curve.

I make bezier Curve very very hard.

So i need a program or plugin or website that make me convert the two points that i draw to bezierCurveTo().

Like “https://cubic-bezier.com/” it make me change the point and convert it to cubic-bezier function for the Css

I need the same but to bezierCurveTo(). Really i need any help to do curves.

I know the px can’t be the same in all canvas but i need anything help to do put my ctx1, cty1, ctx2, cty2, x, y

And Thanks

facing issue when open view in new tab jquery isn’t loaded

I’m facing an issue with my MVC application i have some jquery function written on my Layout page and i call these function from different views, but on a specific VIEW when i open this view by clicking from menu it will work fine but when I open the view in new tab from menu by right click on it so jquery isn’t loaded. Its happening only in 1 View of my application i have several views and all are working fine.
any leads why this happen ?
Thanks in advance.

ReactJS: Sorting list for data starts with capital letter

I have an array of objects and I should sorting this array, but I have a problem because my sorting consider the capital letter before others (for example “Boat” results first of “apple” ).

I need to show these data in a table, and I click the sorting criteria clicking on the table’s title that will set paginationState.sort

So I have thought to this solution, but it not sort the capital letter in the right way:

 const [listSorting, setListSorting] = useState([]) 

  useEffect(() => {
    if (applicationList && applicationList > 0) {
      sortingList();
    }
  }, [props.applicationList]);

  const sortingList = () => {
    const list = [...applicationList].sort((a, b) => {
      if (typeof a[paginationState.sort] === 'string') {
        if (paginationState.order === 'asc') a[paginationState.sort].toLowerCase().localeCompare(b[paginationState.sort].toLowerCase());
        if (paginationState.order === 'desc') a[paginationState.sort].toLowerCase().localeCompare(b[paginationState.sort].toLowerCase());
      } else if (typeof a[paginationState.sort] === 'number') {
        if (paginationState.order === 'asc' && a[paginationState.sort] < b[paginationState.sort]) return -1;
        if (paginationState.order === 'desc' && a[paginationState.sort] > b[paginationState.sort]) return 1;
      }
      return 0;
    });
    setListSorting(list);
  };

So in the return I have :

      <div className="table-responsive">
        {listSorting && listSorting .length > 0 ? (
//......

  <tbody>
              {listSorting.map((application, i) => (
                <tr key={`entity-${i}`} data-cy="entityTable">

My array of objects applicationList is like :

applicationList : [
{
 appCod: 1,
 appDescription: 'string'
 appName: 'string'
},
{
 ...... 
},
]

So if click on table’s title appCod the value of paginationState.sort will be equal to ‘appCod’.

What would to obtain:

I have a problem with words that starts with capital letter because they are considered before others.

So I would like to get a sort that allows me to sort them correctly. How could I do?

Recursive method does not terminate execution on return

good day.
I’ve a problem with a method recursive, this method will print a numbers in the window.
the function given a number n, print following a pattern for example:

n= 16, difference = 5

16 11 6 1 -4 1 6 11 16

n= 10, difference = 5

10 5 0 5 10

The code:

function pattern(number,dif,m=0, nI=0) {
    if (m===2) {
        return 0;
    }
    var nI = nI !== 0 ? nI : number;
    if (!(m===2)) {
        document.write(number+' ')
    }

    if (number=== 0 || number < 0){
        pattern(number+dif, dif, 1,nI)
    }
    if (m===0) {
        pattern(number-dif, dif, 0,nI)
    }
    if (m===1) {
        if (nI == number) {
            pattern(false, false, 2,false)
        }
        pattern(number+dif, dif, 1,nI)
    }



}

pattern(10,5)

Basiclly when the number is in ‘n’ again call the function with parameter m = 2, is executed the reurn but it enters in the sum:

    if (m===1) {
        if (nI == number) {
            pattern(false, false, 2,false)
        }
       >>> pattern(number+dif, dif, 1,nI) <<<<
    }