UNPKG

abcjs

Version:

Renderer for abc music notation

58 lines (46 loc) 1.45 kB
// abc_parse.js: parses a string representing ABC Music Notation into a usable internal structure. var parseCommon = {}; parseCommon.clone = function(source) { var destination = {}; for (var property in source) if (source.hasOwnProperty(property)) destination[property] = source[property]; return destination; }; parseCommon.cloneArray = function(source) { var destination = []; for (var i = 0; i < source.length; i++) { destination.push(parseCommon.clone(source[i])); } return destination; }; parseCommon.cloneHashOfHash = function(source) { var destination = {}; for (var property in source) if (source.hasOwnProperty(property)) destination[property] = parseCommon.clone(source[property]); return destination; }; parseCommon.cloneHashOfArrayOfHash = function(source) { var destination = {}; for (var property in source) if (source.hasOwnProperty(property)) destination[property] = parseCommon.cloneArray(source[property]); return destination; }; parseCommon.strip = function(str) { return str.replace(/^\s+/, '').replace(/\s+$/, ''); }; parseCommon.startsWith = function(str, pattern) { return str.indexOf(pattern) === 0; }; parseCommon.endsWith = function(str, pattern) { var d = str.length - pattern.length; return d >= 0 && str.lastIndexOf(pattern) === d; }; parseCommon.last = function(arr) { if (arr.length === 0) return null; return arr[arr.length-1]; }; module.exports = parseCommon;