Issue Uppercase in .liquid

I want to put a capital letter at the beginning of each word in the variable {{ article.author }} thanks to the script at the bottom of the page which works because I am fetching the variable with capital letters in the console.

enter image description here

But I don’t poorly understand the variable is displayed in uppercase on the site.

Name of author in uppercase

Do you have an idea ?

{%- if article and article != empty -%}
  {%- liquid
    assign ratio = 1
    if media_aspect_ratio != nil
      assign ratio = media_aspect_ratio
    endif
  -%}
  <div class="card-wrapper underline-links-hover">
    {% comment %} <article aria-labelledby="Article-{{ article.id }}"> {% endcomment %}
    <div class="card article-card
      card--{{ settings.card_style }}
      {% if media_height and media_height != 'adapt' %} article-card__image--{{ media_height }}{% endif %}
      {% if article.image and show_image %} card--media{% else %} card--text{% endif %}
      {% if settings.card_style == 'card' %} color-{{ settings.card_color_scheme }} gradient{% endif %}
      {% if settings.card_style == 'card' and media_height == nil and article.image == empty or show_image == false %} ratio{% endif %}"
      style="--ratio-percent: {{ 1 | divided_by: ratio | times: 100 }}%;"
    >
      <div class="card__inner {% if settings.card_style == 'standard' %} color-{{ settings.card_color_scheme }} gradient{% endif %}{% if article.image and show_image or settings.card_style == 'standard' %} ratio{% endif %}" style="--ratio-percent: {{ 1 | divided_by: ratio | times: 100 }}%;">
        {%- if show_image == true and article.image -%}
          <div class="article-card__image-wrapper card__media">
            <div class="article-card__image media media--hover-effect" {% if section.settings.media_height == 'adapt' %} style="padding-bottom: {{ 1 | divided_by: article.image.aspect_ratio | times: 100 }}%;"{% endif %}>
              {% comment %}theme-check-disable ImgLazyLoading{% endcomment %}
              <img
                srcset="{%- if article.image.src.width >= 165 -%}{{ article.image.src | image_url: width: 165 }} 165w,{%- endif -%}
                  {%- if article.image.src.width >= 360 -%}{{ article.image.src | image_url: width: 360 }} 360w,{%- endif -%}
                  {%- if article.image.src.width >= 533 -%}{{ article.image.src | image_url: width: 533 }} 533w,{%- endif -%}
                  {%- if article.image.src.width >= 720 -%}{{ article.image.src | image_url: width: 720 }} 720w,{%- endif -%}
                  {%- if article.image.src.width >= 1000 -%}{{ article.image.src | image_url: width: 1000 }} 1000w,{%- endif -%}
                  {%- if article.image.src.width >= 1500 -%}{{ article.image.src | image_url: width: 1500 }} 1500w,{%- endif -%}
                  {{ article.image.src | image_url }} {{ article.image.src.width }}w"
                src="{{ article.image.src | image_url: width: 533 }}"
                sizes="(min-width: {{ settings.page_width }}px) {{ settings.page_width | minus: 100 | divided_by: 2 }}px, (min-width: 750px) calc((100vw - 130px) / 2), calc((100vw - 50px) / 2)"
                alt="{{ article.image.src.alt | escape }}"
                class="motion-reduce"
                {% unless lazy_load == false %}loading="lazy"{% endunless %}
                width="{{ article.image.width }}"
                height="{{ article.image.height }}"
              >
              {% comment %}theme-check-enable ImgLazyLoading{% endcomment %}
            </div>
          </div>
        {%- endif -%}
        <div class="card__content">        
          <div class="card__information">
            <h3 class="card__heading{% if show_excerpt %} h2{% endif %}">
              <a href="{{ article.url }}" class="full-unstyled-link">
                {{ article.title | truncate: 50 | escape }}
              </a>
            </h3>
            <div class="article-card__info caption-with-letter-spacing h5">
              {%- if show_date -%}
                <span class="circle-divider">{{ article.published_at | time_tag: '%d/%m/%Y' }}</span>
              {%- endif -%}
              {%- if show_author -%}
                <span id="blog_author">{{ article.author }}</span>
              {%- endif -%}
            </div>
            {%- if show_excerpt -%}
              {%- if article.excerpt.size > 0 or article.content.size > 0 -%}
                <p class="article-card__excerpt rte-width">
                  {%- if article.excerpt.size > 0 -%}
                    {{ article.excerpt | strip_html | truncatewords: 30 }}
                  {%- else -%}
                    {{ article.content | strip_html | truncatewords: 30 }}
                  {%- endif -%}
                </p>
              {%- endif -%}
              <div class="article-card__footer">
                {%- if article.comments_count > 0 and blog.comments_enabled? -%}
                  <span>{{ 'blogs.article.comments' | t: count: article.comments_count }}</span>
                {%- endif -%}
              </div>
            {%- endif -%}
          </div>
          {%- if show_badge -%}
            <div class="card__badge {{ settings.badge_position }}">
              <span class="badge color-background-1">{{ 'blogs.article.blog' | t }}</span>
            </div>
          {%- endif -%}
        </div>
      </div>
      <div class="card__content">
        <div class="card__information">
          <h3 class="card__heading{% if show_excerpt %} h2{% endif %}">
            <a href="{{ article.url }}" class="full-unstyled-link">
              {{ article.title | truncate: 50 | escape }}
            </a>
          </h3>
          <div class="article-card__info caption-with-letter-spacing h5">
            {%- if show_date -%}
              <span class="circle-divider">{{ article.published_at | time_tag: '%d/%m/%Y' }}</span>
            {%- endif -%}
            {%- if show_author -%}
              <span id="blog_author">{{ article.author }}</span>
            {%- endif -%}
          </div>
          {%- if show_excerpt -%}
            {%- if article.excerpt.size > 0 or article.content.size > 0 -%}
              <p class="article-card__excerpt rte-width">
                {%- if article.excerpt.size > 0 -%}
                  {{ article.excerpt | strip_html | truncatewords: 30 }}
                {%- else -%}
                  {{ article.content | strip_html | truncatewords: 30 }}
                {%- endif -%}
              </p>
            {%- endif -%}
            <div class="article-card__footer">
              {%- if article.comments_count > 0 and blog.comments_enabled? -%}
                <span>{{ 'blogs.article.comments' | t: count: article.comments_count }}</span>
              {%- endif -%}
            </div>
          {%- endif -%}
        </div>
        {%- if show_badge -%}
          <div class="card__badge {{ settings.badge_position }}">
            <span class="badge color-background-1">{{ 'blogs.article.blog' | t }}</span>
          </div>
        {%- endif -%}  
      </div>
    </div>
  </div>
{%- endif -%}


