How to use the hasha function in hasha

To help you get started, we’ve selected a few hasha 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 alwaysonlinetxm / rollup-plugin-fill-html / src / index.js View on Github external
fileList.forEach(node => {
				let { type, file } = node;
				let hash = '';
				let code = '';

				if (/\[hash\]/.test(file)) {
					if (file === destPath) {
						// data.code will remove the last line of the source code(//# sourceMappingURL=xxx), so it's needed to add this
						code = data.code + `//# sourceMappingURL=${basename(file)}.map`;
					} else {
						code = readFileSync(file).toString();
					}
					hash = hasha(code, { algorithm: 'md5' });
					// remove the file without hash
					unlinkSync(file);
					file = file.replace('[hash]', hash)
					writeFileSync(file, code);
				}

				const src = isURL(file) ? file : relative(firstDir, file);

				if (type === 'js') {
					let attrs = {src: src};
					let mode = node.mode || defaultmode;
					if (mode) attrs.type = mode;
					attrs = Object.entries(([key, val]) => `${key}="${val}"`).join(' ');
					const script = `\n`;
					// node.inject will cover the inject
					if (node.inject === 'head' || inject === 'head') {
github AlexxNB / svelte-docs / packages / core / builtins / svelte_preprocess_builtins.js View on Github external
function replaceBuiltins(text,filename){
  const used = new Set();
  let uid = 0;

  //current file identificator
  const fid = hasha(filename,{algorithm: 'md5'});
  
  //remve all examples by file id
  ExamplesStore.delete(new RegExp(`Ex_\\d+_${fid}`));
  
   
  // parse blocks in the file
  getBlocks(text).forEach(block => {
    
    if(block.type === 'example') {
      used.add('Example');

      let name = `Ex_${uid++}_${fid}`;
      text = text.replace(
        block.fragment,
        example_replacer(block.content,block.params,name)
      )
github sveltejs / svelte-hackernews / client / rollup.config.js View on Github external
css: componentStyles => {
				let styles = globalStyles.replace( '__components__', componentStyles );

				try {
					fs.mkdirSync( 'client/dist' );
				} catch ( err ) {
					// noop
				}

				if ( dev ) {
					fs.writeFileSync( `client/dist/main.css`, styles );
				} else {
					styles = new CleanCSS().minify( styles ).styles;

					const hash = hasha( styles, { algorithm: 'md5' });
					fs.writeFileSync( `client/dist/main.${hash}.css`, styles );
					fs.writeFileSync( `server/manifests/css.json`, JSON.stringify({ 'main.css': `client/dist/main.${hash}.css` }) );
				}
			}
		}),
github geut / postcss-copy / src / __tests__ / helpers / random-folder.js View on Github external
export default function randomFolder(pathname, title) {
    return path.join('src/__tests__',
        pathname,
        hasha(title, { algorithm: 'md5' })
    );
}
github dosyago / 22120 / archivist.js View on Github external
async function saveResponseData(key, url, response) {
    const origin = (new URL(url).origin);
    let originDir = State.Cache.get(origin);
    if ( ! originDir ) {
      originDir = path.resolve(library_path(), origin.replace(TBL, '_'));
      try {
        await Fs.promises.mkdir(originDir, {recursive:true});
      } catch(e) {
        console.warn(`Issue with origin directory ${path.dirname(responsePath)}`, e);
      }
      State.Cache.set(origin, originDir);
    }

    const fileName = `${await hasha(key, HASH_OPTS)}.json`;

    const responsePath = path.resolve(originDir, fileName);
    await Fs.promises.writeFile(responsePath, JSON.stringify(response));

    return responsePath;
  }
github callstack / haul / packages / haul-core / src / webpack / loaders / assetLoader.ts View on Github external
const hashes = pairs.map(item =>
    hasha(item.content, {
      algorithm: 'md5',
    })
  );
github Yoctol / bottender / bot / DangerousDCGHandlerBuilder.js View on Github external
constructor(name: string, actions) {
    this._key = `__${hasha(name, { algorithm: 'sha256' })}__`;
    this._name = name;
    this._actions = actions;
  }
github terkelg / ramme / src / common / api / user.js View on Github external
const doLogin = async (username, password) => {
  if (typeof user === 'undefined' || !user.hasOwnProperty('hash')) {
    let userData = {
      username: username,
      hash: hasha(username, {
        algorithm: 'md5'
      })
    }
    settings.set('currentUser', userData)
    user = settings.get('currentUser')
  }

  let session = await createSession(user, password)
  return session
}
github speedracer / speedracer / lib / artefacts / race.js View on Github external
constructor(name) {
    this.name = name
    this.id = hasha(name, { algorithm: 'md5' })
    this.ref = `${REF_PREFIX}_${this.id}`
    this.trace = null
  }

hasha

Hashing made simple. Get the hash of a buffer/string/stream/file.

MIT
Latest version published 6 months ago

Package Health Score

76 / 100
Full package analysis