Skip to content

Instantly share code, notes, and snippets.

@klappy
klappy / Tiny JavaScript tokenizer.js
Last active September 16, 2019 20:51 — forked from borgar/Tiny JavaScript tokenizer.js
A compact tokenizer written in JavaScript.
/**
* Tiny tokenizer - https://gist.github.com/borgar/451393
* @param {String} string - string to be tokenized
* @param {Object} parsers - { word:/\w+/, whitespace:/\s+/, punctuation:/[^\w\s]/ }
* @param {String} deftok - type to label tokens that are not classified with the above parsers
* @return {Array} - array of objects => [{ token:"this", type:"word" },{ token:" ", type:"whitespace" }, Object { token:"is", type:"word" }, ... ]
**/
export const classifyTokens = (string, parsers, deftok) => {
string = (!string) ? '' : string; // if string is undefined, make it an empty string
if (typeof string !== 'string') {
@klappy
klappy / SKMultilineLabel.swift
Last active October 11, 2017 03:21 — forked from kevinwo/SKMultilineLabel.swift
Multi line label in Sprite Kit in Swift
//
// SKMultilineLabel.swift
//
// Created by Craig on 10/04/2015
// Modified by Christopher Klapp on 11/21/2015 for line breaks \n for paragraphs
// Copyright (c) 2015 Interactive Coconut. All rights reserved.
//
/* USE:
(most component parameters have defaults)