<script>
var span = document.getElementById("blog_author").innerText.toLowerCase().replace(/b(w)/g, x => x.toUpperCase());
  console.log(span);
</script>

is there a way to store my svelte store in local storage so it doesn’t reset on page refresh?

the content I fetch from my svelte store disappears on page refresh, is there a way to stop it from resetting so it can stay on the page even when i reload? sorry if the question is a little vague im not sure how to really phrase it.

svelte store

import { writable } from "svelte/store";

export const leagueTable = writable([]);

const fetchTable = async () => {
    const url = `https://soccer.sportmonks.com/api/v2.0/standings/season/19734?api_token=API_KEY`;
    const res = await fetch(url);
    const data = await res.json();
    leagueTable.set(data.data);
}
fetchTable();

component

<script>
    import { leagueTable } from "../stores/league-standings-stores"
    console.log($leagueTable)
    const tableMaps = $leagueTable.map($leagueTable => $leagueTable.standings.data).flat();
    console.log(tableMaps)
</script>

{#each tablePositions as tablePosition}
  <div class="standings-table flex gap-9 mb-2 pb-4 pt-3 border-b border-[#303041]">
       <div class="team-details flex gap-4 w-full" id="td">
        <p class="w-[18px]">{tablePosition.position}</p>
         <img src="{tablePosition.team.data.logo_path}" alt="" class="w-[1.5em] object-scale-down">
          <p class="">{tablePosition.team_name}</p>
      </div>

      <div class="team-stats flex gap-5 text-left child:w-5 child:text-center w-full">
        <p>{tablePosition.overall.games_played}</p>
        <p>{tablePosition.overall.won}</p>
        <p>{tablePosition.overall.draw}</p>
        <p>{tablePosition.overall.lost}</p>
        <p>{tablePosition.overall.goals_scored}</p>
        <p>{tablePosition.overall.goals_against}</p>
        <p>{tablePosition.total.goal_difference}</p>
        <p>{tablePosition.overall.points}</p>
        <p class="!w-[78px] !text-left">{tablePosition.recent_form}</p>
      </div>
 </div>
{/each}

Parse JSON object to ChartJS using object.keys/object.values

I’m trying to show data from a JSON file to ChartJS, however, my JSON structure is different to what I have seen in previous relatable questions. Check JSON below:

{
    "AAPL": [
        {
            "Q1": -26986,
            "Q2": -168099,
            "Q3": -137101,
            "Q4": -561990
        }
    ]
}

My code is an attempt to use the keys as labels and the values as data:

const xmlhttp4 = new XMLHttpRequest();
const url4 = 'https://api.npoint.io/ee3b3d406810c46c44e0';

xmlhttp4.open('GET', url4, true);
xmlhttp4.send();
xmlhttp4.onreadystatechange = function() {
    if(this.readyState == 4 && this.status == 200) {
        const datapoints = JSON.parse(this.responseText);
        const data1 = datapoints[0]
        const barchart = document.getElementById('insider_positions_barchart').getContext('2d');
        const myBarChartAUD = new Chart(barchart, {
            type: 'bar',
            data: {
                labels: Object.keys(data1),
                datasets: [{
                    label: 'Net Activity',
                    data: Object.values(data1),
                    backgroundColor: [
                        'rgba(0, 255, 255, 0.2)',
                    ],
                    borderColor: [
                        'rgba(0, 255, 255, 1)',
                    ],
                    borderWidth: 3
                }]
            },
            options: {
                plugins: {
                    legend: {
                        display: false
                    }
                },
                maintainAspectRatio: false,
                scales: {
                    y: {
                        ticks: {
                            color: "white"
                        },
                        grid: {
                            display: false
                        }
                    },
                    x: {
                        ticks: {
                            color: "white"
                        },
                        grid: {
                            display: false
                        }
                    }
                }
            }
        })
    }
}

I’m not sure why this isn’t working, I’m guessing it’s to do with how I’m calling the keys & values. Unless I should change the JSON structure perhaps?

Prisma returns when i try to fetch something

I use prisma as ORM to build my expressJs API and when i try to fetch something, like a user below i have an empty JSOn as result. I don’t understand because prisma has good access to my MySQL database (it mapped it well).

`

// route "/users"
app.get('/users/getAll', async (req,res)=>{
    const users = prisma.user.findMany();
    res.send(users);
});

`

I tried to use differents methods on differents table and i have the same result an empty JSON

Import a different module acording to a string given in props

My question is pretty simple : I have some ugly repetitive React imports and rendering code, and couldn’t find a way to make it clean so I am hoping someone already encountered this problem and might know a better solution…

Here is the component I’m trying to make more dynamic :

import { InfoIcon } from '../assets/InfoIcon'

import { DemandsIcon } from '../assets/DemandsIcon'
import { HomeIcon } from '../assets/HomeIcon'
import { MyWorkIcon } from '../assets/MyWorkIcon'
import { PortfoliosIcon } from '../assets/PortfoliosIcon'
import { ProjectsIcon } from '../assets/ProjectsIcon'

export const ModuleIcon = ({ iconName }) => {
  switch (iconName) {
    case 'home':
      return <HomeIcon />
    case 'myWork':
      return <MyWorkIcon />
    case 'projects':
      return <ProjectsIcon />
    case 'portfolios':
      return <PortfoliosIcon />
    case 'demands':
      return <DemandsIcon />
    default:
      return <InfoIcon />
  }
}

Here, all the components I am importing are just a component that return an

If you need more info, I am available 🙂

I didn’t find any other solution as I just don’t understand how to import according to a string given in props

How to create a function for desktop only?

I have an event listener that is currently being triggered on mousemove. However i want this to only be applied to desktop and not mobile.

And vice versa, for my own reference how would I apply it to mobile only if I wanted to?

Here is my function wrapped around an if statement that if the innerWidth is more than 1000, to trigger add the event listener on mousemove. however I still see it being applied to mobile.

    if (window.innerWidth > 1000) {
    document.addEventListener("mousemove", debounce(inactiveUser, 10000));
    }

If it’s helpful, I am triggering an action event being sent to a tool we use for analytics and campaigns called Evergage. The function is below, along with a console log that I added:

    const inactiveUser = () => {
        console.log("mouse move on desktop only");
        sendEvent({
            action: "Inactive Checkout",
        });
    };

Incorrect integer value: ‘Rpu00a05.000’ for column `db_percetakan`.`mst_produk`.`harga_produk`

I experienced an error when I was about to enter the Harga Dasar using the IDR format
w

input

<input class="form-control input-currency" name="harga_produk" type="text" type-currency="IDR" placeholder="Rp" required>

my Controller

public function store(Request $request) {
    $produk = Produk::create($request->all());

    return response()->json('Data berhasil Disimpan', 200);
}

format money javascript

document.querySelectorAll('input[type-currency="IDR"]').forEach((element) => {
  element.addEventListener('keyup', function(e) {
  let cursorPostion = this.selectionStart;
    let value = parseInt(this.value.replace(/[^,d]/g, ''));
    let originalLenght = this.value.length;
    if (isNaN(value)) {
      this.value = "";
    } else {    
      this.value = value.toLocaleString('id-ID', {
        currency: 'IDR',
        style: 'currency',
        minimumFractionDigits: 0
      });
      cursorPostion = this.value.length - originalLenght + cursorPostion;
      this.setSelectionRange(cursorPostion, cursorPostion);
    }
  });
});

groupBy based on range of values using RxJS in angular

I have a raw data array

[ {bugid: b1 , state: 'foo', days: 2}, {bugid: b2, state: 'bar', days: 41}, {bugid: b3, state: 'foo', days: 45} ]

I want to group this data using RxJS in this format

{ '0-25': [{ name: foo, value: 1}, {name: bar, value: 0}], '26-50': [{name: foo, value: 1}, {name: bar, value: 1}] }

I am not able to group in the range

How to make workbox work in localhost with create-react-app?

I am using create-react-app v5.0.1 and workbox with version

"workbox-background-sync": "^6.4.2",
"workbox-broadcast-update": "^6.4.2",
"workbox-cacheable-response": "^6.4.2",
"workbox-core": "^6.4.2",
"workbox-expiration": "^6.4.2",
"workbox-google-analytics": "^6.4.2",
"workbox-navigation-preload": "^6.4.2",
"workbox-precaching": "^6.4.2",
"workbox-range-requests": "^6.4.2",
"workbox-routing": "^6.4.2",
"workbox-strategies": "^6.4.2",
"workbox-streams": "^6.4.2",

according to the file generated in serviceWorkerRegisteration.ts, it doesn’t support localhost development even after I removed the checks it still not working in localhost.

I have to build the app to check small changes and it takes a lot of time, is there any workaround to make it work locally?

ReactJs – CheckBox atualizar estado

Possuo um array com objetos para renderizar alguns checkBox. Porém quando chamo a função onClick ou onChange meu e.target.value fica como “on”, preciso saber o valor de qual elemento foi clicado para atualizar meu estado do array com o novo valor do checkbox.

let arrayNiveis = [
        {
            id: 1,
            codigo: 16,
            filhos: [
                {
                    id: 2,
                    codigo: 17,
                    filhos: null,
                    marcado: false,
                    menu: 1,
                    nivel: 1,
                    nome: "Listar",
                    opcao: 2,
                    pai: 1
                },
                {
                    id: 3,
                    codigo: 19,
                    filhos: null,
                    marcado: false,
                    menu: 1,
                    nivel: 2,
                    nome: "Disponível",
                    opcao: 2,
                    pai: 1
                }
            ],
            marcado: false,
            menu: 1,
            nivel: 0,
            nome: "MANUTENÇÃO DE SERIAIS",
            opcao: 2,
            pai: null
        }
    ];

const handleCheckBox = (e: any) => {
        console.log("entro no check")
        arrayGrupoNiveis.map((nivelItem: any) => (
            nivelItem.codigo == e.target &&
            nivelItem.filhos.map((filho: any) => (
                filho.codigo == e.target &&
                (filho.marcado = !filho.marcado)
            ))
        ))
    };

return (
<FormProvider>
  {
    arrayGrupoNiveis.map((nivelItem: any) => (
      nivelItem.menu == 1 ?
        {
          nivelItem.filhos.map((filho: any) => (
            <Box sx={{ marginLeft: 4 }}>
              <FormControlLabel
                control={
                  <Checkbox
                    checked={filho.marcado}
                    size="small"
                    onClick={handleCheckBox}
                  />}
                label={filho.nome}
              />
              </FormControlLabel>
            </Box>
           ))
        }
      :
      <Box>
      </Box>
    ))
  }
</FormProvider >
    );

Tentei passar o codigo do pai e do filho porem ele atualiza todos os valores, preciso atualizar somente o elemento que for clicado.

How to access a device webcam and auto save the frames into the device without clicking any single button for capturing and saving?

I am working on a project which takes video input from user and puts the prediction and sends the video frames to the users. As it is easy on my device as it does not need any permission to access. But when it comes to the client side it asks for capturing and saving the frames which is a irritating task. I want a solution that it has to take the device camera permission and autosave the video frames into the device.

I tried opening the device camera using python OpenCV. It works fine with my system, but when it comes to the deployment stage python is unable to open the user device camera. I am searching for a solution which can open device camera using Javascript and autosave the video frames into the device without any single click for capturing and saving the frames.

React router with dynamic array

I want to create a dynamic router based on my page list. But I can’t define my components.
Link path and component names are coming to my list.
Is there any solution to this?

import Home from "../pages/Home";

import BannerManagement from "../pages/BannerManagement";

My page list in App.js

const pageList= [
  {
    path: "home",
    element: "Home",
  },
  {
    path: "BannerManagement",
    element: "BannerManagement",
  }
];

in App.js

ReactDOM.render(
        <Router>
            <BrowserRouter>
              {
                pageList.map(page=>{
                return (<Route exact path={"/"+page.path} component={page.element}/>)
              })
            }
            </BrowserRouter>
      </Router>,document.getElementById('root'));

validating date format in the formats of us and euro [duplicate]

I am defiately a noob in regex, i had the code which is working good but the problem is that validation of date is not perfect, it checks for 2 disits of date and 2 digits of month and 2 digits of year but i want to have a proper validation of date using a regex, even my code works but it is missing the validation of date,

Many will suggest to use date field, but as per requirement, i cannot do so.

Here is the fiddle i have

https://jsfiddle.net/05oe4hzn/

Fiddle code is here

<form action="">
  <input class="startDate date" data-message="Invalid start date" 
  placeholder="DD/MM/YYYY" />
  <input class="endDate date" data-message="Invalid end date"
  placeholder="DD/MM/YYYY" />
  <input type="submit">
</form>
<hr/>
<form action="">
  <input class="startDate date" data-message="Invalid start date" 
  placeholder="MM/DD/YYYY" />
  <input class="endDate date" data-message="Invalid end date"
  placeholder="MM/DD/YYYY" />  
  <input type="submit">
</form>

and a JS Code

const dateRegex = {
  "MM/DD/YYYY": /(?<month>d{2})/(?<day>d{2})/(?<year>d{4})/,
  "DD/MM/YYYY": /(?<day>d{2})/(?<month>d{2})/(?<year>d{4})/
};
const getDate = (dateString, format) => {
  const result = dateRegex[format].exec(dateString);
  if (!result) return -1;
  const { year,month,day } = result.groups; // spread
  const date = new Date(year, month-1, day, 15, 0, 0, 0);
  console.log(dateString,year,month,day,"n",date)
  return isNaN(date) ? -1 : [date, +year, +month, +day]; // return date and parts
};

const validateDate = formElement => {
  const value = formElement.value.trim();
  if (value === "") return true; // only test actual values
  const dateValid = getDate(value, formElement.placeholder)
  if (dateValid === -1) return false; // not matching format
  const [date, year, month, day] = dateValid;
  console.log(date.getFullYear(),"===",year,date.getMonth(),"===",(month - 1),date.getDate(),"===",day); // remove this after testing
  return date.getFullYear() === year && 
         date.getMonth() === (month - 1) && 
         date.getDate() === day;
};
$("form").on("submit", function(e) { // passing the submit event
  $(".date",this).each(function() { // only the dates in this form
    if (!validateDate(this)) {
      alert($(this).data("message"));
      $(this).focus();
      e.preventDefault(); 
      return false; // stop processing dates
    }  
  })
})