Best JavaScript code snippet using ng-mocks
Turtle.js
Source:Turtle.js
1class Turtle {2 constructor(className, extendClass)3 {4 this.id = systemId;5 this.className = className;6 this.extendClass = extendClass;7 this.properties = new Map();8 this.prefixes = fillPrefixes();9 }10 getId(){11 return this.id;12 }13 setId(id){14 this.id = id;15 }16 getClassName(){17 return this.className;18 }19 setClassName(className){20 this.className = className;21 }22 getClassExtend(){23 return this.extendClass;24 }25 setClassExtend(extendClass){26 this.extendClass = extendClass;27 }28 addProperty(property, value){29 this.properties.set(property, value);30 }31 getProperties(){32 return this.properties;33 }34 setProperties(properties){35 this.properties = properties;36 }37 getPrefixes(){38 return this.prefixes;39 }40 setPrefixes(prefixes){41 this.prefixes = prefixes;42 }43 getTurtleLines(){44 const lines = [];45 const preNames = this.prefixes.keys();46 for (const name of preNames)47 {48 lines.push("@prefix " + name + ": <" + this.prefixes.get(name) + "> .");49 }50 lines.push("<" + this.className + ">" + " <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> . ");51 lines.push("<" + this.className + ">" + " <http://www.w3.org/1999/02/22-rdf-syntax-ns#label> \""+getURLName(this.className)+"\" . ");52 if((this.extendClass != undefined) && (this.extendClass != null)) {53 if (this.extendClass.length > 0) {54 lines.push("<" + this.className + ">" + " <http://www.w3.org/1999/02/22-rdf-syntax-ns#subClassOf> <"+this.extendClass+"> . ");55 }56 }57 const get_keys = this.properties.keys();58 for (const prop of get_keys)59 {60 lines.push("<" + prop + "> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> ; <http://www.w3.org/1999/02/22-rdf-syntax-ns#label> \""+getURLName(prop)+"\" .");61 lines.push("<"+this.className+"> <http://shacleditor/hasProperty> <"+prop+"> .");62 if((this.properties.get(prop) != undefined) && (this.properties.get(prop) != null)) {63 if (this.properties.get(prop).length > 0) {64 lines.push("<"+this.className+"> <"+prop+"> "+this.properties.get(prop)+" .");65 }66 }67 }68 return lines;69 }70 generateInsert(){71 const lines = [];72 //systemId = -1;73 const preNames = this.prefixes.keys();74 for (const name of preNames)75 {76 lines.push("prefix " + name + ": <" + this.prefixes.get(name) + "> ");77 }78 lines.push("insert data { graph <http://shacleditor#"+ this.getId() +"> { ");79 lines.push("<" + this.className + ">" + " <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> . ");80 lines.push("<" + this.className + ">" + " <http://www.w3.org/1999/02/22-rdf-syntax-ns#label> \""+getURLName(this.className)+"\" . ");81 if((this.extendClass != undefined) && (this.extendClass != null)) {82 if (this.extendClass.length > 0) {83 lines.push("<" + this.className + ">" + " <http://www.w3.org/1999/02/22-rdf-syntax-ns#subClassOf> <"+this.extendClass+"> . ");84 }85 }86 const get_keys = this.properties.keys();87 for (const prop of get_keys)88 {89 lines.push("<" + prop + "> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> ; <http://www.w3.org/1999/02/22-rdf-syntax-ns#label> \""+getURLName(prop)+"\" .");90 lines.push("<"+this.className+"> <http://shacleditor/hasProperty> <"+prop+"> .");91 console.log(this.properties.get(prop));92 if((this.properties.get(prop) != undefined) && (this.properties.get(prop) != null)) {93 if (this.properties.get(prop).length > 0) {94 lines.push("<"+this.className+"> <"+prop+"> \""+this.properties.get(prop)+"\" .");95 }96 }97 }98 let res = "";99 lines.push("} }");100 for (const line of lines)101 {102 res += "\n" + line;103 }104 res = res.trim();105 return res;106 }107 printText(){108 let res = "";109 const lines = this.getTurtleLines();110 for (var line of lines)111 {112 res += "\n" + line;113 }114 res = res.trim();115 if(this.properties.size > 0){116 res = res.substring(0, res.length-2) + ".";117 }118 return res;119 }...
LayoutComponent.js
Source:LayoutComponent.js
1import React, {Component, PropTypes, Children} from 'react';2import _ from 'underscore';34export var RowComponent = React.createClass({5 render: function(){6 let extendClass = this.props.extendClass != undefined ? this.props.extendClass : '';78 return (9 <div className={`row ${extendClass}`}>10 {this.props.children}11 </div>12 );13 }14});1516export var ColComponent = React.createClass({17 render: function(){18 let extendClass = this.props.extendClass != undefined ? this.props.extendClass : '';1920 return (21 <div className={`col-md-${this.props.size} ${extendClass}`}>22 {this.props.children}23 </div>24 );25 }26});2728class PortletComponent extends Component{29 render(){30 let extendClass = this.props.extendClass != undefined ? this.props.extendClass : '';3132 return (33 <div className="portlet light bordered" id={this.props.id}>34 <div className="portlet-title">35 <div className="caption caption-md">36 <span className="caption-subject font-blue-madison bold uppercase">{this.props.title}</span>37 </div>38 <div className="actions">39 {this.props.buttons}40 </div>41 </div>42 <div className={`portlet-body ${extendClass}`}>43 {this.props.children}44 </div>45 </div>46 );47 }48}4950PortletComponent.propTypes = {51 id: PropTypes.string,52 title: PropTypes.string.isRequired,53 extendClass: PropTypes.string,54 buttons: PropTypes.arrayOf(PropTypes.element)55}5657class PortletTabContentComponent extends Component{58 render(){59 return Children.only(this.props.children);60 }61}6263PortletTabContentComponent.propTypes = {64 title: PropTypes.string.isRequired,65 active: PropTypes.bool66};6768class PortletTabComponent extends Component{69 render(){70 let tabs = [];71 let contents = [];7273 this.props.children.forEach(function(component, index){74 let id = _.uniqueId('tab_');75 let title = component.props.title;76 let active = component.props.active != undefined ? component.props.active : false;7778 tabs.push(79 <li key={index} className={active ? 'active' : ''}>80 <a href={`#${id}`} data-toggle="tab">{title}</a>81 </li>82 );83 contents.push(84 <div key={index} className={`tab-pane ${active ? 'active' : ''}`} id={id}>85 {component}86 </div>87 );88 });8990 return (91 <div className="portlet light bordered" id={this.props.id}>92 <div className="portlet-title tabbable-line">93 <div className="caption caption-md">94 <span className="caption-subject font-blue-madison bold uppercase">{this.props.title}</span>95 </div>96 <ul className="nav nav-tabs">97 {tabs}98 </ul>99 </div>100 <div className="portlet-body">101 <div className="tab-content">102 {contents}103 </div>104 </div>105 </div>106 );107 }108};109110PortletTabComponent.propTypes = {111 id: PropTypes.string,112 title: PropTypes.string.isRequired113};114115export {116 PortletComponent,117 PortletTabContentComponent, 118 PortletTabComponent
...
fscript.js
Source:fscript.js
1(function (root, factory) {2 if (typeof define === 'function' && define.amd) {3 define([], factory);4 } else if (typeof module === 'object' && module.exports) {5 module.exports= factory( );6 } else {7 root.fscript = factory();8 }9}(this, function () {10 'use strict';11 12 // use for create a metaclass13 function __makeClass__(classname,extendClass,attr,metaClass){14 if(metaClass){15 var classObj = metaClass.prototype.__new__.apply(this,arguments);16 classObj.prototype.__metaClass__ = metaClass;17 return classObj;18 }else if(extendClass){19 return extendClass.prototype.__metaClass__.prototype.__new__.apply(this,arguments);20 }else{21 return CLASS.prototype.__new__.apply(this,arguments);22 }23 }24 function CLASS(classname,extendClass,attr){25 return CLASS.prototype.__new__.apply(this,arguments);26 }27 CLASS.prototype={28 __new__:function(classname,extendClass,attr){29 var newClass = function(){30 return newClass.prototype.__new__.apply(this,arguments);31 }32 if(extendClass==CLASS){33 //create a meta class34 newClass.prototype = {35 __new__:CLASS.prototype.__new__,36 __attr__:attr,37 __className__:classname,38 __class__: newClass,39 __extendsClasses__:[extendClass],40 __baseClass__:extendClass,41 __metaClass__:CLASS42 };43 attr.apply(newClass.prototype);44 }else{45 //create a normal class46 newClass.prototype = {47 __new__:function(){48 var Obj = {};49 Obj[classname] = function(){};50 newClass.prototype.__attr__.apply(Obj);51 if(arguments.length)52 Obj[classname].apply(Obj,arguments);53 if(extendClass){54 var upper = extendClass.prototype.__new__();55 newClass.prototype.__extendsClasses__=newClass.prototype.__extendsClasses__.concat(extendClass.prototype.__extendsClasses__);56 Obj.upper = upper;57 for(var key in upper){58 if(!Obj[key]){59 Obj[key]=upper[key];60 }61 }62 }63 return Obj;64 },65 __attr__:attr,66 __className__:classname,67 __class__: newClass,68 __extendsClasses__:[extendClass],69 __baseClass__:extendClass,70 __metaClass__:CLASS71 };72 }73 return newClass;74 },75 __attr__:function(){this.CLASS=function(){}},76 __className__:"CLASS",77 __class__:CLASS,78 __baseClass__:null,79 __extendsClasses__:[],80 __metaClass__:CLASS81 };82 function upper(key,obj){83 if(obj.upper)84 return obj.upper[key];85 else86 return null;87 }88 89 return {CLASS:CLASS,__makeClass__:__makeClass__,upper:upper};...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!