<commit_before>/**
 * @file	KLScriptValue.swift
 * @brief	Extend JSValue class
 * @par Copyright
 *   Copyright (C) 2018 Steel Wheels Project
 */

import KiwiEngine
import CoconutData
import JavaScriptCore
import Foundation

extension JSValue
{
	public static let classPropertyName: String	= "className"
	public static let instancePropertyName: String	= "instanceName"

	public convenience init(URL url: URL, in context: KEContext) {
		let urlobj = KLURL(URL: url, context: context)
		self.init(object: urlobj, in: context)
	}

	public convenience init(image img: CNImage, in context: KEContext) {
		let imgobj = KLImage(context: context)
		imgobj.coreImage = img
		self.init(object: imgobj, in: context)
	}

	public var classPropertyName: String? {
		if let dict = self.toObject() as? Dictionary<AnyHashable, Any> {
			if let name = dict[JSValue.classPropertyName] as? String {
				return name
			}
		}
		return nil
	}

	public func isClass(name nm: String) -> Bool {
		if let thisname = classPropertyName {
			return (thisname == nm)
		} else {
			return false
		}
	}

	public var isDictionary: Bool {
		get {<commit_msg>KiwiLibrary: Update to latest CNValue class<commit_after>/**
 * @file	KLScriptValue.swift
 * @brief	Extend JSValue class
 * @par Copyright
 *   Copyright (C) 2018 Steel Wheels Project
 */

import KiwiEngine
import CoconutData
import JavaScriptCore
import Foundation

extension JSValue
{
	public static let instancePropertyName: String	= "instanceName"

	public convenience init(URL url: URL, in context: KEContext) {
		let urlobj = KLURL(URL: url, context: context)
		self.init(object: urlobj, in: context)
	}

	public convenience init(image img: CNImage, in context: KEContext) {
		let imgobj = KLImage(context: context)
		imgobj.coreImage = img
		self.init(object: imgobj, in: context)
	}

	public var classPropertyName: String? {
		if let dict = self.toObject() as? Dictionary<String, Any> {
			return dict["class"] as? String
		} else {
			return nil
		}
	}

	public func isClass(name nm: String) -> Bool {
		if let thisname = classPropertyName {
			return (thisname == nm)
		} else {
			return false
		}
	}

	public var isDictionary: Bool {
		get {
{'fraction_non_alphanumeric': 0.09512867647058823, 'fraction_numerical': 0.003676470588235294, 'mean_word_length': 4.027713625866051, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6191023', 'n_tokens_mistral': 765, 'n_tokens_neox': 681, 'n_words': 226}