“MODULE_NOT_FOUND” after npm run server

I just picked up a new book, Fullstack React and when trying to run the example app, I am getting the error of module not found. The modules in question are apparently live-server. Here’s the error message. I’ve done npm install before npm run server and no luck

> live-server public --host=localhost --port=3000 --middleware=./disable-browser-cache.js

internal/modules/cjs/loader.js:892
  throw err;
  ^

Error: Cannot find module './disable-browser-cache.js'
Require stack:
- C:UsersSuleymanAppDataRoamingnpmnode_moduleslive-serverindex.js
- C:UsersSuleymanAppDataRoamingnpmnode_moduleslive-serverlive-server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at C:UsersSuleymanAppDataRoamingnpmnode_moduleslive-serverindex.js:189:10
    at Array.map (<anonymous>)
    at Object.LiveServer.start (C:UsersSuleymanAppDataRoamingnpmnode_moduleslive-serverindex.js:183:13)
    at Object.<anonymous> (C:UsersSuleymanAppDataRoamingnpmnode_moduleslive-serverlive-server.js:174:12)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\Users\Suleyman\AppData\Roaming\npm\node_modules\live-server\index.js',
    'C:\Users\Suleyman\AppData\Roaming\npm\node_modules\live-server\live-server.js'
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] server: `live-server public --host=localhost --port=3000 --middleware=./disable-browser-cache.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] server script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:UsersSuleymanAppDataRoamingnpm-cache_logs2022-03-29T07_43_25_808Z-debug.log
PS C:UsersSuleymanDownloadsfullstack-react-masterfullstack-react-mastervoting_app> ```

How to change the color of an individual element in slidemenu Prime NG

I’m trying to change it through the styleClass attribute inside the object, but it doesn’t work. I can change the color through the span, but then all the elements change color. And I need to mark only one.

enter image description here

<div class="header-document__menu-document">
                <p-button
                    styleClass="p-button-text"
                    icon="pi pi-ellipsis-v"
                    (click)="menu.toggle($event)"
                ></p-button>
                <p-slideMenu
                    #menu
                    appendTo="body"
                    [popup]="true"
                    [model]="documentMenuItems"
                    [viewportHeight]="210"
                    [menuWidth]="250"
                    [style]="{ width: '250px' }"
                    [backLabel]="'back'"
                >
                </p-slideMenu>
</div>

public documentMenuItems: MenuItem[] = [
    {
        label: 'edit rubric',
        icon: 'pi pi-pencil',
        command: _ => this.showWindowEditGroup(),
    },
    {
        label: 'Create rubric',
        icon: 'pi pi-plus',
        command: _ => this.showWindowCreateGroup(),
    },
    {
        label: 'Delete rubric',
        icon: 'pi pi-times',
        command: _ => this.onDeleteGroupButtonClick(),
        styleClass: 'delete-rubric',
    },
];

How to store localStorage values in mysql using php [duplicate]

  for (var i = 0; i < JSvar.length; i++) {
    allTotal = parseFloat(allTotal) + parseFloat(document.getElementById('total' + JSvar[i].id_bills).value);
  }

  document.getElementById('sub_total').value = parseFloat(allTotal).toFixed(2);

  for (var i = 0; i < JSvar.length; i++) {
    if (JSvar[i].id_bills == idBills) {
      JSvar[i].quantity = qty;
      JSvar[i].total = total;
      JSvar[i].sub_total = allTotal;

    }

  }

  var JSvar_serialized = JSON.stringify(JSvar);
  window.localStorage.setItem("Jsvar", JSvar_serialized);
  var JSvar_deserialized = JSON.parse(localStorage.getItem("Jsvar"));
}

here is my code so i want to update Jsvar localStorage data into mysql database

$sql_update = "UPDATE bills SET rate='" . $_POST["rate"] . "', quantity='" . $_POST["qty"] . "', total='" . $_POST["total"] . "', sub_total='" . $_POST["sub_total"] . "', discount='" . $_POST["discount"] . "', total_amt='" . $_POST["total_amt"] . "', recieved_amt='" . $_POST["recieved_amt"] . "', balance='" . $_POST["balance_amt"] . "', updated_date='" . $_POST["date_id"] . "' WHERE invoice_number='" . $_POST["invoice_number"] . "' ";

Regex is unable to find and replace a string containing parentheses

I am attempting to find a sentence in a paragraph (contained in a textarea), and highlight it. All works well if the sentence does NOT contain opening and closing parenthesis, such as the example below. The replace method is unable to replace the string with its equivalent surrounded by the “mark” tags. Can anyone advise how I can update my Regex to find and replace a string containing parentheses? Do I need to find and replace all parentheses with “/(” and “/)” first?

const text = "An economy is composed of suppliers (workers) and demanders (firms)."

