How to use hash-sum - 10 common examples

To help you get started, we’ve selected a few hash-sum 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 vue-styleguidist / vue-styleguidist / packages / vue-styleguidist / src / loaders / utils / parseVue.ts View on Github external
export default function parseVue(source: string, filename: string): compiler.SFCDescriptor {
	const cacheKey = hash(filename + source)
	// source-map cache busting for hot-reloadded modules
	let output = cache.get(cacheKey)
	if (output) {
		return output
	}
	output = compiler.parseComponent(source)
	cache.set(cacheKey, output)
	return output
}
github nuxt / nuxt.js / lib / core / module.js View on Github external
if (!template) {
      throw new Error('Invalid template:' + JSON.stringify(template))
    }

    // Validate & parse source
    const src = template.src || template
    const srcPath = path.parse(src)
    /* istanbul ignore if */
    if (!src || typeof src !== 'string' || !fs.existsSync(src)) {
      throw new Error('Template src not found:' + src)
    }

    // Generate unique and human readable dst filename
    const dst =
      template.fileName ||
      path.basename(srcPath.dir) + `.${srcPath.name}.${hash(src)}` + srcPath.ext

    // Add to templates list
    const templateObj = {
      src,
      dst,
      options: template.options
    }

    this.options.build.templates.push(templateObj)
    return templateObj
  }
github sapegin / fledermaus / test / caches / page.spec.js View on Github external
test('update hash in cache', () => {
		setPageCache({ 'a.html': hashSum('x') });
		isPageUpdated('a.html', 'y');
		expect(getPageCache()).toEqual({ 'a.html': hashSum('y') });
	});
});
github okamilab / nebula / src / Main.jsx View on Github external
getChatParticipants(chat) {
    if (!chat) {
      return [];
    }

    const { account, contacts } = this.state;
    const { publicKey } = account;

    const participants = {
      [sum(publicKey)]: { key: publicKey }
    };

    Object.keys(chat.participants)
      .forEach(k => {
        const contact = contacts[k];
        if (!contact) {
          return;
        }
        participants[k] = contacts[k];
      });

    return participants;
  }
github okamilab / nebula / src / Main.jsx View on Github external
async onMessageSend(key, message) {
    const { account, chats } = this.state;
    const chat = chats.find(c => c.key === key);
    if (!chat) {
      throw new Error('Chat is not found');
    }

    await this.messenger.sendChatMessage(chat.key, chat.topic, { text: message });

    const msg = {
      sender: sum(account.publicKey),
      isRead: true,
      text: message,
      timestamp: Date.now()
    }
    chat.messages[sum(msg)] = msg;

    this.setState({
      chats: [...chats.filter(c => c.key !== key), chat],
    }, this.saveState);
  }
github okamilab / nebula / src / messenger / chats / actions.js View on Github external
return async (event) => {
    const { chats } = getState();
    const hash = sum(event.key);
    const chat = getChat(hash, chats);

    const message = {
      sender: hash,
      isRead: false,
      text: event.payload.text,
      timestamp: event.utc_timestamp,
    }

    const existing = chat.messages[sum(message)];
    if (existing) {
      return;
    }

    dispatch({ type: CHAT_RECEIVE_MESSAGE, hash, message });
  }
}
github okamilab / nebula / src / Main.jsx View on Github external
type: accepted ? 'added' : 'received_declined'
    };

    if (accepted) {
      await this.messenger.subscribeChat(contact, this.onReceiveChatEvent);
    }

    this.setState(
      {
        contacts: { ...contacts, [hash]: contact },
        chats: accepted ? [...chats, {
          key: contact.key,
          topic: contact.topic,
          participants: {
            [sum(contact.key)]: contact.key,
            [sum(account.publicKey)]: account.publicKey,
          },
          messages: {}
        }] : chats,
      },
      this.saveState);
  }
github okamilab / nebula / src / messenger / chats / actions.js View on Github external
async function send(dispatch, client, chat, publicKey, text) {
  const pssMessage = {
    type: 'chat_message',
    payload: { text },
    utc_timestamp: Date.now()
  };
  await client.pss.sendAsym(chat.key, chat.topic, pssMessage);

  const message = {
    sender: sum(publicKey),
    isRead: true,
    timestamp: Date.now(),
    text
  }

  dispatch({ type: CHAT_SEND_MESSAGE, hash: sum(chat.key), message });
}
github saberland / saber / packages / saber / src / plugins / source-pages.ts View on Github external
const handler = (type: 'add' | 'remove' | 'change') => async (
          filename: string
        ) => {
          const filepath = path.join(pagesDir, filename)

          if (type === 'remove') {
            await api.hooks.manipulatePage.promise({
              action: 'remove',
              id: hash(filepath)
            })
          } else {
            const stat = await fs.stat(filepath)
            const file: FileInfo = {
              absolute: filepath,
              relative: filename,
              birthtime: stat.birthtime,
              mtime: stat.mtime,
              content: await fs.readFile(filepath, 'utf8')
            }
            const page = api.pages.fileToPage(file)
            await api.hooks.manipulatePage.promise({ action: 'create', page })
          }

          await api.hooks.onCreatePages.promise()
          await api.hooks.emitPages.promise()
github BuilderIO / builder / packages / react / src / blocks / Symbol.tsx View on Github external
if (!symbol) {
      showPlaceholder = true
    }

    const TagName = this.props.dataOnly
      ? NoWrap
      : (this.props.builderBlock && this.props.builderBlock.tagName) || 'div'

    const { model, entry, data, content, inline, dynamic } = symbol || {}
    if (!(model && (entry || dynamic)) && !inline) {
      showPlaceholder = true
    }

    let key = dynamic ? undefined : [model, entry].join(':')
    const dataString = Builder.isEditing ? null :  data && size(data) && hash(data)

    if (key && dataString && dataString.length < 300) {
      key += ':' + dataString
    }

    const attributes = this.props.attributes || {}
    return (
      
        {state => {
          return (

hash-sum

Blazing fast unique hash generator

MIT
Latest version published 5 years ago

Package Health Score

67 / 100
Full package analysis

Popular hash-sum functions