How to use slugify - 10 common examples

To help you get started, we’ve selected a few slugify 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 processing / p5.js-web-editor / server / config / passport.js View on Github external
User.findOne({ username }, (findByUsernameErr, existingUsernameUser) => {
        if (existingUsernameUser) {
          const adj = friendlyWords.predicates[Math.floor(Math.random() * friendlyWords.predicates.length)];
          username = slugify(`${username} ${adj}`);
        }
        // what if a username is already taken from the display name too?
        // then, append a random friendly word?
        if (existingEmailUser) {
          existingEmailUser.email = existingEmailUser.email || primaryEmail;
          existingEmailUser.google = profile._json.emails[0].value;
          existingEmailUser.username = existingEmailUser.username || username;
          existingEmailUser.tokens.push({ kind: 'google', accessToken });
          existingEmailUser.name = existingEmailUser.name || profile._json.displayName;
          existingEmailUser.verified = User.EmailConfirmation.Verified;
          existingEmailUser.save((saveErr) => {
            if (saveErr) {
              console.log(saveErr);
            }
            done(null, existingEmailUser);
          });
github FormidableLabs / react-native-interactions-workshop / app / src / data / index.js View on Github external
.trim()
          .replace('\n', '<p>')
          .replace(/\s+/g, ' ')
          .replace(/<br>/g, '\n')
          .replace(/</p><p>/g, '\n\n')
      : null;

    const duration = event.duration || 0.5; // in hours
    const profile = speaker ? speakerLookup[slugify(speaker)] : undefined;
    const isTalk = !!profile;

    if (!date || (!title &amp;&amp; !speaker)) {
      return null;
    }
    return {
      slug: slugify(`${title} ${getTime(date)}`),
      title: title || speaker,
      isTalk,
      speaker: isTalk ? speaker : null,
      profile,
      company,
      agenda,
      date,
      duration
    };
  })
  .filter(Boolean);
</p>
github frontarm / mdx-util / deprecated-packages / mdxc / src / mdxc.js View on Github external
import MarkdownIt from 'markdown-it'
import slugify from 'slugify'
import Renderer from './jsxRenderer'
import importsToCommonJS from './importsToCommonJS'
import jsx_inline from './jsx_inline'
import jsx_block from './jsx_block'
import text_with_newline from './text_with_newline'


slugify.extend({
  '&gt;': '',
  '&lt;': '',
  '`': '',
})


const DEFAULT_FACTORIES = {
  'wrapper': 'createFactory(\'div\')',
  'codeBlock': '(props, children) =&gt; createElement("pre", props, createElement("code", { dangerouslySetInnerHTML: { __html: children || props.children } }))'
}


function mdJSX(md) {
  // JSX should entirely replace embedded HTML.
  md.inline.ruler.before('text', 'text_with_newline', text_with_newline);
  md.inline.ruler.before('html_inline', 'jsx_inline', jsx_inline);
github streetmix / streetmix / assets / scripts / util / helpers.js View on Github external
export function normalizeSlug (slug) {
  if (!slug) return

  // Remove certain replacements mapped by slugify
  slugify.extend({
    '|': null,
    '%': null,
    $: null
  })

  const slugified = slugify(slug, {
    replacement: '-',
    remove: /[*+=~.,&lt;&gt;(){}'"!?:;@#$%^&amp;*|\\/[\]]/g,
    lower: true
  })

  // Remove any trailing or leading hyphens, which slugify doesn't clean up
  return slugified.replace(/^[-]+|[-]+$/g, '')
}
github reactioncommerce / reaction-devtools / data / methods.js View on Github external
async function addTags() {
  let numOfTags = settings.tags;
  const linkedTagsRatio = 0.2;
  const topLevelRatio = 0.1;
  let batch = Tags.initializeUnorderedBulkOp({useLegacyOps: true});
  for (let i = 0; i &lt; numOfTags; i++) {
    const data = _.cloneDeep(tagTemplate);
    data._id = randomID(10, "aA0");
    data.name = `${faker.commerce.department()}-${randomID(4, 'aA0')}`;
    data.slug = slugify(data.name);
    data.createdAt = new Date();
    data.updatedAt = new Date();
    if (i === Math.round(numOfTags * topLevelRatio)) {
      data.isTopLevel = true
      tags.push(data._id);
    }
    batch.insert(data);
  }
  await batch.execute();
  batch = Tags.initializeUnorderedBulkOp({useLegacyOps: true});
  const linkedTags = numOfTags * linkedTagsRatio;
  for (let i = 0; i &lt; linkedTags; i++) {
    const currentTag = tags[Math.floor(Math.random() * tags.length)]
    const start = Math.floor(Math.random() * tags.length);
    const len = Math.floor(Math.random() * 5);
    const end = (start + len) &gt; tags.length ? tags.length : (start + len)
github lumen-cms / lumen-cms / lib / templates / components / edit / LcArticleListDialog.vue View on Github external
async onSave () {
        let mutation = createGql;
        const variables = {
          title: this.inputField,
          languageKey: this.$store.state.lc.locale.toUpperCase(),
          slug: slugify(this.inputField, { lower: true })
        };
        if (this.selected) {
          variables.id = this.selected;
          mutation = updateGql;
        }
        await this.mutateGql(
          {
            mutation,
            variables,
            refetchQueries: ['allArticleCategories']
          },
          this.selected ? 'updateArticleCategory' : 'createArticleCategory'
        );
      },
      toggleShow () {
github philsturgeon / awesome-earth / src / templates / category.jsx View on Github external
{(link.countries || []).map(code =&gt; {
                                    const country = Countries.fromAlpha2Code(
                                      code.toUpperCase()
                                    );
                                    return (
                                      <span title="{country.name}">
                                        {country.emoji}
                                      </span>
                                    );
                                  })}
github govau / design-system-site / src / layout / component / screenreader.js View on Github external
const Screenreader = ({ headline, speak, _body, _ID, _parseMD, _relativeURL }) =&gt; (
	<div>
		<div>
			<a href="{`#${">#</a>

			<h2>
				{ headline }
			</h2>

			<div>
				<div>
					{ _parseMD( speak ) }
				</div>
			</div>
			<div>
				{ _body }
			</div>
		</div>
	</div>
);

slugify

Slugifies a String

MIT
Latest version published 2 years ago

Package Health Score

82 / 100
Full package analysis