How to use filenamify - 8 common examples

To help you get started, we’ve selected a few filenamify 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 sindresorhus / pageres / lib / index.js View on Github external
uri = path.basename(uri);
		}

		// Strip empty hash fragments: `#` `#/` `#!/`
		if (/^#!?\/?$/.test(hash)) {
			hash = '';
		}

		stream.filename = filename({
			crop: options.crop ? '-cropped' : '',
			date: easydate('Y-M-d'),
			time: easydate('h-m-s'),
			size,
			width: sizes[0],
			height: sizes[1],
			url: filenamifyUrl(uri) + filenamify(hash)
		});

		if (options.incrementalName) {
			stream.filename = unusedFilename.sync(stream.filename);
		}

		return stream;
	}
github magicdawn / yun-playlist-downloader / ts-src / index.ts View on Github external
// name
  format = format.replace(new RegExp(':name', 'ig'), sanitize(name))

  // djradio only
  if (typesItem.type === 'djradio') {
    const programDate = _.get(song, 'raw.programUi.date')
    if (programDate) {
      format = format.replace(new RegExp(':programDate'), sanitize(programDate))
    }

    const programOrder = _.get(song, 'raw.programUi.programOrder')
    if (programOrder) {
      format = format.replace(
        new RegExp(':programOrder'),
        sanitize(programOrder)
      )
    }
  }

  return format
}
github justinlettau / sql-source-control / src / common / file-utility.ts View on Github external
write(dir: string | false, file: string, content: string) {
    if (dir === false) {
      return;
    }

    // remove unsafe characters
    file = filenamify(file);

    if (!this.shouldWrite(file)) {
      return;
    }

    file = path.join(this.config.getRoot(), dir, file);
    content = content.trim();

    const cacheKey = this.normalize(file);
    const cacheValue = checksum(content);
    this.newCache.add(cacheKey, cacheValue);

    if (!this.doesExist(file)) {
      this.stats.added++;
    } else if (this.existingCache.didChange(cacheKey, cacheValue)) {
      this.stats.updated++;
github ivan-dalmet / smart-swatch / src / components / SaveSketchPalette.js View on Github external
onSubmit={(e) => {
            e.preventDefault();
            FileSaver.saveAs(blob, filenamify(`${filename}swatch.sketchpalette`));
            setIsPopoverOpen(false);
            setColorName(defaultName);
          }}
        >
github javascriptair / site / other / utils / download-twitter-photo.js View on Github external
function downloadTwitterPhoto(twitter, destinationDir) {
  twitter = cleanTwitter(twitter)
  const imageName = filenamify(`${twitter}.png`)
  const tempDir = temp.mkdirSync()
  const imgPath = path.join(tempDir, imageName)
  const destinationPath = path.join(destinationDir, imageName)
  getProfileImageURL(twitter)
    .then(downloadImage)
    .catch(logError)

  function downloadImage(imgUrl) {
    request(imgUrl)
      .pipe(fs.createWriteStream(imgPath).on('close', compress))
  }

  function compress() {
    return compressImage(imgPath, destinationPath).then(unlinkImgPath)
  }
github magicdawn / yun-playlist-downloader / ts-src / index.ts View on Github external
;['typeText', 'type'].forEach(t => {
    const val = sanitize(String(typesItem[t]))
    format = format.replace(new RegExp(':' + t, 'ig'), val)
  })
github machawk1 / wail / wail-twitter / monitor / twitterMonitor.js View on Github external
const makeArchiveConfig = (config, tweet) => {
  let name = filenamify(tweet)
  let saveThisOne = `${config.forCol}_${config.account}_${name}_${new Date().getTime()}.warc`
  return {
    type: 'twitter',
    forCol: config.forCol,
    uri_r: tweet,
    saveTo: path.join(S(settings.get('collections.colWarcs')).template({col: config.forCol}).s, saveThisOne),
    header: {
      isPartOfV: config.forCol,
      description: `Archived by WAIL for ${config.forCol}`
    }
  }
}
github BoostIO / BoostNote.next / src / main / lib / db / helpers.ts View on Github external
.reduce((sum, element) => {
      const sanitized = filenamify(element, { replacement: '_' })
      if (sanitized.length > 0) {
        sum.push(sanitized)
      }
      return sum
    }, [] as string[])
    .join('/')

filenamify

Convert a string to a valid safe filename

MIT
Latest version published 7 months ago

Package Health Score

76 / 100
Full package analysis

Popular filenamify functions

Popular JavaScript code snippets

Find secure code to use in your application or website