Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <input id="finder" type="text" placeholder="search term">

<ul id="list"></ul>
              
            
!

CSS

              
                input {
  box-sizing: border-box;
  font-size: 2rem;
  padding: 1rem;
  display: block;
  margin: 2rem auto;
}

ul {
  list-style: none;
  text-align: center;
  margin: 0;
  padding: 0;
}

li {
  color: #666;
  strong { color: #000; }
  + .label { margin-top: 1rem; }
  &.label {
    color: #CCC;
    text-transform: uppercase;
    font-size: 0.8em;
    letter-spacing: 0.0125em;
    margin-bottom: 0.25rem;
  }
}
              
            
!

JS

              
                //////////////
// usage
//////////////

var finder = document.querySelector("#finder"),
    list   = document.querySelector("#list"),
    lib    = library();

finder.addEventListener("keyup", onKeydown);

// basic usage
function onKeydown(e) {
  if(!e.target.value) { list.innerHTML = ''; return; }
  var results = FS.search(e.target.value, lib);
  if(results.success) { 
    outputSearchResults(results);
    console.log(results);
  } else {
    console.error(results);
  }
}



// handling search results
function outputSearchResults(results) {
  // clear list
  list.innerHTML = '';

  // you deleted the last letter, do nothing more
  if(results.count === lib.length) return;
  
  // label exact
  if(results.exact.length) label(list, 'Exact Matches');
  // spit out exacts
  outputMatches(results.exact);
  
  // no need to go further unless fuzzy
  if(!results.fuzzy.length) return;

  // label fuzzy
  if(results.fuzzy.length) label(list, 'Fuzzy Matches');
  // spit out fuzzies
  outputMatches(results.fuzzy);
}

// outputting matches
function outputMatches(matchesArray) {
  matchesArray.forEach((match) => {
    var el = document.createElement('li');
    match._substrings.forEach((str) => {
      if(str.match) {
        el.innerHTML += `<strong>${str.str}</strong>`;
      } else {
        el.innerHTML += str.str;
      }
    });
    list.appendChild(el);
  });
}

// labeling output
function label(list, text) {
  var line = document.createElement('li');
  line.innerHTML = text;
  line.className = 'label';
  list.appendChild(line);
}

// we would probably sort these names by last touched so that "recent" has value
// it will still prefer an exact match over a fuzzy, 
// but each would be sorted by this order
function library() {
  return [
    'illamon','fragment','latterly','dysgenics','zupus','lecuona','gawkiness','unspiced','lymphoma','payable','befouler','tribune','hespera','natality','chowhound','norene','kelebe','datolite','splay','convey','sita','artemisia','gasolene','epicurean','pretext','deschutes','elkanah','cantal','jar','portiere','trainpipe','limbate','silage','cissy','nip','fubsiest','inhale','fusilier','unfunded','yapper','scheele','jiva','saturator','catalyst','telephony','abby','kazachok','tuileries','judah','boiardo','unlotted','terry','charvaka','beguiler','thorburn','speiss','similarly','target','overcame','unshaking','pyrexia','mangonel','heath','monaural','proexpert','strobila','subchaser','daric','gregg','rattly','ladd','unrayed','kastro','metol','syce','mood','rsvp','hornsby','perutz','steeper','tephrite','flabbier','kikuyu','slopshop','marciano','packer','ungalled','grenfell','crosstree','horrocks','pulpiest','evert','unscribed','shamrock','promote','raking','kahuna','glassy','tippable'
  ];
}

              
            
!
999px

Console