const regex = new RegExp(text, "d");
// regex returns: /The market for labor, then, is composed of suppliers (workers) and demanders (firms). /
        console.log("REGEX:", regex);
        let match = text.replace(regex, "<mark>$&</mark>");
        console.log("MATCH:", match);

HTML 5 Validation Customization

I would like to have a form that:

  1. Display validation messages in a custom format instead of the default style.
  2. Display all invalid field bubbles at once instead of one at a time.

Right now, I am stuck with the boring browser-specific message appearance and I don’t see the next error until I correct the last one. This is a really bad user experience, so looking for a few pointers on how to address this.

This is my current JavaScript code:

const contactUsForm = document.querySelector('#Form');

if (contactUsForm) {

    function Validate() {
    
        validatedFields = contactUsForm.querySelectorAll('[data-validation-required],[data-validation-format]');
        validatedFields.forEach(field => {
            /* RegEx patterns */
            const emailPattern = /^((([a-z]|d|[!#$%&'*+-/=?^_`{|}~]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])+(.([a-z]|d|[!#$%&'*+-/=?^_`{|}~]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])+)*)|((x22)((((x20|x09)*(x0dx0a))?(x20|x09)+)?(([x01-x08x0bx0cx0e-x1fx7f]|x21|[x23-x5b]|[x5d-x7e]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])|(\([x01-x09x0bx0cx0d-x7f]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF]))))*(((x20|x09)*(x0dx0a))?(x20|x09)+)?(x22)))@((([a-z]|d|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])|(([a-z]|d|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])([a-z]|d|-|.|_|~|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])*([a-z]|d|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF]))).)+(([a-z]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])|(([a-z]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])([a-z]|d|-|.|_|~|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])*([a-z]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])))$/i;
                
            if (field.getAttribute('type') === 'email')
            {
                field.setAttribute('pattern', emailPattern);
            }


            if (field.validity.valueMissing) {
                field.setCustomValidity(field.dataset.validationRequired);
            }
            else if (field.validity.patternMismatch) {
                field.setCustomValidity(field.dataset.validationFormat);
            }
            else {
                field.setCustomValidity('');
            }

            
            field.reportValidity();
            contactUsForm.checkValidity();


            /* Recheck on field value change */
            field.addEventListener('change', function() {
                field.setCustomValidity('');
                Validate();
            });
        });
    }

    Validate();
    
    
    contactUsForm.addEventListener('submit', function(e) {
        e.preventDefault;
        
        if (e.checkValidity() == false) {
            return false;
        }
        else {
            // form.submit()
        }
    });

}

jquery returning decimals when the answer is 42 [duplicate]

I have a really simple jquery code:

$('#monthly_percent').change(function () {
    // (2/100*70*30) = 42.00000000000001
    $monthly = $('#daily_objective').val()/100*$(this).val()*30;
    if($monthly > 0)
        $('#monthly_objective').val($monthly);
});

The code is working just fine unless the value of $monthly becomes 42, in which case it returns decimals.
So if $('#daily_objective').val() is 2 and $(this).val() is 70, it returns 42.00000000000001.
At the end it is just a matter of transforming the value to an integer, but why does this happen, and why does this happen only when the answer is 42?
I tried a bunch of other numbers but it worked fine.

unable to update object using hooks in react

I have a function that will update my object value depending on the app name using useState hook. But I am not able to use the hook, it gives error invalid hook call.

Any other way to achieve the same will also work.

var myfun = (function() {

  const APP_NAME= "sample app"
  const [object, setObject] = useState({obj: 'value'})

  if(APP_NAME =="sample app") {
        setObject({obj:'new value'})
         console.log('here')
     }
      return obj
});

myfun(); 

While doing selenium, how to do enter key action, on a search bar which has no search button

I’ve been trying to test an ecommerce site after I close the initial popup no elements is captured by

bd.findElement(By.xpath("/html/body/div[5]/div[2]/div[1]/div[4]/div[3]/div/span")).click();

So, I have been using

JavascriptExecutor js = (JavascriptExecutor)bd;
js.executeScript("arguments[0].click();", element);

And after a while I got stuck at a place where I have to do the enter key action. I have been trying various keys for this and none of them seems to work. So, I either need a code for using the enter button event on the search bar using JavascriptExecutor or a solution where I can fetch elements using findElement.

How to change value of dummy data in React Native

I have dummy data for UI testing as belows

let sampleData = [
    {
        name : "Banana",
        isFurit : true,
        volume: 0,
    },
    {
        name : "book",
        isFurit : false,
        volume: 0,
    },
    {
        name : "melon",
        isFurit : true,
        volume: 0,
    },
]

I want to change ‘isFruit’ value when I press button. but it doesn’t work.

{sampleData.map((data, index) => {
  const {name,isFruit,volume} = data
    return (
.
.
<TouchableOpacity onPress={(isFruit) => (!isFruit)} style={{marginLeft: 5}}>

Unexpected splice() result [duplicate]

I was expecting the result to be an array [1, 3, 1, 3], but instead it’s returning the number which was supposed to be removed. jsfiddle https://jsfiddle.net/Montinyek/a8bpuf9v/17/

The same kind of method worked fine for a slightly different problem https://jsfiddle.net/Montinyek/ty19szmL/
What gives?

function destroyer(arr, b) {
    for(let i = 0; i < arr.length; i++) {
      if(b === arr[i]) {
        return arr.splice(i, 1)
      }
    }
  return arr
}

console.log(destroyer([1, 2, 3, 1, 2, 3], 2));

How to hide input tag when using window.print()

When using window.print(), I want to hide the ‘print page’ button, input tags and only print the ‘s-wrapper’ area. However, during print preview, input tag without css applied is printed on the preview screen. How to remove input tag?

If I print without specifying a specific area, the ‘s-box’ does not fill the A4 paper and is not printed in the center, and the box is printed on top.

[html]

<button onclick="printthispage()" class="no-print">print page</button>
<div class="s-wrapper" id="print">
    <div class="s-box">
        {% for p in page %}
            {% if p== 'S' and p.slide_number == 1 %} <img src="{{ p.slide.url }}" class="s-page"> {% endif %}
        {% endfor %}
        <input class="no-print S_{{ image.id }}_top1" value="{{ image.s }}">
        <input class="no-print S_{{ image.id }}_top2" value="{{ image.o }}">
        <input class="no-print S_{{ image.id }}_top3" value="{{ image.e }}">
        <input class="no-print S_{{ image.id }}_top4" value="{{ image.t }}">
        <button class="no-print S_{{ image.id }}_det">Detail</button>
    </div>
</div>

<script type="text/javascript">
function printthispage() {
    window.print();
}
function beforePrint() {
    initBodyHtml = document.body.innerHTML;
    document.body.innerHTML = document.getElementById('print').innerHTML;
}
function afterPrint() {
    document.body.innerHTML = initBodyHtml;
}


window.onbeforeprint = beforePrint;
</script>

[css]

@page {
    size: A4 landscape;
    margin:0;
}
@media print{
   .no-print {
       visibility: hidden;
   }
}

.s-page{
    width: 100%;}

.s-wrapper{
    width: 78%;
    margin: 20px auto;}

.s-box{
    position: relative;
    border: 1px solid black;}


input[class$="S_{{ image.id }}_top1"] {
    position: absolute;
    width: 4%;
    top: {{ link.link_top }}%;
    left: {{ link.link_left }}%;
    right: {{ link.link_right }}%;
    bottom: {{ link.link_bottom }}%;}

input[class$="S_{{ image.id }}_top2"] {
    position: absolute;
    width: 4%;
    top: {{ link.link_top }}%;
    left: {{ link.link_left|add:4 }}%;
    right: {{ link.link_right|add:-4 }}%;
    bottom: {{ link.link_bottom }}%;}

input[class$="S_{{ image.id }}_top3"] {
    position: absolute;
    width: 4%;
    top: {{ link.link_top }}%;
    left: {{ link.link_left|add:8 }}%;
    right: {{ link.link_right|add:-8 }}%;
    bottom: {{ link.link_bottom }}%;}

input[class$="S_{{ image.id }}_top4"] {
    position: absolute;
    width: 4%;
    top: {{ link.link_top }}%;
    left: {{ link.link_left|add:12 }}%;
    right: {{ link.link_right|add:-12 }}%;
    bottom: {{ link.link_bottom }}%;}

input[class$="S_{{ image.id }}_top5"] {
    position: absolute;
    width: 4%;
    top: {{ link.link_top }}%;
    left: {{ link.link_left|add:16 }}%;
    right: {{ link.link_right|add:-16 }}%;
    bottom: {{ link.link_bottom }}%;}

button[class$="S_{{ image.id }}_det"] {
    background-color: #4CAF50;
    color: white;
    cursor: pointer;
    border: none;
    border-radius: 10%;
    padding: 0.5%;

    position: absolute;
    top: {{ link.link_top }}%;
    left: {{ link.link_left|add:20 }}%;
    right: {{ link.link_right|add:-20 }}%;
    bottom: {{ link.link_bottom }}%;}

Pixi.js How to remove sprite after its render , how to rotate sprite

Im trying to clone this website : https://art4globalgoals.com/

Well, I’ve implement scratch card as below, but I can’t figure out how to automatically

trigger dragging event on screen, and erase it. I’ve read Pixi document about renderer or sprite, but couldn’t find idea about it….

I’ll be very grateful if you guys give any hint or suggestion or examples about it..

Also, I want to rotate my brush depending of my movement of mouse.

The idea was to create a vector of my mouse movement, and make a dot product with vector of (1,0) then get the angle, then apply rotation by angle. but whenever I apply angle to it, result seems chaotic.

below , is my code, and results(without rotation applied , with rotation applied)

import * as PIXI from 'pixi.js';
import { Point } from '@pixi/math';

let currentVector = new Point(1, 0);

currentVector = currentVector.set(1, 0);
const screenSize = {
    width: window.innerWidth,
    height: window.innerHeight
};
let brushWidth = (window.innerHeight / window.innerWidth) * 150;
let brushHeight = (window.innerHeight / window.innerWidth) * 200;

const app = new PIXI.Application({
    width: window.innerWidth,
    height: window.innerHeight,
    resolution: window.devicePixelRatio,
    autoDensity: true
});

document.body.appendChild(app.view);

app.loader
    .add('background', '/jpeg/mask.jpeg')
    .add('mask', '/png/effel-gray.png')
    .add('bristle1', '/png/brush6.png')
    .add('bristle2', '/png/bristle2.png')
    .load(() => {
        setup();
    });

const setup = () => {
    const brushTexture = app.loader.resources.bristle1.texture;
    // const brushTexture2 = app.loader.resources.bristle2.texture;

    const brush = new PIXI.Sprite(brushTexture);
    // const brush2 = new PIXI.Sprite(brushTexture2);

    brush.width = brushWidth;
    brush.height = brushHeight;
    brush.anchor.set(0.5, 0.5);

    // brush2.width = brushWidth;
    // brush2.height = brushHeight;

    const backgroundTexture = app.loader.resources.background.texture;
    const maskTexture = app.loader.resources.mask.texture;
    const background = new PIXI.Sprite(backgroundTexture);
    background.x = app.renderer.screen.width / 2;
    background.y = app.renderer.screen.height / 2;
    background.anchor.x = 0.5;
    background.anchor.y = 0.5;
    background.width = window.innerWidth;
    background.height = window.innerHeight;

    const mask = new PIXI.Sprite(maskTexture);
    mask.width = app.renderer.screen.width;
    mask.height = app.renderer.screen.height;
    mask.x = app.renderer.screen.width / 2;
    mask.y = app.renderer.screen.height / 2;
    mask.anchor.x = 0.5;
    mask.anchor.y = 0.5;
    mask.width = window.innerWidth;
    mask.height = window.innerHeight;

    app.stage.addChild(mask);
    app.stage.addChild(background);

    const renderTexture = PIXI.RenderTexture.create(app.screen.width, app.screen.height);

    const renderTextureSprite = new PIXI.Sprite(renderTexture);

    app.stage.addChild(renderTextureSprite);

    background.mask = renderTextureSprite;

    app.stage.interactive = true;
    app.stage.on('pointerdown', pointerDown);
    app.stage.on('pointerup', pointerUp);
    app.stage.on('pointermove', pointerMove);

    let dragging = false;
    let bristle2Render = false;

    let vector;
    function pointerMove(event) {
        if (dragging) {
            brush.position.copyFrom(event.data.global);

            brush.width += 1;

            const vx = event.data.global.x - currentVector.x;
            const vy = event.data.global.y - currentVector.y;
            vector = new Point(vx, vy);
            vector = vector.set(vx, vy);

            const dotProd = vector.x;
            const magnitude = Math.sqrt(vector.x * vector.x + vector.y * vector.y);
            const angle = Math.acos(dotProd / magnitude);
            currentVector = currentVector.set(event.data.global.x, event.data.global.y);

            app.renderer.render(
                brush,
                {
                    renderTexture,
                    transform: new PIXI.Matrix().rotate(angle),
                    clear: false
                },
                false,
                null,
                false
            );

            // if (bristle2Render) {
            //  brush2.position.copyFrom(event.data.global);
            //  app.renderer.render(brush2, renderTexture, false, null, false);
            // }

            // if (brush.width === 100) {
            //  dragging = false;
            //  brushWidth = 0;
            // }
        }
    }

    function pointerDown(event) {
        dragging = true;
        pointerMove(event);
    }

    function pointerUp(event) {
        dragging = false;
        bristle2Render = false;
        brush.width = brushWidth;
    }

    window.addEventListener('resize', () => {
        screenSize.width = window.innerWidth;
        screenSize.height = window.innerHeight;

        app.renderer.resize(window.innerWidth, window.innerHeight);
        app.renderer.stage.width = window.innerWidth;
        app.renderer.stage.height = window.innerHeight;
    });
};

Result without rotation

Result with rotation

How to escape * in regex password pattern

I use validate.js for form validation and have a password pattern where I would like to allow only one of the following special characters: -!@_#+

Password pattern is as below:

 password1: {
  pattern:/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[-!@_#+])(?=.{8,})/
},

However, when I enter *, $ or % character as password input no error message is given. Any help would be appreciated.
Thank you.