Best JavaScript code snippet using storybook-root
ViolenceSearch.js
Source: ViolenceSearch.js
1/**2 * Created on 2011-12-153 * @author: willian12345@126.com4 * @desc: å¹é
è¾å
¥æ¡å
è¾å
¥çæ°æ®æåºåè¿åæ°ç»5 * @version: 1.06 * 1.1 æ·»å åæå¡å¨è¯·æ±åè¡¨æ°æ®çåè½ by wangyuefei7 * 1.2 å»¶æ¶åæå¡å¨è¯·æ±æ°æ® by wangyuefei8 * 1.3 ä¿®å¤è¿æ»¤å
³é®åé夿¶ï¼è¿åæ°æ®å®å
¨ä¸è´çbug by chengtingting9 * @eg:10 * ViolenceSearch.init(options);11 * @param1 12 * {13 * input: ä½ çè¾å
¥æ¡,14 * 15 * resource: ä½ çèµæº(jsonæ ¼å¼)16 ä¾å¦ï¼ 17 [{"avatar":"\/misc\/images\/avatars\/0T15420K-7.jpg","userid":"2012","username":"\u72d7\u5b50\u4e8c","location":"\u6d59\u6c5f\u676d\u5dde"},{"avatar":"\/misc\/images\/avatars\/16.jpg","userid":"2013","username":"\u4e8c\u72d7\u5b50","location":"\u6d59\u6c5f\u676d\u5dde"},{"avatar":"\/misc\/images\/avatars\/01135553C-27.jpg","userid":"2014","username":"\u72d7\u72d7\u4e8c\u5b50","location":"\u6d59\u6c5f\u676d\u5dde"}]18 *19 * filter: å·²éæ©çæ°æ®ç¶å®¹å¨20 * filterWord: è¿æ»¤å
³é®å21 * filterKey: è¿æ»¤æ°æ®é¡¹çå¯ä¸id22 * isFilterSelected: æ¯å¦è¿æ»¤,23 * callback: åè°å½æ°ä¸ä¼è¿åæåºåçæ°æ®(对象)24 * descend: æ¯å¦éåºæåº25 * searchUrl:æ·»å åæå¡å¨è¯·æ±åè¡¨æ°æ®çurl by wangyuefei26 * delayTime:å»¶æ¶è¯·æ±æ¶é´27 * }28 * 29 * callback彿°è¡¨è¾¾å¼ç»æè¿ååæ°æ°ç» [Object{index:åºå·,item:{åjson对象}}]30 */31;if(typeof ViolenceSearch == 'undefined'){32 ViolenceSearch = {};33}34ViolenceSearch.init = function(options){35 return new SEARCHER(options);36}37function SEARCHER(options){38 this.currentInput = options.input;39 this.resource = options.resource;40 this.originResource = [].concat(this.resource); //å¾å°ä¸ä¸ªæ°å¯¹è±¡41 this.filter = options.filter;42 this.filterWord = options.filterWord;43 this.filterKey = options.filterKey;44 this.isFilterSelected = options.isFilterSelected;45 this.callback = options.callback;46 this.searchUrl = options.searchUrl;47 this.delayTime = options.delayTime|1;48 this.descend = (options.descend == 'undefined' || options.descend == false) ? false : true;49 this.compactArray = [];50 this.bindChangeEvent();//inputåçæ¹å(å
¼å®¹æµè§å¨)51};52SEARCHER.prototype = {53 onInputChanged: function(_value){54 var that = this;55 var json={};56 json.keyword=_value;57 if(_value != ''){58 if(that.searchUrl){59 $.djax({60 url:that.searchUrl,61 data:json,62 type:'GET',63 dataType:'jsonp',64 success:function(data){65 that.callback(data);66 }67 })68 }else{69 that.getCompactData(_value);70 }71 }else{72 if(that.searchUrl){73 $.djax({74 url:that.searchUrl,75 data:json,76 type:'GET',77 dataType:'jsonp',78 success:function(data){79 that.callback(data);80 }81 })82 }else{83 that.callback();84 }85 }86 },87 bindChangeEvent: function(){ 88 var that = this,time;89 /**å½ç¨æ·å¨<åéå°ä¿¡æ¯æ¡>ä¸è¾å
¥æ¶å®æ¶å¹é
æ¾ç¤ºè¾å
¥**/90 $(that.currentInput).bind($.browser.opera ? "input" : "keyup", function(e){91 if(e.keyCode != 40 && e.keyCode != 38 && e.keyCode != 13){92 var $this=$(this);93 if(time){94 clearTimeout(time);95 }96 time = setTimeout(function(){97 that.onInputChanged($.trim($this.val()));98 },that.delayTime);99 }100 });101 },102 compare: function(object1,object2){103 if(object1.index > object2.index) return 1;104 else if(object1.index < object2.index) return -1;105 else return 0;106 },107 getSelected_userids: function(){//è·å¾å·²éæ©çæ°æ®id108 var filterIDs = [];109 var spans = $(this.filter).find('span');110 var spansLength = spans.length;111 for(var i=0;i < spansLength; i++){112 filterIDs.push($(spans[i]).attr('rel'));113 }114 return filterIDs;115 },116 getCompactData: function(_value){117 var that = this;118 var value = _value;119 120 that.compactArray.length = 0;121 122 for(var i=0, len = that.resource.length; i< len; i++){//ä¸ºæææ°æ®é¡¹å ä¸visible屿§ç¨äºè¿æ»¤ä¸è¿å123 that.resource[i].visible = true;124 }125 126 if(that.isFilterSelected){//æ¯å¦è¿æ»¤å·²æ·»å çæ°æ®127 var filterIDs = that.getSelected_userids(); 128 var len=$(that.filter).find('span').length;129 for(var i=0; i < len; i++){130 var num = that.resource.length - 1;131 that.resource[num].visible = true;132 }133 for(var i=0; i < len; i++){//è¿æ»¤å·²ç»éæ©çæ°æ®134 var num = that.resource.length - 1;135 while(num >= 0){136 if(filterIDs[i] == that.resource[num][that.filterKey]){137 that.resource[num].visible = false;138 }139 num--;140 }141 }142 }143 that.compactArray.length = 0;144 for(var i=0, len = that.resource.length; i< len; i++){//å¹é
æ¥æ¾å°å¹é
å¹¶ä¸å¯è§çæ°æ®é¡¹145 var currentItem = that.resource[i];146 var _index = currentItem[that.filterWord].indexOf(_value);147 if(_index >= 0 && currentItem.visible){148 var object = {};149 object.index = _index;150 object.item = currentItem;151 that.compactArray.push(object);152 }153 }154 155 if(that.compactArray.length > 0){156 that.compactArray.sort(that.compare);157 if(that.descend){158 that.compactArray.reverse();159 }160 }161 var temp = {};162 var arr = [];163 var arr1 = [];164 165 //ä¿®å¤è¿æ»¤å
³é®åé夿¶ï¼è¿åæ°æ®å®å
¨ä¸è´çbug by chengtingting166 $.each(that.compactArray,function(i,o){167 temp[o.item[that.filterKey]] = o;168 temp[o.item[that.filterKey]].ischecked = false; //å½å
³é®åæé夿¶ï¼ç¨ischecked夿ï¼é¿å
é夿å
¥169 arr.push(o.item[this.filterWord]);170 });171 arr = arr.sort(); //æå
³é®åæåº172 $.each(arr,function(i,o){ //oå
³é®å173 for(var i in temp){174 if(o === temp[i].item[this.filterWord] && !temp[i].ischecked){175 arr1.push(temp[i]);176 temp[i].ischecked = true;177 }178 }179 })180 that.callback(arr1);181 }...
compact-array.js
Source: compact-array.js
...26 }27 function filter(col, fn) {28 return col.filter(fn);29 }30 function compactArray(o) {31 var ret = [];32 if (isArray(o)) {33 for (var i = 0; i < o.length; i++) {34 if (!isEmpty(o[i])) {35 if (isArray(o[i])) {36 ret.push(compactArray(o[i]));37 } else {38 ret.push(o[i]);39 }40 }41 }42 }43 return ret;44 }45 if (typeof exports !== 'undefined') {46 if (typeof module !== 'undefined' && module.exports) {47 exports = module.exports = compactArray;48 }49 exports.compactArray = compactArray;50 } else if (typeof define === 'function' && define.amd) {...
compact-array.spec.ts
Source: compact-array.spec.ts
1import { compactArray } from '@terminus/fe-utilities';2describe(`compactArray`, function() {3 test(`should return undefined if the array is empty or doesn't exist`, () => {4 expect(compactArray(null as any)).toEqual(undefined);5 expect(compactArray([])).toEqual(undefined);6 });7 test(`should return the cleaned array`, () => {8 const arr1: any[] = ['foo', null, 'bar', undefined, 'baz'];9 expect(compactArray<string>(arr1)).toEqual(['foo', 'bar', 'baz']);10 });...
Using AI Code Generation
1import { compactArray } from 'storybook-root';2import { compactArray } from 'storybook-root';3import { compactArray } from 'storybook-root';4import { compactArray } from 'storybook-root';5import { compactArray } from 'storybook-root';6import { compactArray } from 'storybook-root';7import { compactArray } from 'storybook-root';8import { compactArray } from 'storybook-root';9import { compactArray } from 'storybook-root';10import { compactArray } from 'storybook-root';11import { compactArray } from 'storybook-root';12import { compactArray } from 'storybook-root';13import { compactArray } from 'storybook-root';14import { compactArray } from 'storybook-root';15import { compactArray } from 'storybook-root';16import { compactArray } from 'storybook-root';17import { compactArray } from 'storybook-root';18import { compactArray } from
Using AI Code Generation
1import { compactArray } from 'storybook-root';2import { compactArray } from 'storybook-root';3import { compactArray } from 'storybook-root';4import { compactArray } from 'storybook-root';5import { compactArray } from 'storybook-root';6import { compactArray } from 'storybook-root';7import { compactArray } from 'storybook-root';8import { compactArray } from 'storybook-root';9import { compactArray } from 'storybook-root';10import { compactArray } from 'storybook-root';11import { compactArray } from 'storybook-root';12import { compactArray } from 'storybook-root';13import { compactArray } from 'storybook-root';14import { compactArray } from 'storybook-root';15import { compactArray } from 'storybook-root';16import { compactArray } from 'storybook-root';17import { compactArray } from 'storybook-root';18import { compactArray } from 'storybook-root';19import { compactArray } from 'storybook-root';20import { compactArray } from 'storybook-root';
Using AI Code Generation
1import { compactArray } from 'storybook-root';2import { compactArray } from 'storybook-root';3import { compactArray } from 'storybook-root';4import { compactArray } from 'storybook-root';5import { compactArray } from 'storybook-root';6import { compactArray } from 'storybook-root';7import { compactArray } from 'storybook-root';8import { compactArray } from 'storybook-root';9import { compactArray } from 'storybook-root';10import { compactArray } from 'storybook-root';11import { compactArray } from 'storybook-root';12import { compactArray } from 'storybook-root';13import { compactArray } from 'storybook-root';
Check out the latest blogs from LambdaTest on this topic:
Are members of agile teams different from members of other teams? Both yes and no. Yes, because some of the behaviors we observe in agile teams are more distinct than in non-agile teams. And no, because we are talking about individuals!
Hey LambdaTesters! We’ve got something special for you this week. ????
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Recently, I was going through some of the design patterns in Java by reading the book Head First Design Patterns by Eric Freeman, Elisabeth Robson, Bert Bates, and Kathy Sierra.
Technical debt was originally defined as code restructuring, but in today’s fast-paced software delivery environment, it has evolved. Technical debt may be anything that the software development team puts off for later, such as ineffective code, unfixed defects, lacking unit tests, excessive manual tests, or missing automated tests. And, like financial debt, it is challenging to pay back.
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!!