How to use the @imgcook/cli-utils.unique function in @imgcook/cli-utils

To help you get started, we’ve selected a few @imgcook/cli-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imgcook / imgcook-cli / packages / @imgcook / cli-loader-images / index.js View on Github external
const loader = async (fileValue, option) => {
  let imgArr = [];
  const { filePath, index } = option;
  const temporaryImages = `${(
    new Date().getTime() + Math.floor(Math.random() * 10000)
  ).toString(30)}`;
  imgArr = fileValue.match(
    /(https?):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|](\.png|\.jpg)/g
  );
  if (imgArr && imgArr.length > 0) {
    imgArr = unique(imgArr);
    const imgPath = `${filePath}/images`;
    let imgObj = [];
    const imgrc = `${imgPath}/.imgrc`;
    if (fs.existsSync(imgrc)) {
      let imgConfig = fs.readFileSync(imgrc, 'utf8');
      imgObj = JSON.parse(imgConfig) || [];
    }
    for (let idx = 0; idx < imgArr.length; idx++) {
      if (!fs.existsSync(imgPath)) {
        fs.mkdirSync(imgPath);
      }
      let suffix = imgArr[idx].split('.');
      suffix = suffix[suffix.length - 1];
      const imgName = `img_${option.moduleData.id}_${index}_${idx}.${suffix}`;
      const imgPathItem = `${imgPath}/${imgName}`;
      let curImgObj = {};

@imgcook/cli-utils

imgcook cli utils

MIT
Latest version published 3 years ago

Package Health Score

43 / 100
Full package analysis

Similar packages