Skip to content

named colors should return a copy of the result array when using get.rgb("colorName") #85

@d4rya38

Description

@d4rya38

Problem

When using the get.rgb() function with a named color, the returned array is a reference to the underlying mapped colorName to array representation while it should be a copy to it. This creates bugs when you manipulate the result you get from the function, any modification to that result also modified all the returned values from the get.rgb() function when you call it with the same named color.

Steps to reproduce

import colorString from "color-string";

const col1 = colorString.get.rgb("red"); // [255, 0, 0, 1]
console.log("col1:", col1);
col1[0] = 0; // now [0, 0, 0, 1]
console.log("col1 after modification", col1);

const col2 = colorString.get.rgb("red"); // returns [0, 0, 0, 1] while it should be [255, 0, 0, 1]
console.log("col2:", col2);

All the tests have been done on
Window 11 Home 24H2
node v24.1.0 on PowerShell

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions