Best JavaScript code snippet using wpt
json2typescript.unit.ts
Source:json2typescript.unit.ts
...291 // Unmapped property should not return mapping, even though property is the same name as a mapped property292 // on another class293 expect((<any>jsonConvert).getClassPropertyMappingOptions(duplicateCat1, "district")).toBeNull();294 });295 describe("convertProperty()", () => {296 let jsonConvert: JsonConvert;297 beforeEach(() => {298 jsonConvert = new JsonConvert();299 jsonConvert.ignorePrimitiveChecks = false;300 jsonConvert.valueCheckingMode = ValueCheckingMode.ALLOW_NULL;301 });302 describe("expectedJsonType unmapped", () => {303 it("should return the value if expected type is Any, Object, or null", () => {304 expect((<any>jsonConvert).convertProperty(Any, cat1, true)).toBe(cat1);305 expect((<any>jsonConvert).convertProperty(Object, cat1, false)).toBe(cat1);306 expect((<any>jsonConvert).convertProperty(null, cat1, true)).toBe(cat1);307 });308 it("should NOT throw an error even if null not allowed", () => {309 jsonConvert.valueCheckingMode = ValueCheckingMode.DISALLOW_NULL;310 expect((<any>jsonConvert).convertProperty(Any, null, true)).toBeNull("expected Any");311 expect((<any>jsonConvert).convertProperty(Object, null, false)).toBeNull("expected Object");312 expect((<any>jsonConvert).convertProperty(null, null, true)).toBeNull("expected null");313 });314 });315 describe("expectedJsonType mapped class", () => {316 it("should correctly serialize/deserialize a mapped object property", () => {317 expect((<any>jsonConvert).convertProperty(Cat, cat2, PropertyConvertingMode.MAP_NULLABLE, true)).toEqual(cat2JsonObject);318 expect((<any>jsonConvert).convertProperty(Cat, cat1JsonObject, PropertyConvertingMode.MAP_NULLABLE, false)).toEqual(cat1);319 });320 it("should return null if allowed", () => {321 jsonConvert.valueCheckingMode = ValueCheckingMode.ALLOW_OBJECT_NULL;322 expect((<any>jsonConvert).convertProperty(Cat, null, PropertyConvertingMode.MAP_NULLABLE, true)).toEqual(null);323 expect((<any>jsonConvert).convertProperty(Cat, null, PropertyConvertingMode.MAP_NULLABLE, false)).toEqual(null);324 });325 it("should throw an error if null not allowed", () => {326 jsonConvert.valueCheckingMode = ValueCheckingMode.DISALLOW_NULL;327 expect(() => (<any>jsonConvert).convertProperty(Cat, null, PropertyConvertingMode.MAP_NULLABLE, true))328 .toThrowError();329 expect(() => (<any>jsonConvert).convertProperty(Cat, null, PropertyConvertingMode.MAP_NULLABLE, false))330 .toThrowError();331 });332 it("should throw an error if value is an array", () => {333 expect(() => (<any>jsonConvert).convertProperty(Cat, [cat1, cat2], true))334 .toThrowError();335 });336 });337 describe("expectedJsonType primitive", () => {338 it("should correctly serialize and deserialize expected primitive values", () => {339 expect((<any>jsonConvert).convertProperty(String, "Andreas", PropertyConvertingMode.MAP_NULLABLE, false)).toBe("Andreas");340 expect((<any>jsonConvert).convertProperty(Number, 2.2, PropertyConvertingMode.MAP_NULLABLE, false)).toBe(2.2);341 expect((<any>jsonConvert).convertProperty(Boolean, true, PropertyConvertingMode.MAP_NULLABLE, true)).toBe(true);342 });343 it("should error if expected JSON type doesn't match value type", () => {344 expect(() => (<any>jsonConvert).convertProperty(Number, "Andreas", PropertyConvertingMode.MAP_NULLABLE, false)).toThrowError();345 expect(() => (<any>jsonConvert).convertProperty(String, true, PropertyConvertingMode.MAP_NULLABLE, true)).toThrowError();346 expect(() => (<any>jsonConvert).convertProperty(Boolean, 54, PropertyConvertingMode.MAP_NULLABLE, true)).toThrowError();347 });348 it("should return value if expected JSON type doesn't match value type but flag set", () => {349 jsonConvert.ignorePrimitiveChecks = true;350 expect((<any>jsonConvert).convertProperty(Number, "Andreas", PropertyConvertingMode.MAP_NULLABLE, false)).toBe("Andreas");351 expect((<any>jsonConvert).convertProperty(String, true, PropertyConvertingMode.MAP_NULLABLE, true)).toBe(true);352 expect((<any>jsonConvert).convertProperty(Boolean, 54, PropertyConvertingMode.MAP_NULLABLE, true)).toBe(54);353 });354 it("should return null if nulls allowed", () => {355 expect((<any>jsonConvert).convertProperty(String, null, PropertyConvertingMode.MAP_NULLABLE, false)).toBeNull("expected string should be null");356 expect((<any>jsonConvert).convertProperty(Number, null, PropertyConvertingMode.MAP_NULLABLE, false)).toBeNull("expected number should be null");357 expect((<any>jsonConvert).convertProperty(Boolean, null, PropertyConvertingMode.MAP_NULLABLE, true)).toBeNull("expected boolean should be null");358 });359 it("should throw an error if only object nulls allowed", () => {360 jsonConvert.valueCheckingMode = ValueCheckingMode.ALLOW_OBJECT_NULL;361 expect(() => (<any>jsonConvert).convertProperty(String, null, PropertyConvertingMode.MAP_NULLABLE, false))362 .toThrowError();363 expect(() => (<any>jsonConvert).convertProperty(Number, null, PropertyConvertingMode.MAP_NULLABLE, false))364 .toThrowError();365 expect(() => (<any>jsonConvert).convertProperty(Boolean, null, PropertyConvertingMode.MAP_NULLABLE, true))366 .toThrowError();367 });368 it("should throw an error if value is an array", () => {369 expect(() => (<any>jsonConvert).convertProperty(String, ["Andreas", "Joseph"], PropertyConvertingMode.MAP_NULLABLE, true))370 .toThrowError();371 });372 });373 describe("expectedJsonType array", () => {374 it("should return value as-is if expected type is empty", () => {375 const pseudoArray = {376 "0": "Andreas",377 "1": {"0": true, "1": 2.2},378 };379 expect((<any>jsonConvert).convertProperty([], pseudoArray, PropertyConvertingMode.MAP_NULLABLE, true)).toBe(pseudoArray);380 expect((<any>jsonConvert).convertProperty([], cat1, PropertyConvertingMode.MAP_NULLABLE, false)).toBe(cat1);381 });382 it("should return empty array if value is empty", () => {383 expect((<any>jsonConvert).convertProperty([String], [], PropertyConvertingMode.MAP_NULLABLE, true)).toEqual([]);384 expect((<any>jsonConvert).convertProperty([String, [Boolean, Number]], [], PropertyConvertingMode.PASS_NULLABLE, false)).toEqual([]);385 expect((<any>jsonConvert).convertProperty([Cat], [], PropertyConvertingMode.MAP_NULLABLE, false)).toEqual([]);386 });387 it("should correctly handle array of object types", () => {388 jsonConvert.valueCheckingMode = ValueCheckingMode.ALLOW_NULL;389 expect((<any>jsonConvert).convertProperty([Cat], [cat1, cat2], PropertyConvertingMode.PASS_NULLABLE, true)).toEqual([cat1JsonObject, cat2JsonObject]);390 expect((<any>jsonConvert).convertProperty([Cat], [cat1JsonObject, cat2JsonObject], PropertyConvertingMode.PASS_NULLABLE, false)).toEqual([cat1, cat2]);391 });392 it("should correctly handle expected nested array types", () => {393 expect((<any>jsonConvert).convertProperty([String, [Boolean, Number]], ["Andreas", [true, 2.2]], false))394 .toEqual(["Andreas", [true, 2.2]]);395 expect((<any>jsonConvert).convertProperty([String, [Boolean, Number]], {396 "0": "Andreas",397 "1": {"0": true, "1": 2.2},398 }, true)).toEqual(["Andreas", [true, 2.2]]);399 });400 it("should expand expected array type as needed without affecting original mapping", () => {401 const expectedJsonType = [String];402 expect((<any>jsonConvert).convertProperty(expectedJsonType, ["Andreas", "Joseph", "Albert"], PropertyConvertingMode.MAP_NULLABLE, true))403 .toEqual(["Andreas", "Joseph", "Albert"]);404 expect(expectedJsonType).toEqual([String]);405 expect((<any>jsonConvert).convertProperty(expectedJsonType, {406 "0": "Andreas",407 "1": "Joseph",408 "2": "Albert",409 }, PropertyConvertingMode.MAP_NULLABLE))410 .toEqual(["Andreas", "Joseph", "Albert"]);411 expect(expectedJsonType).toEqual([String]);412 });413 it("should throw an error if expected array and value is primitive", () => {414 expect(() => (<any>jsonConvert).convertProperty([String], "Andreas", PropertyConvertingMode.MAP_NULLABLE))415 .toThrowError();416 expect(() => (<any>jsonConvert).convertProperty([], "Andreas", PropertyConvertingMode.MAP_NULLABLE))417 .toThrowError();418 });419 it("should return null if nulls allowed", () => {420 expect((<any>jsonConvert).convertProperty([String], null, PropertyConvertingMode.MAP_NULLABLE, true)).toEqual(null);421 expect((<any>jsonConvert).convertProperty([String, [Boolean, Number]], null, PropertyConvertingMode.MAP_NULLABLE, true)).toEqual(null);422 });423 it("should throw an error if nulls disallowed", () => {424 jsonConvert.valueCheckingMode = ValueCheckingMode.DISALLOW_NULL;425 expect(() => (<any>jsonConvert).convertProperty([String], null, PropertyConvertingMode.MAP_NULLABLE, true))426 .toThrowError();427 expect(() => (<any>jsonConvert).convertProperty([String, [Boolean, Number]], null, PropertyConvertingMode.MAP_NULLABLE, true))428 .toThrowError();429 });430 });431 });432 it("getObjectValue()", () => {433 expect((<any>jsonConvert).getObjectValue({"name": "Andreas"}, "name")).toBe("Andreas");434 expect(() => (<any>jsonConvert).getObjectValue({"nAmE": "Andreas"}, "NaMe")).toThrow();435 jsonConvert.propertyMatchingRule = PropertyMatchingRule.CASE_INSENSITIVE;436 expect((<any>jsonConvert).getObjectValue({"nAmE": "Andreas"}, "NaMe")).toBe("Andreas");437 jsonConvert.propertyMatchingRule = PropertyMatchingRule.CASE_STRICT;438 });439 });440 // JSON2TYPESCRIPT TYPES441 describe("json2typescript types", () => {...
converter.spec.ts
Source:converter.spec.ts
1import {Converter} from './converter';2import {ConvertProperty, Convertable} from './decorators';3import {assert} from 'chai';4import {ConversionError, Undefined} from './types';5class ConvertSource {6 name = 'ConvertSource';7 val1 = 1;8 // Getterãã³ãã¼ããããã¨ã確èªãã9 get calculated(): string {10 return 'calculated';11 }12}13class SubConvertSource extends ConvertSource {14 name = 'SubConvertSource';15 val2 = 2;16 get subCalculated(): string {17 return 'subCalculated';18 }19}20class SubSubConvertSource extends SubConvertSource {21 name = 'SubSubConvertSource';22 val3 = 3;23}24class NestedClass {25 @ConvertProperty()26 s: string;27}28class ConvertTarget {29 @ConvertProperty()30 s: string;31 @ConvertProperty()32 n: number;33 @ConvertProperty()34 d: Date;35 @ConvertProperty()36 b: boolean;37 @ConvertProperty()38 nil: null;39 /**40 * 常ã«undefinedã«ãªã41 */42 @ConvertProperty({type: Undefined})43 undef: string;44 @ConvertProperty()45 nestedPlain: {46 s: string;47 sa: string[];48 };49 @ConvertProperty()50 nestedClass: NestedClass;51 // design:type ã¡ã¿ãã¼ã¿ãåºåãããªããããåå¤æãçºçããªã52 noConvert: number;53 // Getter54 @ConvertProperty()55 calculated: string;56}57class SubConvertTarget extends ConvertTarget {58 // Getter59 @ConvertProperty()60 subCalculated: string;61}62class SubSubConvertTarget extends SubConvertTarget {63 @ConvertProperty() name: string;64 @ConvertProperty() val1: number;65 @ConvertProperty() val2: number;66 @ConvertProperty() val3: number;67}68class ObjectID {69 constructor(private s: string) {70 }71 toString(): string {72 return this.s;73 }74}75function ThirdPartyDecorator(): any {76 return function (): any {};77}78@Convertable({79 target: 'all',80 suppressConversionError: false,81 excludes: ['n'],82})83class OptionSpecified {84 @ConvertProperty()85 s: string;86 @ConvertProperty()87 n: number;88 @ThirdPartyDecorator()89 decoratedByThirdParty: string;90 notDecorated: string;91}92describe('converter', () => {93 describe('convert()', () => {94 it ('nullãundefinedã¯ãBooleanã¸ã®å¤æãæ示ããã¨ãã ãfalseã«ãªããããã以å¤ã¯ãã®ã¾ã¾', () => {95 const converter = new Converter();96 assert.isNull(converter.convert(null, String));97 assert.isUndefined(converter.convert(undefined, String));98 assert.isNull(converter.convert(null, Date));99 assert.isUndefined(converter.convert(undefined, Date));100 assert.isNull(converter.convert(null, Number));101 assert.isUndefined(converter.convert(undefined, Number));102 assert.isNull(converter.convert(null, Object));103 assert.isUndefined(converter.convert(undefined, Object));104 // booleanã«å¤æãããã¨ããã¨ãã ãfalseã«ãªã105 assert.isFalse(converter.convert(null, Boolean));106 assert.isFalse(converter.convert(undefined, Boolean));107 assert.isNull(converter.convert(null, ConvertTarget));108 assert.isUndefined(converter.convert(undefined, ConvertTarget));109 assert.propertyVal(converter.convert({s: undefined}, ConvertTarget), 's', undefined, 'undefined is not changed');110 assert.propertyVal(converter.convert({s: null}, ConvertTarget), 's', null, 'null is not changed');111 });112 it('æ§ã
ãªåããstringã¸ã®å¤æãããã©ã«ãã§è¡ãã', () => {113 const converter = new Converter();114 const date = new Date();115 assert.propertyVal(converter.convert({s: '123'}, ConvertTarget), 's', '123', 'string to string');116 assert.propertyVal(converter.convert({s: 123}, ConvertTarget), 's', '123', 'number to string');117 assert.equal(converter.convert({s: date}, ConvertTarget).s, date.toISOString(), 'date to string');118 assert.propertyVal(converter.convert({s: true}, ConvertTarget), 's', 'true', 'boolean to string');119 assert.propertyVal(converter.convert({s: {}}, ConvertTarget), 's', '[object Object]', 'object to string');120 });121 it('æ§ã
ãªåããnumberã¸ã®å¤æãããã©ã«ãã§è¡ãã', () => {122 const converter = new Converter();123 const date = new Date();124 assert.propertyVal(converter.convert({n: '123'}, ConvertTarget), 'n', 123, 'string to number');125 assert.propertyVal(converter.convert({n: 123}, ConvertTarget), 'n', 123, 'number to number');126 assert.isNaN(converter.convert({n: NaN}, ConvertTarget).n, 'NaN to NaN');127 assert.throw(() => converter.convert({n: date}, ConvertTarget));128 assert.throw(() => converter.convert({n: true}, ConvertTarget));129 assert.throw(() => converter.convert({n: false}, ConvertTarget));130 assert.throw(() => converter.convert({n: {}}, ConvertTarget));131 });132 it('æ§ã
ãªåããDateã¸ã®å¤æãããã©ã«ãã§è¡ãã', () => {133 const converter = new Converter();134 const date = new Date();135 assert.equal(converter.convert({d: date}, ConvertTarget).d.getTime(), date.getTime(), 'date to date');136 assert.equal(137 converter.convert({d: date.toISOString()}, ConvertTarget).d.getTime(), date.getTime(), 'ISO string to date');138 assert.equal(139 converter.convert({d: date.toDateString()}, ConvertTarget).d.getTime(),140 new Date(date.toDateString()).getTime(), 'Date string to date');141 assert.equal(converter.convert({d: 123}, ConvertTarget).d.getTime(), 123, 'number to date');142 assert.throw(() => converter.convert({d: true}, ConvertTarget));143 assert.throw(() => converter.convert({d: false}, ConvertTarget));144 assert.throw(() => converter.convert({d: {}}, ConvertTarget));145 });146 it('æ§ã
ãªåããbooleanã¸ã®å¤æãããã©ã«ãã§è¡ãã', () => {147 const converter = new Converter();148 const date = new Date();149 assert.propertyVal(converter.convert({b: '123'}, ConvertTarget), 'b', true, 'string to boolean');150 assert.propertyVal(converter.convert({b: 123}, ConvertTarget), 'b', true, 'number to boolean');151 assert.equal(converter.convert({b: date}, ConvertTarget).b, true, 'date to boolean');152 assert.propertyVal(converter.convert({b: true}, ConvertTarget), 'b', true, 'boolean to boolean');153 assert.propertyVal(converter.convert({b: {}}, ConvertTarget), 'b', true, 'object to boolean');154 assert.propertyVal(converter.convert({b: 0}, ConvertTarget), 'b', false);155 assert.propertyVal(converter.convert({b: -0}, ConvertTarget), 'b', false);156 assert.propertyVal(converter.convert({b: null}, ConvertTarget), 'b', false);157 assert.propertyVal(converter.convert({b: false}, ConvertTarget), 'b', false);158 assert.propertyVal(converter.convert({b: NaN}, ConvertTarget), 'b', false);159 assert.propertyVal(converter.convert({b: undefined}, ConvertTarget), 'b', false);160 });161 it('ãã¬ã¼ã³ãªãªãã¸ã§ã¯ãã¯ãã®ã¾ã¾ã³ãã¼ããã', () => {162 const converter = new Converter();163 const result = converter.convert({nestedPlain: {s: 123, sa: ['def', 'ghi']}}, ConvertTarget);164 assert.instanceOf(result.nestedPlain, Object);165 // nestedPlain.sã¯åå®ç¾©ä¸ã¯stringã ãããã¬ã¼ã³ãªå
¥ãåããããã£ã¯åå¤æãèµ·ãããªã166 assert.deepEqual(result.nestedPlain, <any>{s: 123, sa: ['def', 'ghi']});167 });168 it('ãã¬ã¼ã³ãªãªãã¸ã§ã¯ãããã¯ã©ã¹ã¤ã³ã¹ã¿ã³ã¹ã¸ã®å¤æãããã©ã«ãã§è¡ãã', () => {169 const converter = new Converter();170 const result = converter.convert({nestedClass: {s: 123}}, ConvertTarget);171 assert.instanceOf(result.nestedClass, NestedClass);172 assert.equal(result.nestedClass.s, '123');173 });174 it('Undefinedåãæå®ãããããããã£ã¯å¸¸ã«undefinedã¨ãªã', () => {175 const converter = new Converter();176 const result = converter.convert({undef: '123'}, ConvertTarget);177 assert.isUndefined(result.undef);178 });179 it('é
åå
¨ã¦ã®è¦ç´ ãå¤æããã', () => {180 const converter = new Converter();181 const array = converter.convert([1, 2, 3], String);182 assert.sameOrderedMembers(['1', '2', '3'], array);183 });184 });185 describe('ConvertOptions', () => {186 it('ãªãã·ã§ã³ã¯ã¡ã½ããå¼æ°ããã³ã¬ã¼ã¿ãConverterã®é ã«åªå
ããã', () => {187 // Converterã®ãªãã·ã§ã³ã«æå®ãã¦ã¿ããããã³ã¬ã¼ã¿ã®æå®ï¼'n'ã®ã¿é¤å¤ï¼ãåªå
ãããã188 const converter = new Converter({excludes: ['s', 'n'], target: 'decorated'});189 let result = converter.convert({190 s: 'abc',191 n: 123192 }, OptionSpecified);193 assert.equal(result.s, 'abc');194 assert.isUndefined(result.n);195 // ã¡ã½ããå¼æ°ã§ãexcludesã空ã«ãã196 result = converter.convert({197 s: 'abc',198 n: 123199 }, OptionSpecified, {excludes: []});200 assert.equal(result.s, 'abc');201 assert.equal(result.n, 123);202 });203 it('suppressConversionErrorã«trueãæå®ããã¦ããã¨ãConversionErrorã®çºçãæå¶ããã', () => {204 const converter = new Converter();205 // ã¾ãConversionErrorã®çºçã確èª206 assert.throws(() => converter.convert({n: 'abc'}, ConvertTarget), ConversionError);207 // æå¶208 assert.doesNotThrow(() => converter.convert({n: 'abc'}, ConvertTarget, {suppressConversionError: true}));209 // Dateåã§ã確èª210 assert.throws(() => converter.convert({d: 'abc'}, ConvertTarget), ConversionError);211 assert.doesNotThrow(() => converter.convert({d: 'abc'}, ConvertTarget, {suppressConversionError: true}));212 });213 it('includes: "all"ãæå®ããã¦ãã¦å¤æå
ã®åãä¸æãªå ´åãå¤ãã»ããããã', () => {214 const converter = new Converter();215 const result = converter.convert({notDecorated: 'abc'}, OptionSpecified, {target: 'all'});216 assert.equal(result.notDecorated, 'abc');217 });218 it('includes: "typed"ãæå®ããã¦ããã¨ãå¤æå
ã®åæ
å ±ãåå¾ã§ããããããã£ã«ã®ã¿å¤ãã»ããããã', () => {219 const converter = new Converter();220 const result = converter.convert({221 s: 'abc',222 decoratedByThirdParty: 'abc',223 notDecorated: 'abc'224 }, OptionSpecified, {target: 'typed'});225 assert.equal(result.s, 'abc');226 assert.equal(result.decoratedByThirdParty, 'abc');227 assert.isUndefined(result.notDecorated);228 });229 it('includes: "decorated"ãæå®ããã¦ããã¨ã@ConvertPropertyãä»ä¸ãããããããã£ã«ã®ã¿å¤ãã»ããããã', () => {230 const converter = new Converter();231 const result = converter.convert({232 s: 'abc',233 decoratedByThirdParty: 'def',234 notDecorated: 'ghi'235 }, OptionSpecified, {target: 'decorated'});236 assert.equal(result.s, 'abc');237 assert.isUndefined(result.decoratedByThirdParty);238 assert.isUndefined(result.notDecorated);239 });240 it('excludesãæå®ããã¦ããããããã£ã«ã¯å¤ãã»ãããããªã', () => {241 const converter = new Converter();242 // s以å¤ã®ããããã£ããã¹ã¦é¤å¤ãã243 const result = converter.convert({244 s: 'abc',245 b: true,246 n: 123,247 noConvert: 'abc',248 }, ConvertTarget, {249 excludes: [250 'b',251 (key) => key === 'n',252 /no/253 ]254 });255 assert.deepEqual(result, <any>{s: 'abc'});256 });257 it('_getAllProperties ã§ãã¹ã¦ã®ããããã£ãåæã§ãã', () => {258 const converter = new Converter();259 const src = new SubSubConvertSource();260 const keys = converter._getAllProperties(src);261 // console.log('keys', keys);262 assert.deepEqual(keys, ['name', 'val1', 'val2', 'val3', 'subCalculated', 'calculated']);263 });264 it('Getterãã³ãã¼ï¼å¤æããã', () => {265 const converter = new Converter();266 // s以å¤ã®ããããã£ããã¹ã¦é¤å¤ãã267 const result = converter.convert(new ConvertSource(), ConvertTarget);268 assert.deepEqual(result, <any>{calculated: 'calculated'});269 });270 it('親ã¯ã©ã¹ã®Getterãã³ãã¼ï¼å¤æããã', () => {271 const converter = new Converter();272 const src = new SubSubConvertSource();273 const result = converter.convert(src, SubSubConvertTarget);274 const resultJson = JSON.parse(JSON.stringify(result));275 assert.deepEqual(resultJson, <any>{276 name: 'SubSubConvertSource',277 val1: 1,278 val2: 2,279 val3: 3,280 calculated: 'calculated',281 subCalculated: 'subCalculated',282 });283 });284 it('suppressConversionError', () => {285 });286 });287 describe('register()', () => {288 it('æ°ããã³ã³ãã¼ã¿é¢æ°ãç»é²ã§ãã', () => {289 const converter = new Converter();290 converter.register(ObjectID, (value) => new ObjectID(String(value)));291 const objectId = converter.convert('abc', ObjectID);292 assert.instanceOf(objectId, ObjectID);293 assert.equal(objectId.toString(), 'abc');294 });295 });...
FlareShapeGradientStroke.js
Source:FlareShapeGradientStroke.js
...14 const paintData = this._PaintData;15 const gradientType = paintData.gradientType;16 const nodeType = gradientType === 1 ? gradientNodeTypes.GRADIENT_STROKE : gradientNodeTypes.RADIAL_GRADIENT_STROKE;17 const node = new FlareNode('Gradient Stroke', null, nodeType);18 const opacity = convertProperty(paintData.opacity, propertyTypes.OPACITY, animations, id, 0.01, offsetTime);19 node.opacity = opacity20 const width = convertProperty(this._PaintData.width, 'strokeWidth', animations, id, 1, offsetTime)21 const start = convertProperty(paintData.startPoint, propertyTypes.GRADIENT_START, animations, id, 1, offsetTime);22 const end = convertProperty(paintData.endPoint, propertyTypes.GRADIENT_END, animations, id, 1, offsetTime);23 const colorStops = this._GradientStops.convert(animations, offsetTime, id, start, end);24 const radialProperties = {}25 //TODO: find out if radial properties are supported26 /*if (gradientType === 2) {27 const secondaryRadiusScale = convertProperty(paintData.highlightLength, propertyTypes.GRADIENT_HIGHLIGHT_LENGTH, animations, id, 0.01, offsetTime);28 radialProperties.secondaryRadiusScale = secondaryRadiusScale29 }*/30 const fillRule = "nonzero"31 return {32 ...node.convert(),33 colorStops,34 fillRule,35 start,36 end,37 ...radialProperties,38 cap: lineCapTypes[this._PaintData.lineCap],39 join: lineJoinTypes[this._PaintData.lineJoin],40 width,41 }...
Using AI Code Generation
1var wpt = require('wpt');2wpt.convertProperty('font-size', '1.5em', function(err, result) {3 if (err) {4 console.log(err);5 } else {6 console.log(result);7 }8});9var wpt = require('wpt');10wpt.convertValues('font-size', '1.5em 2em 2.5em', function(err, result) {11 if (err) {12 console.log(err);13 } else {14 console.log(result);15 }16});17var wpt = require('wpt');18wpt.getBrowserInfo(function(err, result) {19 if (err) {20 console.log(err);21 } else {22 console.log(result);23 }24});25var wpt = require('wpt');26wpt.getLocations(function(err, result) {27 if (err) {28 console.log(err);29 } else {30 console.log(result);31 }32});
Using AI Code Generation
1const wptools = require('wptools');2const fs = require('fs');3const readline = require('readline');4const prompt = require('prompt');5var data = fs.readFileSync('list.txt','utf8');6var lines = data.split('\n');7var newFile = [];8var failed = [];9var noInfo = [];10var noExtract = [];11var noImage = [];12var noWiki = [];13var noWikiTitle = [];14var noWikiDesc = [];15var noWikiImage = [];16var noWikiCategory = [];17var noWikiLink = [];18var noWikiWiki = [];19var noWikiWikiTitle = [];20var noWikiWikiDesc = [];21var noWikiWikiImage = [];22var noWikiWikiCategory = [];23var noWikiWikiLink = [];24var noWikiWikiWiki = [];25var noWikiWikiWikiTitle = [];26var noWikiWikiWikiDesc = [];
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.get(function(err, resp) {4 console.log(page.convertProperty('birth_date', 'fr'));5 console.log(page.convertProperty('birth_date', 'ru'));6 console.log(page.convertProperty('birth_date', 'de'));7 console.log(page.convertProperty('birth_date', 'zh'));8});9### `page.getParse()`10var wptools = require('wptools');11var page = wptools.page('Albert Einstein');12page.getParse(function(err, resp) {13 console.log(page.data.parse);14});15### `page.getParse([options], callback)`16* `action`: `parse` (default)17* `prop`: `text|categories|links|templates|images|externallinks|sections|displaytitle` (default: `text`)18* `section`: `0` (default)19* `disabletoc`: `true` (default)20* `disableeditsection`: `true` (default)21* `disablestylededuplication`: `true` (default)22* `disablelimitreport`: `true` (default)23* `disableeditsection`: `true` (default)
Using AI Code Generation
1var wptools = require('wptools');2var query = wptools.page('Barack Obama');3query.get(function(err, page) {4 console.log("\n\n\n\n\n\n");5 console.log(page.convertProperty('birth date'));6 console.log("\n\n\n\n\n\n");7});8var wptools = require('wptools');9var query = wptools.page('Barack Obama');10query.get(function(err, page) {11 console.log("\n\n\n\n\n\n");12 console.log(page.convertProperty('birth date', 'date'));13 console.log("\n\n\n\n\n\n");14});
Using AI Code Generation
1var fs = require('fs');2var wptools = require('wptools');3var page = wptools.page('Wikipedia:WikiProject Military history/Assessment/Articles by quality');4page.get(function(err, resp) {5 if (err) {6 console.log(err);7 return;8 }9 if (resp) {10 var json = resp.json();11 var data = json.convertProperty('wikitext');12 fs.writeFile('data.json', JSON.stringify(data), function(err) {13 if (err) {14 console.log(err);15 } else {16 console.log('JSON saved to data.json');17 }18 });19 }20});
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.get(function(err, resp) {4 console.log(page.convertProperty('P123'));5});6var wptools = require('wptools');7var page = wptools.page('Albert Einstein');8page.get(function(err, resp) {9 console.log(page.convertProperty('P31'));10});11var wptools = require('wptools');12var page = wptools.page('Albert Einstein');13page.get(function(err, resp) {14 console.log(page.convertProperty('P31'));15});16var wptools = require('wptools');17var page = wptools.page('Albert Einstein');18page.get(function(err, resp) {19 console.log(page.convertProperty('P31'));20});21var wptools = require('wptools');22var page = wptools.page('Albert Einstein');23page.get(function(err, resp) {24 console.log(page.convertProperty('P31'));25});
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!!