Best JavaScript code snippet using unexpected
metrics.js
Source:metrics.js
1import _ from "lodash";2import moment from "moment";3import { SemverCmp } from "./semver";4export var Metrics = {};5export var version = "";6export function Version(ver) { version = ver };7var metricFnc = (res, field1, field2) => {8 var points = [];9 var div = 1;10 if (SemverCmp(version, "0.9") > 0) {11 div = 1000;12 }13 _.forEach(res[0], (entries) => {14 _.forEach(entries, (entry) => {15 var value1 = 0, value2 = 0;16 if (field1 in entry) {17 value1 = entry[field1];18 }19 if (field2 in entry) {20 value2 = entry[field2];21 }22 var start = entry.Start;23 var last = entry.Last;24 if (div > 1) {25 start /= div;26 last /= div;27 }28 var value = (value1 + value2) / (last - start);29 points.push([value, moment(last, 'X').valueOf()]);30 });31 });32 return points;33}34var rttFnc = (res, field) => {35 var points = [];36 _.forEach(res[0], (entries) => {37 _.forEach(entries, (entry) => {38 var value = 0;39 if (field in entry) {40 value = entry[field];41 }42 var start = entry.Start / 1000;43 points.push([value, moment(start, 'X').valueOf()]);44 });45 });46 return _.sortBy(points, [function (v) { return v[1]; }]);47}48Metrics["Flow"] = {49 "Default": {50 "Name": "Flow",51 "Default": "Bytes",52 "MinVer": "0.1",53 "Fields": {54 "Packets": { Name: "Packets", Suffix: "Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "ABPackets", "BAPackets") } },55 "Bytes": { Name: "Bytes", Suffix: "Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "ABBytes", "BABytes") } },56 "ABPackets": { Name: "ABPackets", Suffix: "Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "ABPackets") } },57 "ABBytes": { Name: "ABBytes", Suffix: "Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "ABBytes") } },58 "BAPackets": { Name: "BAPackets", Suffix: "Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "ABBytes") } },59 "BABytes": { Name: "BABytes", Suffix: "Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "ABBytes") } },60 "RTT": { Name: "RTT", Suffix: "Metrics()", PointsFnc: (res) => { return rttFnc(res, "RTT") } },61 }62 }63}64Metrics["OpenFlow"] = {65 "Default": {66 "Name": "OpenFlow",67 "Default": "RxBytes",68 "MinVer": "0.23",69 "Fields": {70 "RxPackets": { Name: "Packets", Suffix: "Has('Type', 'ofrule').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxPackets") } },71 "RxBytes": { Name: "Bytes", Suffix: "Has('Type', 'ofrule').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxBytes") } },72 }73 }74}75Metrics["Interface"] = {76 "Default": {77 "Name": "Interface",78 "Default": "Bytes",79 "MinVer": "0.1",80 "Fields": {81 "Packets": { Name: "Packets", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxPackets", "TxPackets") } },82 "Bytes": { Name: "Bytes", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxBytes", "TxBytes") } },83 "Collisions": { Name: "Collisions", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "Collisions") } },84 "Multicast": { Name: "Multicast", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "Multicast") } },85 "RxBytes": { Name: "RxBytes", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxBytes") } },86 "RxCompressed": { Name: "RxCompressed", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxCompressed") } },87 "RxCrcErrors": { Name: "RxCrcErrors", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxCrcErrors") } },88 "RxDropped": { Name: "RxDropped", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxDropped") } },89 "RxErrors": { Name: "RxErrors", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxErrors") } },90 "RxFifoErrors": { Name: "RxFifoErrors", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxFifoErrors") } },91 "RxFrameErrors": { Name: "RxFrameErrors", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxFrameErrors") } },92 "RxLengthErrors": { Name: "RxLengthErrors", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxLengthErrors") } },93 "RxMissedErrors": { Name: "RxMissedErrors", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxMissedErrors") } },94 "RxOverErrors": { Name: "RxOverErrors", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxOverErrors") } },95 "RxPackets": { Name: "RxPackets", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxPackets") } },96 "TxAbortedErrors": { Name: "TxAbortedErrors", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "TxAbortedErrors") } },97 "TxBytes": { Name: "TxBytes", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "TxBytes") } },98 "TxCarrierErrors": { Name: "TxCarrierErrors", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "TxCarrierErrors") } },99 "TxCompressed": { Name: "TxCompressed", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "TxCompressed") } },100 "TxDropped": { Name: "TxDropped", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "TxDropped") } },101 "TxHeartbeatErrors": { Name: "TxHeartbeatErrors", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "TxHeartbeatErrors") } },102 "TxPackets": { Name: "TxPackets", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "TxPackets") } },103 "TxWindowErrors": { Name: "TxWindowErrors", Suffix: "HasKey('Metric').Metrics().Aggregates()", PointsFnc: (res) => { return metricFnc(res, "TxWindowErrors") } },104 }105 },106 "OpenvSwitch": {107 "Name": "OpenvSwitch",108 "Default": "Bytes",109 "MinVer": "0.23",110 "Fields": {111 "Packets": { Name: "Packets", Suffix: "HasKey('Ovs.Metric').Metrics('Ovs').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxPackets", "TxPackets") } },112 "Bytes": { Name: "Bytes", Suffix: "Metrics('Ovs').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxBytes", "res.TxBytes") } },113 "Collisions": { Name: "Collisions", Suffix: "HasKey('Ovs.Metric').Metrics('Ovs').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "Collisions") } },114 "RxBytes": { Name: "RxBytes", Suffix: "HasKey('Ovs.Metric').Metrics('Ovs').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxBytes") } },115 "RxCrcErrors": { Name: "RxCrcErrors", Suffix: "HasKey('Ovs.Metric').Metrics('Ovs').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxCrcErrors") } },116 "RxDropped": { Name: "RxDropped", Suffix: "HasKey('Ovs.Metric').Metrics('Ovs').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxDropped") } },117 "RxErrors": { Name: "RxErrors", Suffix: "HasKey('Ovs.Metric').Metrics('Ovs').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxErrors") } },118 "RxFrameErrors": { Name: "RxFrameErrors", Suffix: "HasKey('Ovs.Metric').Metrics('Ovs').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxFrameErrors") } },119 "RxOverErrors": { Name: "RxOverErrors", Suffix: "HasKey('Ovs.Metric').Metrics('Ovs').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxOverErrors") } },120 "RxPackets": { Name: "RxPackets", Suffix: "HasKey('Ovs.Metric').Metrics('Ovs').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "RxPackets") } },121 "TxBytes": { Name: "TxBytes", Suffix: "HasKey('Ovs.Metric').Metrics('Ovs').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "TxBytes") } },122 "TxDropped": { Name: "TxDropped", Suffix: "HasKey('Ovs.Metric').Metrics('Ovs').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "TxDropped") } },123 "TxErrors": { Name: "TxErrors", Suffix: "HasKey('Ovs.Metric').Metrics('Ovs').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "TxErrors") } },124 "TxPackets": { Name: "TxPackets", Suffix: "HasKey('Ovs.Metric').Metrics('Ovs').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "TxPackets") } },125 }126 },127 "sFlow": {128 "Name": "sFlow",129 "Default": "IfInOctets",130 "MinVer": "0.23",131 "Fields": {132 "IfInOctets": { Name: "IfInOctets", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "IfInOctets") } },133 "IfInUcastPkts": { Name: "IfInUcastPkts", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "IfInUcastPkts") } },134 "IfInMulticastPkts": { Name: "IfInMulticastPkts", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "IfInMulticastPkts") } },135 "IfInBroadcastPkts": { Name: "IfInBroadcastPkts", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "IfInBroadcastPkts") } },136 "IfInDiscards": { Name: "IfInDiscards", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "IfInDiscards") } },137 "IfInErrors": { Name: "IfInErrors", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "IfInErrors") } },138 "IfInUnknownProtos": { Name: "IfInUnknownProtos", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "IfInUnknownProtos") } },139 "IfOutOctets": { Name: "IfOutOctets", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "IfOutOctets") } },140 "IfOutUcastPkts": { Name: "IfOutUcastPkts", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "IfOutUcastPkts") } },141 "IfOutMulticastPkts": { Name: "IfOutMulticastPkts", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "IfOutMulticastPkts") } },142 "IfOutBroadcastPkts": { Name: "IfOutBroadcastPkts", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "IfOutBroadcastPkts") } },143 "IfOutDiscards": { Name: "IfOutDiscards", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "IfOutDiscards") } },144 "IfOutErrors": { Name: "IfOutErrors", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "IfOutErrors") } },145 "OvsdpNHit": { Name: "OvsdpNHit", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "OvsdpNHit") } },146 "OvsdpNMissed": { Name: "OvsdpNMissed", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "OvsdpNMissed") } },147 "OvsdpNLost": { Name: "OvsdpNLost", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "OvsdpNLost") } },148 "OvsdpNMaskHit": { Name: "OvsdpNMaskHit", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "OvsdpNMaskHit") } },149 "OvsdpNFlows": { Name: "OvsdpNFlows", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "OvsdpNFlows") } },150 "OvsdpNMasks": { Name: "OvsdpNMasks", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "OvsdpNMasks") } },151 "OvsAppFdOpen": { Name: "OvsAppFdOpen", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "OvsAppFdOpen") } },152 "OvsAppFdMax": { Name: "OvsAppFdMax", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "OvsAppFdMax") } },153 "OvsAppConnOpen": { Name: "OvsAppConnOpen", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "OvsAppConnOpen") } },154 "OvsAppConnMax": { Name: "OvsAppConnMax", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "OvsAppConnMax") } },155 "OvsAppMemUsed": { Name: "OvsAppMemUsed", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "OvsAppMemUsed") } },156 "OvsAppMemMax": { Name: "OvsAppMemMax", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "OvsAppMemMax") } },157 "VlanOctets": { Name: "VlanOctets", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "VlanOctets") } },158 "VlanUcastPkts": { Name: "VlanUcastPkts", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "VlanUcastPkts") } },159 "VlanMulticastPkts": { Name: "VlanMulticastPkts", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "VlanMulticastPkts") } },160 "VlanBroadcastPkts": { Name: "VlanBroadcastPkts", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "VlanBroadcastPkts") } },161 "VlanDiscards": { Name: "VlanDiscards", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "VlanDiscards") } },162 "EthAlignmentErrors": { Name: "EthAlignmentErrors", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "EthAlignmentErrors") } },163 "EthFCSErrors": { Name: "EthFCSErrors", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "EthFCSErrors") } },164 "EthSingleCollisionFrames": { Name: "EthSingleCollisionFrames", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "EthSingleCollisionFrames") } },165 "EthMultipleCollisionFrames": { Name: "EthMultipleCollisionFrames", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "EthMultipleCollisionFrames") } },166 "EthSQETestErrors": { Name: "EthSQETestErrors", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "EthSQETestErrors") } },167 "EthDeferredTransmissions": { Name: "EthDeferredTransmissions", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "EthDeferredTransmissions") } },168 "EthLateCollisions": { Name: "EthLateCollisions", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "EthLateCollisions") } },169 "EthExcessiveCollisions": { Name: "EthExcessiveCollisions", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "EthExcessiveCollisions") } },170 "EthInternalMacReceiveErrors": { Name: "EthInternalMacReceiveErrors", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "EthInternalMacReceiveErrors") } },171 "EthInternalMacTransmitErrors": { Name: "EthInternalMacTransmitErrors", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "EthInternalMacTransmitErrors") } },172 "EthCarrierSenseErrors": { Name: "EthCarrierSenseErrors", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "EthCarrierSenseErrors") } },173 "EthFrameTooLongs": { Name: "EthFrameTooLongs", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "EthFrameTooLongs") } },174 "EthSymbolErrors": { Name: "EthSymbolErrors", Suffix: "HasKey('SFlow').Metrics('SFlow').Aggregates()", PointsFnc: (res) => { return metricFnc(res, "EthSymbolErrors") } },175 }176 }177}178export function TypeByKeys(keys) {179 if (keys.indexOf("Filters") >= 0 && keys.indexOf("Actions") >= 0) {180 return "OpenFlow";181 } else if (keys.indexOf("TrackingID") >= 0) {182 return "Flow";183 } else {184 return "Interface";185 }186 return {}...
decoder.js
Source:decoder.js
1'use strict';2var Map = require("./map");3var Entity = require("./entity");4var NeonError = require('./error');5function Result() {6 this.key = 0;7 this.value = null;8 this.add = function (key, value) {9 if (this.value === null) {10 this.value = new Map();11 }12 return this.value.add(key, value);13 };14}15function decoder(output) {16 if (typeof output === "undefined") {17 output = decoder.MAP;18 }19 /** @var array */20 this.tokens = [];21 /** @var int */22 this.pos = 0;23 this.input = "";24 /**25 * Decodes a NEON string.26 * @param input string27 * @return mixed28 */29 this.decode = function (input) {30 if (typeof (input) != "string") {31 throw 'Argument must be a string, ' + typeof input + ' given.';32 } else if (input.substr(0, 3) == "\xEF\xBB\xBF") { // BOM33 input = input.substr(3);34 }35 this.input = "\n" + "" + input.replace(/\r\n/g, "\n"); // \n forces indent detection36 var regexp = new RegExp('(' + "" + decoder.patterns.join(')|(') + "" + ')', 'mig');37 this.tokens = this.split(regexp, this.input);38 var last = this.tokens[this.tokens.length - 1];39 if (this.tokens && !regexp.test(last[0])) {40 this.pos = this.tokens.length - 1;41 this.error();42 }43 this.pos = 0;44 var res = this.parse(null);45 while ((this.tokens[this.pos])) {46 if (this.tokens[this.pos][0][0] === "\n") {47 this.pos++;48 } else {49 this.error();50 }51 }52 var flatten = function (res) {53 if (res instanceof Result) {54 return flatten(res.value);55 } else if (res instanceof Entity) {56 res.attributes = flatten(res.attributes);57 res.value = flatten(res.value);58 } else if (res instanceof Map) {59 if (output === decoder.FORCE_OBJECT) {60 var obj = {};61 res.forEach(function (key, value) {62 obj[key] = flatten(value);63 });64 return obj;65 } else {66 var result = new Map;67 var isList = true;68 var cmp = 0;69 res.forEach(function (key, value) {70 result.set(key, flatten(value));71 if (key !== cmp++) {72 isList = false;73 }74 });75 if (output === decoder.MAP) {76 return result;77 } else {78 return isList ? result.values() : result.toObject();79 }80 }81 }82 return res;83 };84 return flatten(res);85 };86 /**87 * @param indent string indentation (for block-parser)88 * @param key mixed89 * @param hasKey bool90 * @return array91 */92 this.parse = function (indent, defaultValue, key, hasKey) {93 if (typeof key === "undefined") {94 key = null;95 }96 if (typeof defaultValue === "undefined") {97 defaultValue = null;98 }99 if (typeof hasKey === "undefined") {100 hasKey = false;101 }102 var result = new Result();103 result.value = defaultValue;104 var inlineParser = indent === false;105 var value = null;106 var hasValue = false;107 var tokens = this.tokens;108 var count = tokens.length;109 var mainResult = result;110 for (; this.pos < count; this.pos++) {111 var t = tokens[this.pos][0];112 if (t === ',') { // ArrayEntry separator113 if ((!hasKey && !hasValue) || !inlineParser) {114 this.error();115 }116 this.addValue(result, hasKey ? key : null, hasValue ? value : null);117 hasKey = hasValue = false;118 } else if (t === ':' || t === '=') { // KeyValuePair separator119 if (hasValue && (typeof value == "object")) {120 this.error('Unacceptable key');121 } else if (hasKey && key == null && hasValue && !inlineParser) {122 this.pos++;123 this.addValue(result, null, this.parse(indent + "" + ' ', new Map(), value, true));124 var newIndent = (typeof tokens[this.pos] !== "undefined" && typeof tokens[this.pos + 1] !== "undefined") ? tokens[this.pos][0].substr(1) : ''; // not last125 if (newIndent.length > indent.length) {126 this.pos++;127 this.error('Bad indentation');128 } else if (newIndent.length < indent.length) {129 return mainResult; // block parser exit point130 }131 hasKey = hasValue = false;132 } else if (hasKey || !hasValue) {133 this.error();134 } else {135 key = value;136 hasKey = true;137 hasValue = false;138 result = mainResult;139 }140 } else if (t === '-') { // BlockArray bullet141 if (hasKey || hasValue || inlineParser) {142 this.error();143 }144 key = null;145 hasKey = true;146 } else if ((decoder.brackets[t])) { // Opening bracket [ ( {147 if (hasValue) {148 if (t !== '(') {149 this.error();150 }151 this.pos++;152 if (value instanceof Entity && value.value === decoder.CHAIN) {153 value.attributes.value.last().value.attributes = this.parse(false, new Map());154 } else {155 value = new Entity(value, this.parse(false, new Map()));156 }157 } else {158 this.pos++;159 value = this.parse(false, new Map());160 }161 hasValue = true;162 if (tokens[this.pos] === undefined || tokens[this.pos][0] !== decoder.brackets[t]) { // unexpected type of bracket or block-parser163 this.error();164 }165 } else if (t === ']' || t === '}' || t === ')') { // Closing bracket ] ) }166 if (!inlineParser) {167 this.error();168 }169 break;170 } else if (t[0] === "\n") { // Indent171 if (inlineParser) {172 if (hasKey || hasValue) {173 this.addValue(result, hasKey ? key : null, hasValue ? value : null);174 hasKey = hasValue = false;175 }176 } else {177 while (tokens[this.pos + 1] !== undefined && tokens[this.pos + 1][0][0] === "\n") {178 this.pos++; // skip to last indent179 }180 if (tokens[this.pos + 1] === undefined) {181 break;182 }183 newIndent = tokens[this.pos][0].substr(1);184 if (indent === null) { // first iteration185 indent = newIndent;186 }187 var minlen = Math.min(newIndent.length, indent.length);188 if (minlen && newIndent.substr(0, minlen) !== indent.substr(0, minlen)) {189 this.pos++;190 this.error('Invalid combination of tabs and spaces');191 }192 if (newIndent.length > indent.length) { // open new block-array or hash193 if (hasValue || !hasKey) {194 this.pos++;195 this.error('Bad indentation');196 }197 this.addValue(result, key, this.parse(newIndent, new Map));198 newIndent = (tokens[this.pos] !== undefined && tokens[this.pos + 1] !== undefined) ? tokens[this.pos][0].substr(1) : ''; // not last199 if (newIndent.length > indent.length) {200 this.pos++;201 this.error('Bad indentation');202 }203 hasKey = false;204 } else {205 if (hasValue && !hasKey) { // block items must have "key"; NULL key means list item206 break;207 } else if (hasKey) {208 this.addValue(result, key, hasValue ? value : null);209 if (key !== null && !hasValue && newIndent === indent && typeof tokens[this.pos + 1] !== "undefined" && tokens[this.pos + 1][0] === "-") {210 result.value.set(key, new Result);211 result = result.value.get(key);212 }213 hasKey = hasValue = false;214 }215 }216 if (newIndent.length < indent.length) { // close block217 return mainResult; // block parser exit point218 }219 }220 } else if (hasValue) { // Value221 if (value instanceof Entity) { // Entity chaining222 if (value.value !== decoder.CHAIN) {223 var attributes = new Result();224 attributes.add(null, value);225 value = new Entity(decoder.CHAIN, attributes);226 }227 value.attributes.add(null, new Entity(t));228 } else {229 this.error();230 }231 } else { // Value232 if (typeof this.parse.consts == 'undefined')233 this.parse.consts = {234 'true': true, 'True': true, 'TRUE': true, 'yes': true, 'Yes': true, 'YES': true, 'on': true, 'On': true, 'ON': true,235 'false': false, 'False': false, 'FALSE': false, 'no': false, 'No': false, 'NO': false, 'off': false, 'Off': false, 'OFF': false,236 'null': 0, 'Null': 0, 'NULL': 0237 };238 if (t[0] === '"') {239 var self = this;240 value = t.substr(1, t.length - 2).replace(/\\(?:u[0-9a-f]{4}|x[0-9a-f]{2}|.)/gi, function (match) {241 var mapping = {'t': "\t", 'n': "\n", 'r': "\r", 'f': "\x0C", 'b': "\x08", '"': '"', '\\': '\\', '/': '/', '_': "\xc2\xa0"};242 if (mapping[match[1]] !== undefined) {243 return mapping[match[1]];244 } else if (match[1] === 'u' && match.length === 6) {245 return String.fromCharCode(parseInt(match.substr(2), 16));246 } else if (match[1] === 'x' && match.length === 4) {247 return String.fromCharCode(parseInt(match.substr(2), 16));248 } else {249 self.error("Invalid escaping sequence " + match + "");250 }251 });252 } else if (t[0] === "'") {253 value = t.substr(1, t.length - 2);254 } else if (typeof this.parse.consts[t] !== "undefined"255 && (typeof tokens[this.pos + 1] === "undefined" || (typeof tokens[this.pos + 1] !== "undefined" && tokens[this.pos + 1][0] !== ':' && tokens[this.pos + 1][0] !== '='))) {256 value = this.parse.consts[t] === 0 ? null : this.parse.consts[t];257 } else if (!isNaN(t)) {258 value = t * 1;259 } else if (t.match(/^\d\d\d\d-\d\d?-\d\d?(?:(?:[Tt]| +)\d\d?:\d\d:\d\d(?:\.\d*)? *(?:Z|[-+]\d\d?(?::\d\d)?)?)?$/)) {260 value = new Date(t);261 } else { // literal262 value = t;263 }264 hasValue = true;265 }266 }267 if (inlineParser) {268 if (hasKey || hasValue) {269 this.addValue(result, hasKey ? key : null, hasValue ? value : null);270 }271 } else {272 if (hasValue && !hasKey) { // block items must have "key"273 if (result.value === null || (result.value instanceof Map && result.value.length == 0)) { //if empty274 return value; // simple value parser275 } else {276 this.error();277 }278 } else if (hasKey) {279 this.addValue(result, key, hasValue ? value : null);280 }281 }282 return mainResult;283 };284 this.addValue = function (result, key, value) {285 if (result.add(key, value) === false) {286 this.error("Duplicated key '" + key + "'");287 }288 };289 this.error = function (message) {290 if (typeof message === "undefined") {291 message = "Unexpected '%s'";292 }293 var last = this.tokens[this.pos] !== undefined ? this.tokens[this.pos] : null;294 var offset = last ? last[1] : this.input.length;295 var text = this.input.substr(0, offset);296 var line = text.split("\n").length - 1;297 var col = offset - ("\n" + "" + text).lastIndexOf("\n") + 1;298 var token = last ? last[0].substr(0, 40).replace("\n", '<new line>') : 'end';299 throw new NeonError(message.replace("%s", token), line, col);300 };301 this.split = function (pattern, subject) {302 /*303 Copyright (c) 2013 Kevin van Zonneveld (http://kvz.io)304 and Contributors (http://phpjs.org/authors)305 LICENSE: https://github.com/kvz/phpjs/blob/master/LICENSE.txt306 */307 var result, ret = [], index = 0, i = 0;308 var _filter = function (str, strindex) {309 if (!str.length) {310 return;311 }312 str = [str, strindex];313 ret.push(str);314 };315 // Exec the pattern and get the result316 while (result = pattern.exec(subject)) {317 // Take the correct portion of the string and filter the match318 _filter(subject.slice(index, result.index), index);319 index = result.index + result[0].length;320 // Convert the regexp result into a normal array321 var resarr = Array.prototype.slice.call(result);322 for (i = 1; i < resarr.length; i++) {323 if (result[i] !== undefined) {324 _filter(result[i], result.index + result[0].indexOf(result[i]));325 }326 }327 }328 // Filter last match329 _filter(subject.slice(index, subject.length), index);330 return ret;331 }332}333decoder.patterns = [334 "'[^'\\n]*'|\"(?:\\\\.|[^\"\\\\\\n])*\"",335 "(?:[^\\x00-\\x20#\"',:=[\\]{}()!`-]|[:-][^\"',\\]})\\s])(?:[^\\x00-\\x20,:=\\]})(]+|:(?![\\s,\\]})]|$)|[\\ \\t]+[^\\x00-\\x20#,:=\\]})(])*",336 "[,:=[\\]{}()-]",337 "?:\\#.*",338 "\\n[\\t\\ ]*",339 "?:[\\t\\ ]+"];340decoder.brackets = {341 '[': ']',342 '{': '}',343 '(': ')'344};345decoder.CHAIN = '!!chain';346decoder.MAP = 'map';347decoder.AUTO = 'auto';348decoder.FORCE_OBJECT = 'object';...
i18n.js
Source:i18n.js
1// translate router.meta.title, be used in breadcrumb sidebar tagsview2export function generateTitle(title) {3 const hasKey = this.$te('route.' + title)4 const translatedTitle = this.$t('route.' + title) // $t :this method from vue-i18n, inject in @/lang/index.js5 if (hasKey) {6 return translatedTitle7 }8 return title9}10export function generateNavbar(title) {11 const hasKey = this.$te('navbar.' + title)12 const translatedTitle = this.$t('navbar.' + title) // $t :this method from vue-i18n, inject in @/lang/index.js13 if (hasKey) {14 return translatedTitle15 }16 return title17}18// åºé¨19export function generateFooter(title) {20 const hasKey = this.$te('footer.' + title)21 const translatedTitle = this.$t('footer.' + title) // $t :this method from vue-i18n, inject in @/lang/index.js22 if (hasKey) {23 return translatedTitle24 }25 return title26}27// é¦é¡µ28export function generateDashboard(title) {29 const hasKey = this.$te('dashboard.' + title)30 const translatedTitle = this.$t('dashboard.' + title)31 if (hasKey) {32 return translatedTitle33 }34 return title35}36// ç¿æº37export function generateMiner(title) {38 const hasKey = this.$te('miner.' + title)39 const translatedTitle = this.$t('miner.' + title)40 if (hasKey) {41 return translatedTitle42 }43 return title44}45// å
¬åä¸å¿46export function generateNoticeCenter(title) {47 const hasKey = this.$te('noticeCenter.' + title)48 const translatedTitle = this.$t('noticeCenter.' + title)49 if (hasKey) {50 return translatedTitle51 }52 return title53}54// æ´å¤å
¬å55export function generateNoticeMore(title) {56 const hasKey = this.$te('noticeMore.' + title)57 const translatedTitle = this.$t('noticeMore.' + title)58 if (hasKey) {59 return translatedTitle60 }61 return title62}63// å
¬å详æ
64export function generateNoticeDetail(title) {65 const hasKey = this.$te('noticeDetail.' + title)66 const translatedTitle = this.$t('noticeDetail.' + title)67 if (hasKey) {68 return translatedTitle69 }70 return title71}72// 帮å©ä¸å¿73export function generateHelpCenter(title) {74 const hasKey = this.$te('helpCenter.' + title)75 const translatedTitle = this.$t('helpCenter.' + title)76 if (hasKey) {77 return translatedTitle78 }79 return title80}81// æ´å¤å¸®å©82export function generateHelpMore(title) {83 const hasKey = this.$te('helpMore.' + title)84 const translatedTitle = this.$t('helpMore.' + title)85 if (hasKey) {86 return translatedTitle87 }88 return title89}90// 帮å©è¯¦æ
91export function generateHelpDetail(title) {92 const hasKey = this.$te('helpDetail.' + title)93 const translatedTitle = this.$t('helpDetail.' + title)94 if (hasKey) {95 return translatedTitle96 }97 return title98}99// 注å100export function generateRegister(title) {101 const hasKey = this.$te('register.' + title)102 const translatedTitle = this.$t('register.' + title)103 if (hasKey) {104 return translatedTitle105 }106 return title107}108// 注åï¼è´¦å·æ¿æ´»ï¼109export function generateAccountActivation(title) {110 const hasKey = this.$te('accountActivation.' + title)111 const translatedTitle = this.$t('accountActivation.' + title)112 if (hasKey) {113 return translatedTitle114 }115 return title116}117// 注åï¼æ¿æ´»éªè¯ï¼118export function generateActivationSuccess(title) {119 const hasKey = this.$te('activationSuccess.' + title)120 const translatedTitle = this.$t('activationSuccess.' + title)121 if (hasKey) {122 return translatedTitle123 }124 return title125}126// ç»å½127export function generateLogin(title) {128 const hasKey = this.$te('login.' + title)129 const translatedTitle = this.$t('login.' + title)130 if (hasKey) {131 return translatedTitle132 }133 return title134}135// æ¾åå¯ç 136export function generateForgetPassword(title) {137 const hasKey = this.$te('forgetPassword.' + title)138 const translatedTitle = this.$t('forgetPassword.' + title)139 if (hasKey) {140 return translatedTitle141 }142 return title143}144// æ¾åå¯ç ï¼éç½®é®ä»¶ï¼145export function generateMailForget(title) {146 const hasKey = this.$te('mailForget.' + title)147 const translatedTitle = this.$t('mailForget.' + title)148 if (hasKey) {149 return translatedTitle150 }151 return title152}153// æ¾åå¯ç ï¼éç½®å¯ç ï¼154export function generateMailResetPassword(title) {155 const hasKey = this.$te('mailResetPassword.' + title)156 const translatedTitle = this.$t('mailResetPassword.' + title)157 if (hasKey) {158 return translatedTitle159 }160 return title161}162// æ¾åå¯ç ï¼éç½®å¯ç æåï¼163export function generateMailForgetSuccess(title) {164 const hasKey = this.$te('mailForgetSuccess.' + title)165 const translatedTitle = this.$t('mailForgetSuccess.' + title)166 if (hasKey) {167 return translatedTitle168 }169 return title170}171// APPä¸è½½172export function generateAppDownload(title) {173 const hasKey = this.$te('appDownload.' + title)174 const translatedTitle = this.$t('appDownload.' + title)175 if (hasKey) {176 return translatedTitle177 }178 return title179}180// å页ç»ä»¶181export function generatePages(title) {182 const hasKey = this.$te('Pages.' + title)183 const translatedTitle = this.$t('Pages.' + title)184 if (hasKey) {185 return translatedTitle186 }187 return title188}189// åºå·éæ©ç»ä»¶190export function generateZoneDialog(title) {191 const hasKey = this.$te('ZoneDialog.' + title)192 const translatedTitle = this.$t('ZoneDialog.' + title)193 if (hasKey) {194 return translatedTitle195 }196 return title197}198export function generateTrade(title) {199 const hasKey = this.$te('trade.' + title)200 const translatedTitle = this.$t('trade.' + title)201 if (hasKey) {202 return translatedTitle203 }204 return title205}206export function generateUser(title) {207 const hasKey = this.$te('userCenter.' + title)208 const translatedTitle = this.$t('userCenter.' + title)209 if (hasKey) {210 return translatedTitle211 }212 return title213}214// æçèµäº§215export function generateAssetManagement(title) {216 const hasKey = this.$te('assetManagement.' + title)217 const translatedTitle = this.$t('assetManagement.' + title)218 if (hasKey) {219 return translatedTitle220 }221 return title222}223export function generateMyPower(title) {224 const hasKey = this.$te('myPower.' + title)225 const translatedTitle = this.$t('myPower.' + title)226 if (hasKey) {227 return translatedTitle228 }229 return title230}231export function generateUserChild(title) {232 const hasKey = this.$te('userCenterChild.' + title)233 const translatedTitle = this.$t('userCenterChild.' + title)234 if (hasKey) {235 return translatedTitle236 }237 return title238}239export function generateCurrententrust(title) {240 const hasKey = this.$te('currententrust.' + title)241 const translatedTitle = this.$t('currententrust.' + title)242 if (hasKey) {243 return translatedTitle244 }245 return title246}247// å
æè®°å½248export function generateRechargeRecord(title) {249 const hasKey = this.$te('rechargeRecord.' + title)250 const translatedTitle = this.$t('rechargeRecord.' + title)251 if (hasKey) {252 return translatedTitle253 }254 return title255}256export function generateHistoryentrust(title) {257 const hasKey = this.$te('historyentrust.' + title)258 const translatedTitle = this.$t('historyentrust.' + title)259 if (hasKey) {260 return translatedTitle261 }262 return title263}264export function generateTransacation(title) {265 const hasKey = this.$te('transacation.' + title)266 const translatedTitle = this.$t('transacation.' + title)267 if (hasKey) {268 return translatedTitle269 }270 return title271}272// æ·»å å°å273export function generatepresentAddr(title) {274 const hasKey = this.$te('presentAddr.' + title)275 const translatedTitle = this.$t('presentAddr.' + title)276 if (hasKey) {277 return translatedTitle278 }279 return title280}281// å¹³å°å红282export function generateAllocationPlatform(title) {283 const hasKey = this.$te('allocationPlatform.' + title)284 const translatedTitle = this.$t('allocationPlatform.' + title)285 if (hasKey) {286 return translatedTitle287 }288 return title289}290// åé¦ç´¯ç§¯291export function generateAllocationFeedback(title) {292 const hasKey = this.$te('allocationFeedback.' + title)293 const translatedTitle = this.$t('allocationFeedback.' + title)294 if (hasKey) {295 return translatedTitle296 }297 return title298}299// å红累积300export function generateAllocationShare(title) {301 const hasKey = this.$te('allocationShare.' + title)302 const translatedTitle = this.$t('allocationShare.' + title)303 if (hasKey) {304 return translatedTitle305 }306 return title307}308// 红人æ¦309export function generateAllocationRanking(title) {310 const hasKey = this.$te('allocationRanking.' + title)311 const translatedTitle = this.$t('allocationRanking.' + title)312 if (hasKey) {313 return translatedTitle314 }315 return title316}317// ä½é¢å®318export function generateRemainderArea(title) {319 const hasKey = this.$te('remainderArea.' + title)320 const translatedTitle = this.$t('remainderArea.' + title)321 if (hasKey) {322 return translatedTitle323 }324 return title325}326// éä»327export function generateLockedPosition(title) {328 const hasKey = this.$te('lockedPosition.' + title)329 const translatedTitle = this.$t('lockedPosition.' + title)330 if (hasKey) {331 return translatedTitle332 }333 return title334}335// éä»è®°å½336export function generateLockRecord(title) {337 const hasKey = this.$te('lockRecord.' + title)338 const translatedTitle = this.$t('lockRecord.' + title)339 if (hasKey) {340 return translatedTitle341 }342 return title343}344// æ³å¸äº¤æ345export function generateFaitTrade(title) {346 const hasKey = this.$te('faitTrade.' + title)347 const translatedTitle = this.$t('faitTrade.' + title)348 if (hasKey) {349 return translatedTitle350 }351 return title352}353// 个人æµæ°´354export function generatePersonalFlow(title) {355 const hasKey = this.$te('personalFlowPage.' + title)356 const translatedTitle = this.$t('personalFlowPage.' + title)357 if (hasKey) {358 return translatedTitle359 }360 return title361}362// ç»è®¡363export function generateState(title) {364 const hasKey = this.$te('stats.' + title)365 const translatedTitle = this.$t('stats.' + title)366 if (hasKey) {367 return translatedTitle368 }369 return title370}...
pushNotifier.js
Source:pushNotifier.js
...13 it('starts', Mocker.mockIt(function(mokr){14 mokr.mock(config, 'endpoint', 'dum');15 var pn = new PushNotifier(config);16 return pn.trad.reload().then(x=>{17 assert(pn.trad.hasKey('NOTIF_NEW_NOTE_CAMPUS', 'fr'));18 assert(pn.trad.hasKey('LYYTI_STATE_ANSWERED', 'fr'));19 assert(pn.trad.hasKey('LYYTI_STATE_CLOSED', 'fr'));20 assert(pn.trad.hasKey('LYYTI_STATE_ONGOING', 'fr'));21 assert(pn.trad.hasKey('LYYTI_STATE_OPENED', 'fr'));22 assert(pn.trad.hasKey('LYYTI_STATE_READ', 'fr'));23 assert(pn.trad.hasKey('LYYTI_STATE_RESOLVED', 'fr'));24 assert(pn.trad.hasKey('LYYTI_STATE_STANDBY', 'fr'));25 assert(pn.trad.hasKey('NOTIF_LYYTI_FOLLOWED_COMMENT', 'fr'));26 assert(pn.trad.hasKey('NOTIF_LYYTI_STATUS_CHANGED', 'fr'));27 assert(pn.trad.hasKey('NOTIF_MGR_ANSWER', 'fr'));28 assert(pn.trad.hasKey('NOTIF_MGR_ANSWER_PRIVATE_LYYTI', 'fr'));29 assert(pn.trad.hasKey('NOTIF_MODERATED_LYYTI', 'fr'));30 assert(pn.trad.hasKey('NOTIF_NEW_COMMENT', 'fr'));31 assert(pn.trad.hasKey('NOTIF_NEW_DOCUMENT_BUILDING', 'fr'));32 assert(pn.trad.hasKey('NOTIF_NEW_DOCUMENT_CAMPUS', 'fr'));33 assert(pn.trad.hasKey('NOTIF_NEW_DOCUMENT_CITY', 'fr'));34 assert(pn.trad.hasKey('NOTIF_NEW_DOCUMENT_FLAT', 'fr'));35 assert(pn.trad.hasKey('NOTIF_NEW_FLAT_ISSUE', 'fr'));36 assert(pn.trad.hasKey('NOTIF_NEW_ISSUE_BUILDING', 'fr'));37 assert(pn.trad.hasKey('NOTIF_NEW_MESSAGE', 'fr'));38 assert(pn.trad.hasKey('NOTIF_NEW_MESSAGE_ON_LYYTI', 'fr'));39 assert(pn.trad.hasKey('NOTIF_NEW_NOTE_BUILDING', 'fr'));40 assert(pn.trad.hasKey('NOTIF_NEW_NOTE_CAMPUS', 'fr'));41 assert(pn.trad.hasKey('NOTIF_NEW_NOTE_CITY', 'fr'));42 assert(pn.trad.hasKey('NOTIF_NEW_NOTE_FLAT', 'fr'));43 assert(pn.trad.hasKey('NOTIF_NEW_OFFER_BUILDING', 'fr'));44 assert(pn.trad.hasKey('NOTIF_NEW_TOPIC_BUILDING', 'fr'));45 assert(pn.trad.hasKey('NOTIF_NEW_USER_BUILDING', 'fr'));46 assert(pn.trad.hasKey('NOTIF_NEW_VOTE_CITY', 'fr'));47 assert(pn.trad.hasKey('NOTIF_NEW_WORK_BUILDING', 'fr'));48 assert(pn.trad.hasKey('NOTIF_NEW_WORK_CAMPUS', 'fr'));49 assert(pn.trad.hasKey('NOTIF_NEW_WORK_CITY', 'fr'));50 assert(pn.trad.hasKey('NOTIF_NEW_WORK_FLAT', 'fr'));51 })52 }));53 it('replaces states', Mocker.mockIt(function(mokr){54 mokr.mock(config, 'endpoint', 'dum');55 var pn = new PushNotifier(config);56 return pn.trad.reload().then(_=>{57 var x = pn.trad.translate('NOTIF_LYYTI_STATUS_CHANGED', 'fr', {"title":"test asset","state":"OPENED"});58 assert.equal(x, 'Le statut de test asset est passé à Ouvert');59 })60 }));61 it('replaces alert obj with str', Mocker.mockIt(function(mokr){62 mokr.mock(config, 'endpoint', 'dum');63 var pn = new PushNotifier(config);64 mokr.mock(pn.trad, 'getLanguages', ()=>['fr','en'])...
Variables.js
Source:Variables.js
1#pragma strict2static var Coins : float;3static var Diamo : float;4static var Done : boolean;5static var Intro : boolean;6static var Pause : boolean;7static var FirstLoad : boolean;8static var Tutorial : boolean;9static var OptionO : boolean;10static var SocialBo : boolean;11static var ResetOp : boolean;12static var ResetSure : boolean;13static var TPause : boolean;14static var Movement : boolean;15static var Debugger : boolean;16static var InsCount : int;17function Start () 18{19 DontDestroyOnLoad(this);20 Setup();21 FirstLoad = true;22 Tutorial = false;23 Screen.sleepTimeout = SleepTimeout.NeverSleep;24 InsCount = 0;25}26function Update () 27{28}29static function Setup()30{31 if(!PlayerPrefs.HasKey("NoAds"))32 {33 PlayerPrefs.SetInt("NoAds",0);34 }35 if(!PlayerPrefs.HasKey("FreeAds"))36 {37 PlayerPrefs.SetInt("FreeAds",1);38 }39 if(!PlayerPrefs.HasKey("Sound"))40 {41 PlayerPrefs.SetInt("Sound",1);42 }43 if(!PlayerPrefs.HasKey("Tutorial"))44 {45 PlayerPrefs.SetInt("Tutorial",0);46 }47 if(!PlayerPrefs.HasKey("UTutorial"))48 {49 PlayerPrefs.SetInt("UTutorial",0);50 }51 if(!PlayerPrefs.HasKey("Slot1"))52 {53 PlayerPrefs.SetInt("Slot1",1);54 }55 if(!PlayerPrefs.HasKey("Slot2"))56 {57 PlayerPrefs.SetInt("Slot2",0);58 }59 if(!PlayerPrefs.HasKey("Slot3"))60 {61 PlayerPrefs.SetInt("Slot3",0);62 }63 if(!PlayerPrefs.HasKey("Slot4"))64 {65 PlayerPrefs.SetInt("Slot4",0);66 }67 if(!PlayerPrefs.HasKey("Slot5"))68 {69 PlayerPrefs.SetInt("Slot5",0);70 }71 if(!PlayerPrefs.HasKey("Slot6"))72 {73 PlayerPrefs.SetInt("Slot6",0);74 }75 if(!PlayerPrefs.HasKey("Slot7"))76 {77 PlayerPrefs.SetInt("Slot7",0);78 }79 if(!PlayerPrefs.HasKey("Slot8"))80 {81 PlayerPrefs.SetInt("Slot8",0);82 }83 if(!PlayerPrefs.HasKey("TotalUnlocks"))84 {85 PlayerPrefs.SetInt("TotalUnlocks",1);86 }87 if(!PlayerPrefs.HasKey("Level"))88 {89 PlayerPrefs.SetInt("Level",1);90 }91 if(!PlayerPrefs.HasKey("VisitedFacebook"))92 {93 PlayerPrefs.SetInt("VisitedFacebook",0);94 }95 if(!PlayerPrefs.HasKey("VisitedTwitter"))96 {97 PlayerPrefs.SetInt("VisitedTwitter",0);98 }99 if(!PlayerPrefs.HasKey("VisitedWebsite"))100 {101 PlayerPrefs.SetInt("VisitedWebsite",0);102 }103 if(!PlayerPrefs.HasKey("VisitedRate"))104 {105 PlayerPrefs.SetInt("VisitedRate",0);106 }107 if(!PlayerPrefs.HasKey("Bonus"))108 {109 PlayerPrefs.SetInt("Bonus",0);110 }111 if(!PlayerPrefs.HasKey("Streak"))112 {113 PlayerPrefs.SetInt("Streak",0);114 }115 NinjaUnits();116 OniUnits();117 Currency();118}119static function Currency()120{121 if(!PlayerPrefs.HasKey("Diamonds"))122 {123 PlayerPrefs.SetInt("Diamonds",0);124 }125 if(!PlayerPrefs.HasKey("TotalDiamonds"))126 {127 PlayerPrefs.SetInt("TotalDiamonds",0);128 }129 if(!PlayerPrefs.HasKey("TotalCoins"))130 {131 PlayerPrefs.SetInt("TotalCoins",0);132 }133 if(!PlayerPrefs.HasKey("Score"))134 {135 PlayerPrefs.SetInt("Score",0);136 }137 if(!PlayerPrefs.HasKey("BonusScore"))138 {139 PlayerPrefs.SetInt("BonusScore",0);140 }141 if(!PlayerPrefs.HasKey("TotalScore"))142 {143 PlayerPrefs.SetInt("TotalScore",0);144 }145 if(!PlayerPrefs.HasKey("Skill"))146 {147 PlayerPrefs.SetInt("Skill",0);148 }149 if(!PlayerPrefs.HasKey("BonusSkill"))150 {151 PlayerPrefs.SetInt("BonusSkill",0);152 }153 if(!PlayerPrefs.HasKey("TotalSkill"))154 {155 PlayerPrefs.SetInt("TotalSkill",0);156 }157 if(!PlayerPrefs.HasKey("TotalKills"))158 {159 PlayerPrefs.SetInt("TotalKills",0);160 }161}162static function NinjaUnits()163{164 if(!PlayerPrefs.HasKey("Swordsman"))165 {166 PlayerPrefs.SetInt("Swordsman",0);167 }168 if(!PlayerPrefs.HasKey("Nunchuckman"))169 {170 PlayerPrefs.SetInt("Nunchuckman",0);171 }172 if(!PlayerPrefs.HasKey("Throwingman"))173 {174 PlayerPrefs.SetInt("Throwingman",0);175 }176 if(!PlayerPrefs.HasKey("Longbowman"))177 {178 PlayerPrefs.SetInt("Longbowman",0);179 }180 if(!PlayerPrefs.HasKey("Woodman"))181 {182 PlayerPrefs.SetInt("Woodman",0);183 }184 if(!PlayerPrefs.HasKey("Chainman"))185 {186 PlayerPrefs.SetInt("Chainman",0);187 }188 if(!PlayerPrefs.HasKey("Saiman"))189 {190 PlayerPrefs.SetInt("Saiman",0);191 }192 if(!PlayerPrefs.HasKey("Clawman"))193 {194 PlayerPrefs.SetInt("Clawman",0);195 }196 if(!PlayerPrefs.HasKey("Unit1Level"))197 {198 PlayerPrefs.SetInt("Unit1Level",1);199 }200 if(!PlayerPrefs.HasKey("Unit2Level"))201 {202 PlayerPrefs.SetInt("Unit2Level",0);203 }204 if(!PlayerPrefs.HasKey("Unit3Level"))205 {206 PlayerPrefs.SetInt("Unit3Level",0);207 }208 if(!PlayerPrefs.HasKey("Unit4Level"))209 {210 PlayerPrefs.SetInt("Unit4Level",0);211 }212 if(!PlayerPrefs.HasKey("Unit5Level"))213 {214 PlayerPrefs.SetInt("Unit5Level",0);215 }216 if(!PlayerPrefs.HasKey("Unit6Level"))217 {218 PlayerPrefs.SetInt("Unit6Level",0);219 }220 if(!PlayerPrefs.HasKey("Unit7Level"))221 {222 PlayerPrefs.SetInt("Unit7Level",0);223 }224 if(!PlayerPrefs.HasKey("Unit8Level"))225 {226 PlayerPrefs.SetInt("Unit8Level",0);227 }228 if(!PlayerPrefs.HasKey("MinerLevel"))229 {230 PlayerPrefs.SetInt("MinerLevel",1);231 }232 if(!PlayerPrefs.HasKey("PagodaLevel"))233 {234 PlayerPrefs.SetInt("PagodaLevel",1);235 }236 if(!PlayerPrefs.HasKey("StoneLevel"))237 {238 PlayerPrefs.SetInt("StoneLevel",0);239 }240 if(PlayerPrefs.GetInt("StoneLevel") > 1)241 {242 PlayerPrefs.SetInt("StoneLevel",1);243 }244 if(!PlayerPrefs.HasKey("CoinsLevel"))245 {246 PlayerPrefs.SetInt("CoinsLevel",1);247 }248}249static function OniUnits()250{251 if(!PlayerPrefs.HasKey("OniUnit1Level"))252 {253 PlayerPrefs.SetInt("OniUnit1Level",1);254 }255 if(!PlayerPrefs.HasKey("OniUnit2Level"))256 {257 PlayerPrefs.SetInt("OniUnit2Level",1);258 }259 if(!PlayerPrefs.HasKey("OniUnit3Level"))260 {261 PlayerPrefs.SetInt("OniUnit3Level",1);262 }263 if(!PlayerPrefs.HasKey("OniUnit4Level"))264 {265 PlayerPrefs.SetInt("OniUnit4Level",1);266 }267 if(!PlayerPrefs.HasKey("OniUnit5Level"))268 {269 PlayerPrefs.SetInt("OniUnit5Level",1);270 }271 if(!PlayerPrefs.HasKey("OniUnit6Level"))272 {273 PlayerPrefs.SetInt("OniUnit6Level",1);274 }275 if(!PlayerPrefs.HasKey("OniUnit7Level"))276 {277 PlayerPrefs.SetInt("OniUnit7Level",1);278 }279 if(!PlayerPrefs.HasKey("OniUnit8Level"))280 {281 PlayerPrefs.SetInt("OniUnit8Level",1);282 }...
recipe-filter-test.js
Source:recipe-filter-test.js
...12 it('hasKeyã«ãªãã¸ã§ã¯ã以å¤ã渡ãã¨ããã®ã¾ã¾è¿ã£ã¦ããã', function() {13 var hasKey, test;14 hasKey = createFilter('hasKey');15 test = 'test';16 expect(hasKey(test, 't')).toBe('test');17 test = 10;18 expect(hasKey(test, 0)).toBe(10);19 test = function() {};20 expect(hasKey(test, 'f').toString()).toBe(test.toString());21 });22 it('hasKeyã«ãªãã¸ã§ã¯ãã渡ãã¨ããã¼ã«queryãå«ããã®ã§ãã£ã«ã¿ã¼ããããã', function() {23 var hasKey, test;24 hasKey = createFilter('hasKey');25 test = {26 test: 'test',27 func: function() {},28 array: ['test'],29 date: new Date(100)30 };31 expect(_.isEqual(hasKey(test, 's'), {32 test: 'test'33 })).toBe(true);34 expect(_.isEqual(hasKey(test, 0), {})).toBe(true);35 expect(_.isEqual(hasKey(test, 'e'), {36 test: 'test',37 date: test.date38 })).toBe(true);39 test = [40 'test',41 function() {},42 ['test'],43 new Date(100)44 ];45 expect(_.isEqual(hasKey(test, 's'), [])).toBe(true);46 expect(_.isEqual(hasKey(test, '0'), ['test'])).toBe(true);47 expect(_.isEqual(hasKey(test, 0), ['test'])).toBe(true);48 });49 });...
test.js
Source:test.js
1var expect = require('chai').expect;2var hasAttr = require('../index');3var SINGLE_LEVEL_JSON = {4 'name': 'Arshad Kazmi',5 'github': 'arshadkazmi42',6 'twitter': '@arshadkazmi42',7};8var MULTI_LEVEL_JSON = {9 'name': 'Arshad Kazmi',10 'profile': {11 'github': {12 'username': 'arshadkazmi42',13 'repos': [14 {15 'repo_name': 'hasattr',16 'url': 'https://github.com/arshadkazmi42/hasattr',17 },18 ],19 },20 'twitter': {21 'username': 'arshadkazmi42',22 },23 },24};25describe('Search the key in all types of json', function() {26 it('should find the key in single level json', function() {27 var hasKey = hasAttr('name', SINGLE_LEVEL_JSON);28 expect(hasKey).to.be.true;29 hasKey = hasAttr('repo_name', SINGLE_LEVEL_JSON);30 expect(hasKey).to.be.false;31 });32 it('should find the key in nested level json', function() {33 var hasKey = hasAttr('github', MULTI_LEVEL_JSON);34 expect(hasKey).to.be.true;35 hasKey = hasAttr('repo_name', MULTI_LEVEL_JSON);36 expect(hasKey).to.be.true;37 });...
hasKey.test.js
Source:hasKey.test.js
...8test('hasKey is a Function', () => {9 expect(hasKey).toBeInstanceOf(Function);10});11test('hasKey returns true for simple property', () => {12 expect(hasKey(data, ['a'])).toBe(true);13});14test('hasKey returns true for object property', () => {15 expect(hasKey(data, ['b'])).toBe(true);16});17test('hasKey returns true for nested property', () => {18 expect(hasKey(data, ['b', 'c'])).toBe(true);19});20test('hasKey returns true for property with dots', () => {21 expect(hasKey(data, ['d.e'])).toBe(true);22});23test('hasKey returns true for property with dots and same sibling key', () => {24 expect(hasKey(data, ['b.d'])).toBe(true);25});26test('hasKey returns false for non-existent property', () => {27 expect(hasKey(data, ['f'])).toBe(false);28});29test('hasKey returns false for virtual nested property', () => {30 expect(hasKey(data, ['d'])).toBe(false);31});32test('hasKey returns false for empty key list', () => {33 expect(hasKey(data, [])).toBe(false);...
Using AI Code Generation
1const unexpected = require('unexpected');2const unexpectedImmutable = require('unexpected-immutable');3const Immutable = require('immutable');4 .clone()5 .use(unexpectedImmutable);6const myMap = Immutable.Map({a: 1, b: 2, c: 3});7expect(myMap, 'to have key', 'a');8expect(myMap, 'to have key', 'd');9const unexpected = require('unexpected');10const unexpectedImmutable = require('unexpected-immutable');11const Immutable = require('immutable');12 .clone()13 .use(unexpectedImmutable);14const myMap = Immutable.Map({a: 1, b: 2, c: 3});15expect(myMap, 'to have key', 'a');16expect(myMap, 'to have key', 'd');
Using AI Code Generation
1var expect = require('unexpected');2var obj = { a: 1, b: 2, c: 3 };3AssertionError: expected { a: 1, b: 2, c: 3 } to have key 'd'4var expect = require('unexpected');5var obj = { a: 1, b: 2, c: 3 };6AssertionError: expected { a: 1, b: 2, c: 3 } to have key 'd' with value 4
Using AI Code Generation
1const hasKey = require('unexpected').hasKey;2hasKey('foo', 'bar');3const hasKey = require('unexpected').hasKey;4hasKey('foo', 'bar');5If you want to use the hasKey function, you need to import it from the unexpected module. This is what the documentation tells you to do:6import { hasKey } from 'unexpected';
Using AI Code Generation
1var expect = require('unexpected')2 .clone()3 .use(require('unexpected-sinon'));4describe('test', function() {5 it('should pass', function() {6 expect('test', 'to have key', 'length');7 });8});9var expect = require('unexpected-sinon');10describe('test', function() {11 it('should pass', function() {12 expect('test', 'to have key', 'length');13 });14});
Using AI Code Generation
1var expect = require('unexpected');2var unexpected = require('unexpected');3var hasKey = unexpected.hasKey;4var expect = require('unexpected').clone();5expect.addAssertion('<object> [not] to have key <string>', function(expect, subject, key) {6 expect(subject, '[not] to have key', key);7});8expect.addAssertion('<object> [not] to have key <string>', function(expect, subject, key) {9 expect(subject, '[not] to have key', key);10});11describe('Test suite', function() {12 it('Test case', function() {13 var obj = {14 };15 expect(obj, 'to have key', 'name');16 });17});
Using AI Code Generation
1var hasKey = require('unexpected').hasKey;2var expect = require('unexpected').clone().use(require('unexpected-sinon'));3var sinon = require('sinon');4function add(a,b){5 return a+b;6}7describe('add', function(){8 it('should add two numbers', function(){9 expect(add(1,2), 'to equal', 3);10 });11});12function add(a,b){13 return a+b;14}15describe('add', function(){16 it('should add two numbers', function(){17 expect(add(1,2), 'to equal', 3);18 });19});20function add(a,b){21 return a+b;22}23describe('add', function(){24 it('should add two numbers', function(){25 expect(add(1,2), 'to equal', 3);26 });27});28function add(a,b){29 return a+b;30}31describe('add', function(){32 it('should add two numbers', function(){33 expect(add(1,2), 'to equal', 3);34 });35});36function add(a,b){37 return a+b;38}39describe('add', function(){40 it('should add two numbers', function(){41 expect(add(1,2), 'to equal', 3);42 });43});44function add(a,b){45 return a+b;46}47describe('add', function(){48 it('should add two numbers', function(){49 expect(add(1,2), 'to equal', 3);50 });51});52function add(a,b){53 return a+b;54}55describe('add', function(){56 it('should add two numbers', function(){57 expect(add(1,2), 'to equal', 3);58 });59});60function add(a,b){61 return a+b;62}63describe('add', function(){64 it('should add two numbers', function(){65 expect(add(1,2), 'to equal', 3);66 });67});68function add(a,b){69 return a+b;70}71describe('add', function(){72 it('should add two numbers', function(){73 expect(add(1,2), 'to equal', 3);74 });75});76function add(a,b){
Using AI Code Generation
1var expect = require('unexpected');2var obj = {foo: 'bar'};3expect(obj, 'to have key', 'foo');4var unexpected = require('unexpected');5unexpected.addAssertion('<any> to have key <string>', function (expect, subject, value) {6 expect(subject, 'to have property', value);7});8var unexpected = require('unexpected');9unexpected.addAssertion('<any> to have property <string>', function (expect, subject, value) {10 expect(subject, 'to have property', value);11});12var expect = require('unexpected');13var MyClass = require('../src/MyClass');14describe('MyClass', function () {15 it('should create an instance with the same properties as the original', function () {16 var myClass = new MyClass();17 myClass.foo = 'bar';18 var newClass = myClass.create();19 expect(newClass, 'to have properties', myClass);20 });21});22expect(newClass, 'to have properties', myClass);23expect(newClass, 'to have properties', myClass.properties);24expect(newClass, 'to have properties', myClass.property);25expect(newClass, 'to have properties', myClass.foo);26expect(newClass, 'to have properties', myClass.foo);27expect(newClass, 'to have properties', myClass.foo.bar);28expect(newClass, 'to have properties', myClass.foo.bar.properties);29var expect = require("unexpected");30var MyClass = require("./MyClass");31describe("MyClass", function () {32 it("should create an instance with the same properties as the original
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!!