Sunday

An example of converting object to an array in javascript


const ingredients = {
 salad: 2,
 tomato: 1,
 cheese: 3,
 meat: 2
}

const transformedIngredients = Object.keys(ingredients)
  .map(iKey => {
     return [...Array(ingredients[iKey])].map((_, i) => {
       return iKey ;
   });
}); 

console.log(transformedIngredients.toString());
the output is: salad,salad,tomato,cheese,cheese,cheese,meat,meat

**Object.keys(ingredients) returns key list:   salad,tomato,cheese,meat
**Array(ingredients[iKey])   returns the value of the given key like salad. for instance,the output for salad: Array(2). so the second map loops 2 time and returns salad twice.

enable css loader >> unknown property 'localIdentName' error

versions >>  "css-loader":"3.4.2"

firstly looking: (in the project created by create-react-app which has been ejected)
{
  test: cssRegex,
  exclude: cssModuleRegex,
  use: getStyleLoaders({
 importLoaders: 1,
 sourceMap: isEnvProduction && shouldUseSourceMap,
  }),
  sideEffects: true,
},
I tried: (this one is the older config)
{
  test: cssRegex,
  exclude: cssModuleRegex,
  use: getStyleLoaders({
 importLoaders: 1,
 modules: true,
 localIdentName: "[name]__[local]___[hash:base64:5]",
 sourceMap: isEnvProduction && shouldUseSourceMap,
  }),
  sideEffects: true,
},
i got following error:
./src/index.css (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-3-1!./node_modules/postcss-loader/src??postcss!./src/index.css)
ValidationError: Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
 - options has an unknown property 'localIdentName'. These properties are valid:
   object { url?, import?, modules?, sourceMap?, importLoaders?, localsConvention?, onlyLocals?, esModule? }

FIX:
 {
  test: cssRegex,
  exclude: cssModuleRegex,
  use: getStyleLoaders({
 importLoaders: 1,
 modules: {
   localIdentName: "[name]__[local]___[hash:base64:5]",
 }, 
 sourceMap: isEnvProduction && shouldUseSourceMap,
  }),
  sideEffects: true,
},